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:
In kode golf
kode golf <file> optimizes a single file using three parallel worktrees, each focused on a different performance dimension:
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