Documentation Index
Fetch the complete documentation index at: https://docs.trykode.xyz/llms.txt
Use this file to discover all available pages before exploring further.
kode golf is a competitive optimization command: you point it at a single source file, and it spins up three isolated git worktrees that each attempt a different optimization strategy in parallel. All three are benchmarked against the original baseline, and the version that shows the most improvement is offered to you for merge. If no strategy beats the baseline, your original code is left completely untouched.
How it works
Before generating any changes, Kode runs your benchmark command against the original file and records the results —
ns/op, B/op, and allocs/op for each benchmark function. This is the bar every strategy must beat.Kode creates three isolated git worktrees and generates a separate optimized version of your file in each, using a different strategy prompt:
Each strategy generates a set of structured hunks, passes them through the full verification gate (syntax, imports, calls, architecture), and only applies the hunks that pass. A strategy that fails verification is marked as failed and excluded from scoring.
After the optimized code is applied in each worktree, Kode runs the benchmark command in each worktree and compares results against the baseline. A strategy’s score reflects how many benchmark functions improved and by how much.
Usage
Flags
| Flag | Description | Default |
|---|---|---|
--optimize | Optimization target: speed, memory, or complexity | speed |
--model | LLM model override | from kode.json |
--test-command | Benchmark command | auto-detected (go test -bench=. -benchmem) |
--project-dir | Project root directory | current working directory |
Example output
Best use cases
Code Golf is most effective when you already suspect a specific file is a bottleneck:- Hot paths — a function that is called millions of times per request and shows up in profiles
- Algorithms you know are slow — O(n²) loops, repeated string concatenation, linear searches over large slices
- Memory-intensive data structures — caches, buffers, and pools that allocate on every call
- Parsers and serializers — files that transform large inputs and are called on every request
Benchmark commands for non-Go projects
The default benchmark command isgo test -bench=. -benchmem. For other languages, pass --test-command with an equivalent:
The benchmark command must write results to stdout in a format Kode can parse. For Go this is automatic. For other runtimes, Kode reads raw stdout and compares the numeric throughput figures between runs — any benchmark framework that prints numbers works, but structured output (JSON, TAP) gives cleaner comparisons.
Next steps
Loop Mode
Run the full pipeline with test execution, rollback, and multi-strategy Ghost Branches.
Daemon Mode
Let Kode watch your git history and proactively surface performance regressions as they accumulate.