# Building a CLI Tool from Idea to Published Package

Complete journey of creating a command-line tool. Design, implementation, and npm publishing.


**Model:** claude-sonnet-4
**Created:** 7/30/2026

---

## Conversation

### **Human**

I want to build a CLI tool called git-prune that removes merged git branches. Where do I start?

---

### **Assistant**

Great project! Let's design this systematically:

PHASE 1: Define the core value. What problem does it solve? (Keeping repos clean of dead branches). Why not just use git branch --merged? (We want automation plus safety).

PHASE 2: Design the interface. Basic usage: git-prune. With options: git-prune --dry-run --keep-main --older-than 30d.

PHASE 3: Core functionality. Get all branches, check which are merged, filter out protected branches (main, develop), optionally filter by age, delete with confirmation.

Tech stack: Node.js (great CLI ecosystem), Commander.js (argument parsing), chalk (colored output), inquirer (interactive prompts), execa (better child_process).

Want me to scaffold the initial project structure?

---

### **Human**

Yes! And make it robust - handle edge cases like if someone runs it on a branch that's about to be deleted.

---

### **Assistant**

EXCELLENT edge case thinking! Here's the architecture:

SAFETY FIRST: Check current branch. Get all branches. Get merged branches. PROTECTION: Never delete current branch. Use dry-run mode. Protects main and master. Uses git branch -d (safe delete - refuses if unmerged).

Safety features built in: Never deletes current branch, dry-run mode, protects main/master branches, uses safe delete that refuses if unmerged.

Want to add tests?

---


---

*Downloaded from BranchLM - GitHub for AI Sessions*
