kode generate is the core generation command. It takes a task description, builds a prompt from it (optionally augmented with a context packet from kode plan), sends it to your configured LLM, and returns structured JSON hunks — each one a targeted replacement scoped to a specific symbol or anchor in a single file. By default the output goes to stdout so you can inspect, store, or pipe it. Add --apply and Kode will also verify the hunks and write passing ones to disk.
Synopsis
What it does
- Reads the model and API endpoint from
.kode/kode.json(or environment variables). - Optionally loads a context packet from
--context-fileto enrich the prompt with relevant code symbols. - Sends the prompt to the LLM and receives a structured response.
- Parses the response into an array of
StructuredHunkobjects. - Without
--apply: prints the hunk array as indented JSON to stdout and exits. - With
--apply: passes the hunks throughkode verify’s pipeline and writes passing hunks to disk, then prints an execution summary to stdout.
Flags
string
Override the LLM model for this run. Accepts
provider/model format. When omitted, Kode reads the model from .kode/kode.json (model field), then falls back to the KODE_LLM_MODEL environment variable, and finally gpt-4o.string
Path to a context packet JSON file produced by
kode plan --packet. The packet is injected into the LLM prompt as structured context, improving patch quality and reducing hallucinated file paths.boolean
default:"false"
Verify and apply hunks to disk after generation. Kode runs each hunk through the 9-gate pipeline and writes patches that pass all gates. Equivalent to running
kode run.string
default:"cwd"
Project root directory. Kode resolves all file paths relative to this directory. Defaults to the current working directory.
Environment variables
Examples
JSON hunk format
When run without--apply, kode generate prints a JSON array to stdout:
hunks envelope:
Relationship to other commands
kode generate --apply and kode run are identical. Use kode generate (without --apply) when you want to inspect or version-control the raw hunks before applying them.