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.
kode loop is the highest-autonomy command in Kode’s toolkit. Where kode run stops after applying verified patches, kode loop continues through a fifth stage: it executes your test suite, and if tests fail it atomically rolls back every change that was applied in that cycle. Optionally, you can ask Kode to explore the task across multiple parallel Ghost Branch worktrees and automatically merge the best-scoring strategy.
What kode loop does differently from kode run
kode run covers three stages: Generate → Verify → Apply. kode loop adds two more:
| Stage | kode run | kode loop |
|---|---|---|
| Generate patches via LLM | ✓ | ✓ |
| Verify hunks through gate | ✓ | ✓ |
| Apply verified hunks | ✓ | ✓ |
| Run test suite | — | ✓ |
| Rollback on test failure | — | ✓ |
| Ghost Branch parallelism | — | ✓ (with --branches) |
PASS and prints a JSON summary to stdout. If the tests fail, Kode restores the repository to the exact snapshot it took before applying — your working tree is left clean.
Basic usage
go test ./..., Node → npm test, Rust → cargo test). You can override this with --test-command.
All flags
| Flag | Description | Default |
|---|---|---|
--branches N | Spawn N parallel Ghost Branch worktrees, each using a different strategy | 1 (no Ghost mode) |
--model | LLM model override | from kode.json |
--context-file | Path to context packet JSON from kode plan --packet | none |
--test-command | Test command override | auto-detected |
--project-dir | Project root directory | current working directory |
Ghost Branch mode
When you pass--branches with a value greater than 1, Kode forks the task across N isolated git worktrees running simultaneously. Each worktree applies a different generation strategy:
- Alpha — lightweight, minimal implementation (smallest surface area)
- Beta — robust, modular architecture (well-structured, dependency-aware)
- Gamma — performance-optimised, aggressive (throughput and latency first)
Using
--branches 2 enables two-strategy mode (Alpha + Beta only). Three strategies (the maximum) give the broadest exploration but roughly triple token cost. Start with --branches 2 and graduate to --branches 3 for complex refactors.Rollback behaviour
If the test suite fails after apply, Kode reverts all changes atomically before exiting. The revert is performed via the internal snapshot mechanism — it does not create a git commit or modify your git history. Your working tree is returned to exactly the state it was in beforekode loop ran.
The JSON output on a failed run includes the test error message:
Combining kode plan with kode loop
For large or complex tasks, pre-building the context packet with kode plan --packet separates the slow graph-construction step from the generation step. This is especially valuable in Ghost Branch mode, where all three branches would otherwise each build their own context independently.
--context-file flag accepts the JSON output of kode plan --packet. Kode skips the plan stage entirely and passes the packet directly into the generate stage for every branch.
Configuring the test command
Kode auto-detects the right test command from your project root, but you should configure it explicitly inkode.json for reproducible results:
--test-command:
Next steps
Code Golf
Pit three optimization strategies against each other in parallel and benchmark the winner automatically.
First Task
New to Kode? Start here to initialize your project and run your first task.