Skip to main content
kode loop is Kode’s most complete command. It runs the full workflow in a single invocation: generate patches from a task description, verify each patch through the 9-gate pipeline, apply passing patches to disk, execute your test suite, and automatically roll back to a pre-patch snapshot if tests fail. Use kode loop when correctness matters and you want deterministic, test-backed results rather than just structural verification.

Synopsis

What it does

  1. Generate — sends your task and optional context to the LLM; receives structured JSON hunks.
  2. Verify — runs each hunk through the 9-gate pipeline (syntax, imports, call graph, architecture, security, blast radius).
  3. Apply — writes hunks that pass all gates to disk.
  4. Test — runs your test command (from .kode/kode.json or --test-command).
  5. Rollback — if tests fail, restores all modified files from the pre-patch snapshot and exits non-zero.
If tests pass, kode loop prints a JSON result to stdout and exits 0.

Flags

string
Override the LLM model for this run. Accepts provider/model format. When omitted, Kode reads from .kode/kode.json, then KODE_LLM_MODEL, then defaults to gpt-4o.
string
Path to a context packet JSON file from kode plan --packet. Providing a context packet gives the LLM a focused, token-capped view of relevant files and symbols.
string
Test command to run after applying patches. Overrides the test_command in .kode/kode.json. If neither is set, Kode auto-detects the command from your project root.
string
default:"cwd"
Project root directory. All file paths and the test command are resolved relative to this directory.
integer
default:"1"
Enable Ghost Branch mode by setting this to 2 or 3. Kode spawns the given number of parallel git worktrees, each using a different implementation strategy, then scores and merges the winner.

Examples

Output

On success, kode loop prints a JSON summary to stdout:
On failure (test step exits non-zero), all modified files are rolled back and the output reflects the failure:

Ghost Branch mode

When you pass --branches 2 or --branches 3, kode loop enters Ghost Branch mode. Each branch runs the full loop in an isolated git worktree using a different implementation strategy: After all branches complete, Kode scores each result by blast radius, token cost, and execution speed, then merges the winning branch into your working tree and discards the rest.
Ghost Branch mode requires a clean git working tree. Kode creates and destroys temporary worktrees during the run. Uncommitted changes in your working tree are safe — they are not touched — but the repository must be a valid git repo.

Rollback behaviour

Before applying any patches, kode loop snapshots all files that will be modified. If the test step fails, every snapshotted file is restored to its pre-patch state. The snapshot is in-memory; no additional git commits or stashes are created. This means the rollback is instantaneous and leaves no git history.
Combine kode plan with kode loop for the best results on multi-file tasks. The context packet helps the LLM make targeted changes, which reduces blast radius and increases the probability of tests passing on the first round.