Skip to main content
AI coding tools have a well-known failure mode: they generate production code with no tests, the tests never get written, and your coverage ratchets steadily downward. TDD Mode closes this loophole at the infrastructure level. With TDD Mode enabled, Kode cannot write a production file until a corresponding test file is present — and when you run kode loop, the test suite must be executed and the results verified before production code is accepted.

How TDD Mode works

TDD Mode activates a TDDEnforcer that runs before any file write. It inspects every file in the proposed patch and classifies each one as either a test file or a production file. Test file detection: A file is considered a test file if its name matches any of these patterns: If a patch contains only production files (no test files), the write is blocked with:
If a patch contains both test files and production files, Kode runs the test command. The production files are accepted only if the tests pass.

Configuring TDD Mode

Enable TDD Mode in .kode/kode.json under the engine section:
If you omit test_command, Kode auto-detects the correct command by scanning your project for language markers: Detection walks the project tree, skipping node_modules, .git, and vendor directories.

What happens in a loop with TDD Mode on

When you run kode loop with TDD Mode enabled, Kode enforces a strict test-first sequence:

Example configuration

Here is a complete kode.json for a Go project with TDD Mode enabled:
And for a TypeScript project:
TDD Mode pairs perfectly with kode loop, which includes automatic test execution and rollback. Running kode loop --branches 3 with TDD Mode active means each Ghost Branch must also produce passing tests to be eligible for winner selection — branches that fail tests score -1.0 and are eliminated.
  • Guides: Loop mode — full walkthrough of the kode loop workflow with test integration and rollback behaviour