> ## 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: The Contrarian, Verification-First AI Coding Agent

> Kode replaces the generate-and-pray AI coding paradigm with a 9-gate verification pipeline that validates every patch before it touches your filesystem.

Kode is a verification-first AI coding agent that replaces the "generate-and-pray" paradigm that defines every other AI coding tool on the market. While Cursor, Copilot, and Cline write LLM-generated code directly to your filesystem and leave you to be the verification layer, Kode puts a deterministic, compiled Go pipeline between the model's output and your disk. Every patch the LLM produces must pass nine sequential verification gates before a single byte is written. If any gate fails, the patch is rejected and the model self-corrects on compiler-grade feedback.

## The Core Thesis

**No generation without validation.**

Kode separates concerns that every other AI coding tool conflates. The LLM is a powerful generative engine — excellent at producing plausible-looking code. It is not a compiler, a type-checker, or a security scanner. Kode's Go engine is the security layer, and it does not negotiate with the model: a failed syntax parse, a hallucinated import, or a blast radius breach is a hard block, not a warning you might notice later in a diff.

## The Workflow

Kode enforces a structured software-engineering lifecycle on every task:

**Plan → Critique → Generate → Verify → Apply → Test**

1. **Plan** — Kode builds a surgical context graph of the relevant files, symbols, and import relationships in your project, so the LLM receives only the information it needs.
2. **Critique** — A pre-generation review layer evaluates the plan and rejects structurally flawed approaches before the LLM wastes tokens generating them.
3. **Generate** — The LLM produces structured code hunks (JSON patches) in response to the task prompt.
4. **Verify** — Every hunk is applied in memory and driven through the 9-gate pipeline. The real filesystem is never touched until all gates pass.
5. **Apply** — Verified hunks are written to disk atomically, with a rollback snapshot already in place.
6. **Test** — Kode runs your project's test suite. If tests fail, the changes are automatically reverted from the pre-apply snapshot.

## The 9 Verification Gates

The gate pipeline runs sequentially. A failure at any gate is a hard stop — the remaining gates do not run.

```mermaid theme={null}
graph TD
    LLM[LLM Generates JSON Patch] --> Gate1[Gate 1: AST Syntax]
    Gate1 -->|Pass| Gate2[Gate 2: Imports]
    Gate2 -->|Pass| Gate3[Gate 3: Calls]
    Gate3 -->|Pass| Gate4[Gate 4: Blast Radius]
    Gate4 -->|Pass| Gate5[Gate 5: Architecture]
    Gate5 -->|Pass| Gate6[Gate 6: Sicario SAST]
    Gate6 -->|Pass| Gate7[Gate 7: Sandbox Replay]
    Gate7 -->|Pass| Gate8[Gate 8: QR Code Tunnel]
    Gate8 -->|Pass| Gate9[Gate 9: Browser E2E]
    Gate9 -->|All Gates Pass| FS[(Atomic Write to File System)]

    Gate1 -.->|Fail| RB[Rejection & Self-Correction Loop]
    Gate2 -.->|Fail| RB
    Gate3 -.->|Fail| RB
    Gate4 -.->|Fail| RB
    Gate5 -.->|Fail| RB
    Gate6 -.->|Fail| RB
    Gate7 -.->|Fail| RB
    Gate8 -.->|Fail| RB
    Gate9 -.->|Fail| RB
```

<AccordionGroup>
  <Accordion title="Gate 1 — AST Syntax">
    Dual-engine AST parsing architecture. Uses official Tree-sitter bindings (precision parser) when CGo is enabled, gracefully falling back to fast zero-dependency regex heuristics on strict local environments. Parses **Go, TypeScript, JavaScript, Python, and Rust**. A parse error hard-blocks the filesystem write — the patch never proceeds further.
  </Accordion>

  <Accordion title="Gate 2 — Imports">
    Cross-references every generated import path against the local repository dependency graph. Rejects and self-corrects imports targeting non-existent or hallucinated packages — the most common class of LLM generation error — before the patch ever reaches a compiler or your `node_modules`.
  </Accordion>

  <Accordion title="Gate 3 — Calls">
    Validates that all function and method call sites reference real, existing symbols with compatible signatures. Kode walks the context graph built during planning and cross-references every call site. Prevents the primary source of LLM function hallucination.
  </Accordion>

  <Accordion title="Gate 4 — Blast Radius">
    Computes code churn metrics by walking the dependency graph backward from every modified file. If the downstream impacted file count exceeds your configured `max_blast_radius` threshold (default: 3 files), the patch is blocked. This prevents large, unscoped refactors from slipping through under the guise of a small task.
  </Accordion>

  <Accordion title="Gate 5 — Architecture">
    Enforces modular and microservice boundary rules you declare in `architecture_rules`. Prevents illegal cross-package imports — e.g., database layers importing route handlers, or crossing microservice code lines. You can configure this gate to hard-block on violations or to warn and record them for later review.
  </Accordion>

  <Accordion title="Gate 6 — Security (SAST)">
    Powered by Sicario, Kode's integrated AST-based SAST scanner engine. Audits structural syntax paths for high/critical vulnerabilities — including SQL injection, XSS vectors, and hardcoded credentials — before they are written to disk. High and critical findings are a hard block. Medium and low findings produce a warning. Install Sicario via `kode install sicario` or automatically during `kode init`.
  </Accordion>

  <Accordion title="Gate 7 — Sandbox Replay (NEW)">
    CPU- and memory-bounded dynamic code execution simulator. Runs patches in an isolated local container/sandbox to trap and terminate infinite loops, memory leaks, and unauthorized system or network socket activity before the change reaches your real filesystem.
  </Accordion>

  <Accordion title="Gate 8 — QR Code Tunnel (NEW)">
    Instantly provisions a secure public dev tunnel for previewing local web servers. Renders the tunnel URL as a high-contrast, terminal-scannable QR code to facilitate instant layout and responsiveness testing on actual mobile devices.
  </Accordion>

  <Accordion title="Gate 9 — Browser Verification / E2E (NEW)">
    Synthesizes and executes headless Playwright E2E verification scripts against the running local dev server. Automatically captures walkthrough recordings and checks for visual UI regression, page layout failures, and console errors — rolling back the filesystem changes on failure.
  </Accordion>
</AccordionGroup>

## Key Features

Beyond the verification pipeline, Kode introduces capabilities no incumbent AI coding tool offers.

**Ghost Branches** — Instead of running one LLM strategy, Kode spawns multiple parallel git worktrees via `kode loop --branches N`. Each branch uses a different strategy (Alpha: minimal; Beta: modular; Gamma: performance-optimized). All branches run the full verification and test pipeline concurrently. Kode scores each surviving branch by blast radius, token cost, and execution speed, then merges the highest-scoring winner and discards the rest.

**Blindfold Mode** — Enterprise-grade privacy. When enabled, Kode SHA-256 obfuscates your identifiers — package names, function names, type names — before submitting any code to an external LLM. Your proprietary logic is never exposed in plaintext. The obfuscation mapping is maintained locally and reversed on the output before the patch is applied.

**TDD Mode** — When enabled in your `.kode/kode.json`, the verification pipeline enforces a test-first policy: production code writes are blocked unless a corresponding test file already exists or is included in the same patch set.

A minimal `.kode/config.json` to get started:

```json theme={null}
{
  "provider": "openai",
  "model": "gpt-4o",
  "tdd_mode": true,
  "max_blast_radius": 5,
  "token_budget_usd": 0.50,
  "blindfold_mode": false,
  "architecture_rules": {
    "disallowed_imports": {
      "internal/db": ["internal/gateway", "internal/daemon"]
    }
  }
}
```

**Daemon Mode** — Run `kode daemon` to start a silent background process that polls your git history for code health trends. After detecting 3+ new commits, it analyzes blast radius growth, circular dependencies, and repeated patterns. When thresholds are crossed, it speculatively fixes issues on a ghost branch and prompts you to merge.

**Voice Mode** — Run `kode voice` to start the Kode Command Voice bridge: microphone capture inside the shell, Whisper-based speech-to-text (cloud or local), and automatic routing of the transcribed task into the full `Plan → Critique → Generate → Verify → Apply → Test` loop. Hands-free pair programming with the same verification guarantees as every other entry point.

**MCP Integration** — Kode exposes its full Plan → Verify → Apply pipeline as a Model Context Protocol server (`kode mcp`), so you can drive Kode's verification engine from any MCP-compatible host, including Cursor and Claude Desktop. Add Kode to your `claude_desktop_config.json`:

```json theme={null}
"mcpServers": {
  "kode": {
    "command": "kode",
    "args": ["mcp"]
  }
}
```

## Language Support

Kode's verification pipeline has language-aware support for:

* **Go** — Tree-sitter AST parsing, import resolution, call graph validation
* **TypeScript** and **JavaScript** — Tree-sitter AST parsing, import resolution
* **Python** — Tree-sitter AST parsing, import validation
* **Rust** — Tree-sitter AST parsing via query files

## AI Provider Support

Kode is a Bring Your Own Key (BYOK) platform. Configure any of **25+ supported providers** through the `KODE_LLM_API_KEY` environment variable or your `.kode/kode.json` config. First-party integrations include OpenAI, Anthropic, Google Gemini, and Groq, along with Amazon Bedrock, Azure OpenAI, Mistral, Cohere, DeepInfra, TogetherAI, OpenRouter, and a fully compatible custom OpenAI-compatible endpoint option.

## Where to Go Next

<CardGroup cols={2}>
  <Card title="Quickstart" icon="rocket" href="/quickstart">
    Install Kode, run `kode init`, and generate your first verified patch in under five minutes.
  </Card>

  <Card title="Verification Pipeline" icon="shield-check" href="/concepts/verification-pipeline">
    Deep dive into how the 9-gate pipeline works, how gates interact, and how to configure each one.
  </Card>

  <Card title="Ghost Branches" icon="code-branch" href="/concepts/ghost-branches">
    Learn how parallel speculative execution works and how Kode scores and merges winning branches.
  </Card>

  <Card title="CLI Overview" icon="terminal" href="/cli/overview">
    Full reference for all Kode commands: `run`, `loop`, `plan`, `verify`, `stats`, `daemon`, and more.
  </Card>
</CardGroup>
