Skip to main content
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 nine-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.

How Ghost Branches work

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:
The terminal output shows each branch, its strategy, its score, and the winner:
You can also run two strategies instead of three:

In kode golf

kode golf <file> optimizes a single file using three parallel worktrees, each focused on a different performance dimension:
Kode benchmarks the original code as a baseline with 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.
Ghost Branches require a clean git working tree. If you have uncommitted changes, git worktree add will fail because it cannot safely fork from a dirty HEAD. Run git stash or commit your work-in-progress before using --branches.