Skip to main content
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

  1. Reads the model and API endpoint from .kode/kode.json (or environment variables).
  2. Optionally loads a context packet from --context-file to enrich the prompt with relevant code symbols.
  3. Sends the prompt to the LLM and receives a structured response.
  4. Parses the response into an array of StructuredHunk objects.
  5. Without --apply: prints the hunk array as indented JSON to stdout and exits.
  6. With --apply: passes the hunks through kode 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:
Save this output and verify it independently by wrapping the array in a 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.
Inspect the JSON output of kode generate before committing by piping it into kode verify --input. This gives you a dry-run view of exactly which gates each hunk passes or fails before anything touches disk.