Most AI coding tools pick one approach and run with it. Ghost Branches run several at once. When you activate Ghost Branch mode, Kode creates N isolated git worktrees — each on its own branch, each with its own AI generation pass and full six-gate verification — and then objectively scores every result. The branch with the best score gets merged into your working directory. The others are silently discarded. The result is that Kode explores the solution space instead of committing to the first thing the LLM outputs.Documentation Index
Fetch the complete documentation index at: https://kode-f177b001.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
How Ghost Branches work
Kode calls
git worktree add for each branch, creating a separate directory under .kode/ghost/ — for example, .kode/ghost/alpha, .kode/ghost/beta, .kode/ghost/gamma. Each worktree is on its own branch (ghost/alpha, ghost/beta, ghost/gamma) forked from your current HEAD.All worktrees share your repo’s git history and object store, so creation is near-instant regardless of project size.
Each worktree receives one of three built-in strategies, each translated into a distinct prompt framing:
alphaminimalbetamodulargammaaggressiveAll three branches run concurrently using a Go goroutine pool. Each one runs a complete pipeline: LLM generation → six-gate verification → test execution. If a branch fails, it automatically retries up to 3 times with an escalating prompt that includes the previous error detail.
Any branch that returned
FAIL from the verification pipeline receives a score of -1.0 and is excluded from winner selection. If TDD Mode is active, any branch whose tests do not pass is also eliminated before scoring. Only branches that passed all active gates compete for the top score.Kode calls
git worktree remove on every losing branch and deletes its ghost/* git branch. The winning branch’s changes are merged into your current working directory using git merge --squash.How to use Ghost Branches
In kode loop
Pass --branches N to kode loop to activate Ghost Branch mode for a full Plan → Generate → Verify → Apply → Test cycle. Accepted values are 2 or 3:
In kode golf
kode golf <file> optimizes a single file using three parallel worktrees, each focused on a different performance dimension:
| Strategy | Focus |
|---|---|
concurrency | Goroutines, channels, async patterns |
memory | Pre-allocation, stack vs heap, reduced copies |
algorithmic | Big-O reduction, hash maps, loop elimination |
go test -bench=. -benchmem, then compares each branch’s benchmark results. The branch that most improves the baseline wins. Use --optimize to focus on a specific dimension:
kode golf runs its own fixed set of performance-optimization strategies. It does not use the --branches flag — branch count is always 3 in golf mode.Ghost Branch scoring in detail
Scores are normalized across all branches so the comparison is relative, not absolute. If all three branches have similar blast radii, the blast radius dimension contributes equally to all — the tie-breaker becomes token cost and speed. A branch that fails verification always scores-1.0 regardless of other metrics. If all branches fail, Kode selects the one with the least severe error and reports it.
Best use cases
Large refactors
When restructuring a package or extracting a service, you want the approach with the smallest footprint across your codebase. Ghost Branches select the minimal-blast-radius winner automatically.
Performance-sensitive code
Use
kode golf on hot paths. Three optimization strategies run head-to-head against real benchmarks rather than relying on the LLM’s intuition about what will be faster.Architecture decisions
When you are genuinely unsure whether to use a modular or minimal approach, Ghost Branches make the tradeoff concrete: you see blast radius, token cost, and test results side-by-side.
Exploratory changes
Early in a feature’s life, when the right abstraction isn’t obvious, run three strategies and see which one passes the most gates and costs the fewest tokens.
Related pages
- Guides: Loop mode — full walkthrough of the
kode loopworkflow - CLI:
kode loop— all flags for the loop command including--branches