Skip to content

Core Concepts

CodeKnife is one binary, codeknife, that parses a repository, runs a set of analyzers over it, and reports findings. This page names the parts and points to the page that documents each one.

Every command works on one directory, the root. It is the current directory unless you pass --path <dir>. CodeKnife does not search parent directories for configuration.

Files CodeKnife reads from or writes to the root:

File Purpose Documented in
codeknife.toml Thresholds, excludes, blade toggles and suppression rules. Optional: built-in defaults apply without it. codeknife.toml
arch.toml Layer and dependency rules for the architecture blade. Optional. 2. Architecture
codeknife.baseline The findings the repository is allowed to keep. Ratchet Baseline
.codeknife/ Parse cache, metrics, mutation cache, score history and the default map output. The .codeknife Directory

--no-cache stops CodeKnife writing to .codeknife/.

CodeKnife parses Rust, TypeScript, JavaScript, Python and Go with tree-sitter. From every file it extracts items (functions, methods, types), imports, calls, comments and tests, and builds one cross-file graph. Every blade reads that same model. The static blades do not compile your code or run a language server. Only mutation testing, fix --verify, test and deep mode run your own build, test or lint commands.

What is extracted differs per language, and import resolution has limits. Those limits decide what the dead-code, blast-radius and architecture blades can see. See Language Support, How Metrics Are Computed and Import Resolution.

A blade is one analyzer. There are 13, and each is also a command of its own.

# Command Looks for Page
1 codeknife comments Narration, banners, leftover AI chatter, apology comments and suppressions Comments
2 codeknife arch Long files and functions, complexity, nesting, shallow modules, cycles, layer violations Architecture
3 codeknife clones Structurally similar code and duplicate data shapes Clones
4 codeknife dead Unreachable symbols and files, one-caller wrappers, single-implementation traits Dead Code
5 codeknife slop Swallowed errors, type escapes, debug leftovers, placeholder code Slop
6 codeknife sec Hard-coded secrets, injection patterns, tainted flows, Dockerfile and workflow issues Security
7 codeknife tests Tests that assert little, and functions with a high CRAP score Tests & CRAP
8 codeknife mutate Code changes your tests do not catch Mutation Testing
9 codeknife churn Hotspots, files that change together, and thrash in git history Churn
10 codeknife blast Callers and cross-boundary contracts affected by a change Blast Radius
11 codeknife deps Unused and undeclared dependencies, and packages that do not exist in a registry Dependencies
12 codeknife docs Paths, flags and scripts named in Markdown files that no longer exist Docs Drift
13 codeknife map Nothing: it writes a self-contained HTML map of the repository Garden Map

Ten of the blades have a toggle under [blades] in codeknife.toml. The toggles apply to check and the other commands that run the whole suite. A blade run by its own command ignores its toggle.

A finding is one reported problem. It has a rule ID such as CK_DEAD_SYMBOL, a severity, a file and line range, an optional symbol, a message and a suggested fix.

  • Severity is error, warning or info. Errors and warnings fail the gate. Info findings never do.
  • Rule IDs are fixed strings. The binary can emit 98 of them. See the Rule Catalogue.
  • Impact is a 0 to 100 number that orders findings within a severity.

The full shape, including how finding IDs are hashed, is in the Findings Model.

codeknife check is the gate. It runs the static blades, applies the baseline, and exits 0 for pass, 1 for fail and 2 when the run could not complete. Three mechanisms decide the result.

Mechanism Question it answers Page
Thresholds Is this function too long, too nested, too complex? The limits come from [thresholds], and --strict lowers six of them. codeknife.toml
Ratchet baseline Was this finding already here? A finding inside its baselined limit is dropped from the report. Ratchet Baseline
Loosening guard Did someone make the gate pass by weakening it? Raised thresholds, disabled blades, new excludes, a grown baseline and new suppression comments are compared with git and fail the run. Loosening Guard

Two points are easy to get wrong:

  • The baseline is keyed by rule, file and symbol, not by line number. Moving code inside a file does not create a new finding.
  • A loosening is not a finding. The baseline cannot absorb it. A baseline update that has not been committed is itself reported as a loosening.

check has two optional extras. --deep adds findings from native linters that are installed on your machine (Deep Mode). --tier full adds mutation testing and writes the HTML map.

By default a command analyzes the whole repository. --changed narrows the report to files changed in the git working tree, and --since <ref> adds the changes since that ref. See Paths, Excludes & Changed Scope.

Coverage is optional input. With a coverage report, the tests blade computes real CRAP scores and mutation testing skips lines no test runs. Without one, CodeKnife says so in a note and ranks by complexity alone. See Coverage Reports.

codeknife fix makes text edits for a fixed set of rules: dead private code, strippable comments, debug leftovers, expired suppressions and a few more. It is a dry run until you pass --write. With --verify it runs a build or test command afterwards and rolls back the patches that broke it. No language model is involved. See Autofix Engine.

codeknife test runs only the tests that reach changed code (Smart Test Selection). codeknife verify chains an optional fix, the check and those tests in one command (Verify Pipeline).

CodeKnife has an output format and several commands meant for AI coding agents.

Part What it gives an agent Page
Agent format One header line and one line per finding. It is the default when output is not a terminal. Output Formats & Exit Codes
codeknife plan A ranked list of findings, optionally grouped into work orders by root cause Work Orders (plan)
codeknife dossier A size-limited summary of the repository or of one file or symbol Dossier
codeknife reuse Existing functions and types that match a description, to check before writing new code Reuse Oracle
codeknife mcp Seven tools over a stdio MCP server MCP Server
codeknife hook A PreToolUse hook that denies tool calls which would weaken the gate Anti-Tamper Hooks
  • It does not type-check your code. Analysis is syntactic, from tree-sitter parse trees and name resolution.
  • It does not call a language model. The only network client in the binary belongs to codeknife deps --verify-registry, which queries public package registries when you pass that flag.
  • It does not fail on a low health score. codeknife score always exits 0. See Health Scorecard.

For the full command list, see the CLI Reference. For how the binary is built from its crates, see Crate Architecture.