Git-style conversation branching for Claude Code.
Fork conversations to explore alternatives. Auto-snapshot on corrections. Merge the best results.
Claude Code conversations are linear. Once you go down a path, there's no going back without losing context. You can't try two approaches and compare. You can't undo a bad direction without starting over.
claude-branch adds git-style branching to your conversations:
You: implement auth with JWT
Claude: [implements JWT...]
You: /branch try-cookies ← fork here
You: actually, use session cookies instead
Claude: [implements cookies...]
You: /checkout main ← go back
You: /diff try-cookies ← compare
You: /merge try-cookies ← keep the best
claude plugin install claude-branchRequires Node.js >= 18. On macOS, also needs Xcode Command Line Tools:
xcode-select --install| Command | What it does |
|---|---|
/branch <name> |
Fork the conversation at this point |
/branches |
Show all branches as a tree |
/checkout <name> |
Switch to a branch (restores context) |
/merge <name> |
Merge a branch into the current one |
/diff <name> |
Compare current branch with another |
/snapshot [label] |
Save a manual checkpoint |
/explore <prompt> |
Try 3 approaches in parallel |
/branch-from-snapshot <snap> <name> |
Fork from a saved checkpoint |
/delete-branch <name> |
Remove a branch |
Fork whenever you want to try something different.
You: /branch try-hooks
You: let's rewrite this with React hooks instead of classes
Claude: [rewrites with hooks...]
You: /checkout main
You: /diff try-hooks
When you correct Claude ("no", "wrong", "undo", "revert"...), a snapshot is automatically created before the correction. You can always go back.
Claude: [does something wrong]
You: no, that's not right — do X instead
→ Snapshot auto-saved at this point
→ Later: /branch-from-snapshot auto-before-correction-1710957600-1 alt-approach
Supports English and French correction patterns.
Explore multiple approaches simultaneously.
You: /explore implement the caching layer
→ explore-1: Simple in-memory cache (conservative)
→ explore-2: Redis-backed cache (balanced)
→ explore-3: Multi-level cache with LRU (ambitious)
Claude: Here's a comparison of all 3...
You: /merge explore-2
Zero interference with Claude Code. Never modifies session files. All data stored separately:
~/.claude-branch/
├── claude-branch.db # SQLite: branches, snapshots, tree
├── patches/ # Divergent messages per branch
│ └── <session-id>/
│ ├── main.jsonl
│ └── try-hooks.jsonl
└── settings.json # Config
When you /checkout a branch, claude-branch summarizes the last 20 messages (key decisions, user requests, model responses) and injects this context so Claude can continue naturally.
Every JSONL line is validated before merge. Invalid lines are skipped and reported. Empty branches are rejected with a clear error.
- SQLite with WAL mode for concurrent access
- Transactions for all multi-step operations
- Auto-recovery if database is corrupted
- Branch names validated (alphanumeric, 1-64 chars, no path traversal)
~/.claude-branch/settings.json:
{
"autoSnapshot": true,
"exploreParallelism": 3
}| Setting | Default | Description |
|---|---|---|
autoSnapshot |
true |
Auto-snapshot when corrections detected |
exploreParallelism |
3 |
Number of branches for /explore |
git clone https://github.com/Lcharvol/claude-branch.git
cd claude-branch
npm install
npm run build # compile TypeScript
npm test # 41 tests
npm run dev # watch mode- TypeScript — strict mode, ES2022
- SQLite (better-sqlite3) — WAL mode, transactions
- Node.js test runner — zero external test dependencies
- GitHub Actions — CI on Node 18/20/22
MIT — Lucas Charvolin