Skip to content

The Check Gate

codeknife check is the quality gate. It runs every enabled static blade and the loosening guard in one pass, filters the result through your Ratchet Baseline, and exits 0 (pass), 1 (fail) or 2 (error). Use it in CI, in a pre-commit hook, or after an AI agent edits code.

This demo repository has two committed Python files with a hardcoded key, an orphan file, a deeply nested function and a function with six parameters.

Terminal window
codeknife --no-cache --format human check
echo $?
error[CK_SEC_HARDCODED_SECRET]: potential hardcoded secret (Stripe live secret key) in source code
--> src/token.py:1
= fix: Move credentials to environment variables or an Age/secret manager vault.
warning[CK_DEAD_FILE]: orphan file `src/token.py` has no inbound imports or reachable symbols
--> src/token.py:1-5 (src/token.py)
= fix: Delete this unreferenced file or wire its module into an entrypoint.
warning[CK_ARCH_DEEP_NESTING]: `build_report` nesting depth is 5 (limit 4)
--> src/app.py:11-18 (src.app.build_report)
= fix: Use guard clauses / early returns to reduce nesting depth.
warning[CK_ARCH_TOO_MANY_PARAMS]: `build_report` takes 6 parameters (limit 5)
--> src/app.py:11-18 (src.app.build_report)
= fix: Group cohesive parameters into an options or domain context struct.
note: no coverage file found (running complexity-only mode); generate one with: pytest --cov --cov-report=xml:coverage.xml
note: analyzed 2 commit(s) over the last 90 day(s)
codeknife check: FAIL (2 files, 1 errors, 3 warnings, 0 info, 6ms)
1

The same run in Agent format. Findings are ranked worst first, one per line, with no colour codes:

Terminal window
codeknife --no-cache --format agent check
CODEKNIFE check status=fail files=2 errors=1 warnings=3 infos=0 elapsed_ms=5
[1] ERROR CK_SEC_HARDCODED_SECRET src/token.py:1-1 sym=- impact=95 | potential hardcoded secret (Stripe live secret key) in source code | fix: Move credentials to environment variables or an Age/secret manager vault.
[2] WARNING CK_DEAD_FILE src/token.py:1-5 sym=src/token.py impact=60 | orphan file `src/token.py` has no inbound imports or reachable symbols | fix: Delete this unreferenced file or wire its module into an entrypoint.
[3] WARNING CK_ARCH_DEEP_NESTING src/app.py:11-18 sym=src.app.build_report impact=50 | `build_report` nesting depth is 5 (limit 4) | fix: Use guard clauses / early returns to reduce nesting depth.
[4] WARNING CK_ARCH_TOO_MANY_PARAMS src/app.py:11-18 sym=src.app.build_report impact=45 | `build_report` takes 6 parameters (limit 5) | fix: Group cohesive parameters into an options or domain context struct.
NOTE no coverage file found (running complexity-only mode); generate one with: pytest --cov --cov-report=xml:coverage.xml
NOTE analyzed 2 commit(s) over the last 90 day(s)

And in JSON format (the root value is shortened here):

Terminal window
codeknife --no-cache --format json check
{
"command": "check",
"root": "/work/demo",
"files_scanned": 2,
"elapsed_ms": 3,
"errors": 1,
"warnings": 3,
"infos": 0,
"passed": false,
"findings": [
{
"id": "7c94400ad1754b69",
"rule": "CK_SEC_HARDCODED_SECRET",
"blade": "sec",
"severity": "error",
"location": {
"file": "src/token.py",
"start_line": 1,
"end_line": 1
},
"message": "potential hardcoded secret (Stripe live secret key) in source code",
"fix_hint": "Move credentials to environment variables or an Age/secret manager vault.",
"impact_score": 95.0
},
{
"id": "a5d96c8ae50d6201",
"rule": "CK_ARCH_DEEP_NESTING",
"blade": "arch",
"severity": "warning",
"location": {
"file": "src/app.py",
"start_line": 11,
"end_line": 18,
"symbol": "src.app.build_report"
},
"message": "`build_report` nesting depth is 5 (limit 4)",
"fix_hint": "Use guard clauses / early returns to reduce nesting depth.",
"impact_score": 50.0,
"metric_value": 5.0
}
...
],
"notes": [
"no coverage file found (running complexity-only mode); generate one with: pytest --cov --cov-report=xml:coverage.xml",
"analyzed 2 commit(s) over the last 90 day(s)"
]
}

The JSON report also carries loosenings and pr_brief keys when they are present. Every field is described on Findings Model; every format on Output Formats & Exit Codes.

  1. Load context. Read codeknife.toml (or the built-in defaults), apply strict thresholds if --strict is passed or strictness = "strict" is set, read arch.toml if present, parse every source file into the code model and build the import graph. With --changed, collect the changed file set from git.
  2. Static suite, in parallel. Three branches run at the same time:
    • Group A: comments, arch, clones, dead, slop.
    • Group B: sec, tests, churn, deps, docs.
    • The Loosening Guard.
  3. Blast radius. Only with --changed, and only when the changed set is not empty: the blast blade runs over the changed files and adds CK_BLAST_* findings (severity info in the runs shown on this page).
  4. Metrics. All findings are sorted (severity, then impact, then file, line and rule). Unless --no-cache is set, .codeknife/metrics.json is written. With --changed, the PR Risk Brief is built.
  5. --deep (optional): run native linters and append their findings. See Deep Mode.
  6. --tier full (optional): run mutation testing, then write the HTML Garden Map.
  7. Report. Load codeknife.baseline, drop findings the baseline still allows, decide pass or fail, and print the report.

--tier standard is the default. It runs steps 1 to 4 and 7. These ten blades have a toggle under [blades] in codeknife.toml, and all default to true:

Toggle Blade page
blades.comments Comments
blades.arch Architecture
blades.clones Clones
blades.dead Dead Code
blades.slop Slop
blades.sec Security
blades.tests Tests & CRAP
blades.churn Churn
blades.deps Dependencies
blades.docs Docs Drift

A blade set to false is skipped and adds no findings or notes. There is one exception: the tests blade always runs because its coverage and CRAP data feed the metrics file and the PR Risk Brief. With tests = false its findings and notes are dropped.

There is no toggle for the loosening guard, blast, mutate or map. The guard always runs.

[blades]
sec = false
tests = false
churn = false
Terminal window
codeknife --no-cache --format agent check
CODEKNIFE check status=fail files=2 errors=0 warnings=3 infos=0 elapsed_ms=3
[1] WARNING CK_DEAD_FILE src/token.py:1-5 sym=src/token.py impact=60 | orphan file `src/token.py` has no inbound imports or reachable symbols | fix: Delete this unreferenced file or wire its module into an entrypoint.
[2] WARNING CK_ARCH_DEEP_NESTING src/app.py:11-18 sym=src.app.build_report impact=50 | `build_report` nesting depth is 5 (limit 4) | fix: Use guard clauses / early returns to reduce nesting depth.
[3] WARNING CK_ARCH_TOO_MANY_PARAMS src/app.py:11-18 sym=src.app.build_report impact=45 | `build_report` takes 6 parameters (limit 5) | fix: Group cohesive parameters into an options or domain context struct.

--tier full adds two steps after the static suite (and after --deep, if set):

  1. Mutation testing. The Mutation Testing blade runs with top_crap set from [mutate] top_crap (default 10), the --coverage path if given, and the --changed set if given. Its findings are merged in. This step runs a real test command; if it cannot be started, check exits 2.
  2. Garden Map. The Garden Map HTML file is written to --map-out if given, otherwise to .codeknife/map.html. With --no-cache and no --map-out, the map is not written and a note says so.
[mutate]
test_command = "python3 -m unittest -q"
Terminal window
codeknife --no-cache --format agent check --tier full
CODEKNIFE check status=fail files=5 errors=8 warnings=3 infos=0 elapsed_ms=384
[1] ERROR CK_SEC_HARDCODED_SECRET src/token.py:1-1 sym=- impact=95 | potential hardcoded secret (Stripe live secret key) in source code | fix: Move credentials to environment variables or an Age/secret manager vault.
[2] ERROR CK_MUTATE_SURVIVOR src/app.py:6-6 sym=src.app.load_config impact=85 | mutant survived in `src.app.load_config`: replace return value with default/empty value | fix: Add a test verifying behavior around `return json.loads(open(path).read())` -> `return None` so this mutant fails tests.
...
NOTE no coverage file found (running complexity-only mode); generate one with: pytest --cov --cov-report=xml:coverage.xml
NOTE analyzed 2 commit(s) over the last 90 day(s)
NOTE mutation score: 41.7% (5 killed, 0 cached, 7 survived, 0 unviable, 0 uncovered skipped); schemata: 4 mutant(s) compiled once; blast-filtered tests: 11/12
NOTE --no-cache skipped default .codeknife/map.html write

With --map-out out/map.html (or without --no-cache) the last note becomes:

NOTE wrote interactive map /work/demo-full/out/map.html (5 nodes, 3 edges, 0 red arrows)

A relative --map-out path is resolved against --path, not the current directory. --map-out without --tier full is accepted and ignored.

After the baseline filter, the run fails if either is true:

  • at least one remaining finding has severity error or warning, or
  • the loosening guard reported at least one loosening.

info findings never fail the gate. They are shown and counted, but a run with only info findings passes.

Findings reach that test in this order:

  1. Every blade, guard, deep and mutation finding is collected.
  2. If codeknife.baseline exists, each warning and error finding is checked against it. Findings still inside their baselined limit are removed and counted in a note. info findings always pass through. See Ratchet Baseline.
  3. Guard findings (CK_GUARD_*, all error) are ordinary findings at this point, so the baseline can absorb them. Loosenings are a separate list. The baseline cannot absorb a loosening.

A repository with only an info finding and a baseline passes:

CODEKNIFE check status=pass files=1 errors=0 warnings=0 infos=1 elapsed_ms=3
[1] INFO CK_CMT_SUPPRESSION src/util.py:1-1 sym=- impact=35 | MUST-RESHAPE: `noqa` lint/type suppression | fix: Fix the underlying type or lint warning instead of suppressing it.
NOTE no coverage file found (running complexity-only mode); generate one with: pytest --cov --cov-report=xml:coverage.xml
NOTE analyzed 2 commit(s) over the last 90 day(s)
NOTE 1 finding(s) suppressed by codeknife.baseline
Code Meaning Measured with
0 Pass: no error or warning findings after the baseline, and no loosenings the run above
1 Fail: at least one error or warning finding, or at least one loosening the demo run at the top of this page
2 Error: the run could not complete. codeknife error: ... is printed to stderr see below

Errors measured on this build, each exiting 2:

codeknife error: parsing codeknife.toml: TOML parse error at line 1, column 8
codeknife error: codeknife.baseline:4: expected 4 tab-separated columns, found 3
codeknife error: reading coverage report nope.xml: No such file or directory (os error 2)
codeknife error: spawning test command `pytest -q`: No such file or directory (os error 2)

The last one comes from --tier full when the mutation test command is not installed.

Notes are informational lines. They never change the exit code. Human format prints them as note: ... after the findings, Agent format as NOTE ... at the end, and JSON as the notes array. check itself adds these notes:

Note When
N finding(s) suppressed by codeknife.baseline the baseline removed at least one finding
deep: ... --deep is set; see Deep Mode
mutation score: ... --tier full
wrote interactive map PATH (N nodes, N edges, N red arrows) --tier full wrote the map
--no-cache skipped default .codeknife/map.html write --tier full --no-cache without --map-out

Blades add their own notes, for example the coverage and churn notes above. Those are documented on each blade page.

check has four flags of its own:

Flag Default Effect
--tier standard|full standard full adds mutation testing and the HTML map
--deep off Run installed native linters; see Deep Mode
--coverage PATH none Coverage report for the tests blade. When omitted, the first [coverage] paths entry is used, otherwise the tests blade looks for a report itself. See Coverage Reports. Also passed to mutation in --tier full
--map-out PATH .codeknife/map.html Where --tier full writes the map. Ignored without --tier full

Global flags that change check:

Flag Effect on check
--path PATH Repository root. Default .
--format auto, human, agent, json, sarif, markdown. auto picks Human on a terminal and Agent otherwise. Human output is coloured only on a terminal
--strict Tightens thresholds before any blade runs (below)
--changed Scopes blades to changed files, runs blast, adds the PR Risk Brief (below)
--since REF Base ref for --changed and for the loosening guard (below)
--no-cache Do not read or write the parse cache, do not write .codeknife/metrics.json, and skip the default map write in --tier full
--max-items N Agent format only: show at most N findings (default 60). Human, JSON, SARIF and Markdown output ignore it

--strict (or strictness = "strict" in codeknife.toml) caps these thresholds. A value you set lower in config is kept:

Threshold Strict cap
max_file_lines 400
max_fn_lines 40
max_cognitive_complexity 10
max_crap 10.0
max_params 4
max_nesting 3

Some blades also change individual rules in strict mode; see each blade page. On the demo, --strict adds a finding and tightens two limits:

Terminal window
codeknife --no-cache --format agent --strict check
CODEKNIFE check status=fail files=2 errors=1 warnings=4 infos=0 elapsed_ms=3
[1] ERROR CK_SEC_HARDCODED_SECRET src/token.py:1-1 sym=- impact=95 | potential hardcoded secret (Stripe live secret key) in source code | fix: Move credentials to environment variables or an Age/secret manager vault.
[2] WARNING CK_ARCH_COGNITIVE_COMPLEXITY src/app.py:11-18 sym=src.app.build_report impact=70 | `build_report` cognitive complexity is 15 (limit 10) | fix: Flatten nested conditionals using early returns, match tables, or domain helpers.
[3] WARNING CK_DEAD_FILE src/token.py:1-5 sym=src/token.py impact=60 | orphan file `src/token.py` has no inbound imports or reachable symbols | fix: Delete this unreferenced file or wire its module into an entrypoint.
[4] WARNING CK_ARCH_DEEP_NESTING src/app.py:11-18 sym=src.app.build_report impact=50 | `build_report` nesting depth is 5 (limit 3) | fix: Use guard clauses / early returns to reduce nesting depth.
[5] WARNING CK_ARCH_TOO_MANY_PARAMS src/app.py:11-18 sym=src.app.build_report impact=45 | `build_report` takes 6 parameters (limit 4) | fix: Group cohesive parameters into an options or domain context struct.
...

--strict also changes what the loosening guard sees; see Loosening Guard.

With --changed, the changed set is every file git reports as modified or untracked in the working tree. With --since REF as well, every file that differs between REF and HEAD is added. Blades only report findings in that set. Full path rules are on Paths, Excludes & Changed Scope.

--changed also turns on two things in check:

  • the blast blade over the changed files (only if the set is not empty);
  • the PR Risk Brief (PR_BRIEF line in Agent format, PR Risk Brief in Human format, pr_brief in JSON).

On a clean working tree the set is empty and the gate passes:

Terminal window
codeknife --no-cache --format agent --changed check
CODEKNIFE check status=pass files=2 errors=0 warnings=0 infos=0 elapsed_ms=4
PR_BRIEF risk=low changed_files=0 dirs=0 max_diff_crap=0.0 new_suppressions=0 new_deps=0
NOTE no coverage file found (running complexity-only mode); generate one with: pytest --cov --cov-report=xml:coverage.xml
NOTE analyzed 2 commit(s) over the last 90 day(s)

Against the previous commit:

Terminal window
codeknife --no-cache --format agent --changed --since HEAD~1 check
CODEKNIFE check status=fail files=2 errors=1 warnings=3 infos=4 elapsed_ms=4
PR_BRIEF risk=high changed_files=2 dirs=1 max_diff_crap=0.0 new_suppressions=0 new_deps=0
HOTSPOT src/app.py
HOTSPOT src/token.py
[1] ERROR CK_SEC_HARDCODED_SECRET src/token.py:1-1 sym=- impact=95 | potential hardcoded secret (Stripe live secret key) in source code | fix: Move credentials to environment variables or an Age/secret manager vault.
...
[5] INFO CK_BLAST_IMPACT src/app.py:4-8 sym=src.app.load_config impact=35 | Blast radius for `src.app.load_config`: 1 upstream caller(s) across 1 file(s), 1 entrypoint(s), 0 test(s) | fix: Add tests covering the affected entrypoints before modifying this symbol.
...

PR Risk Brief fields, as computed:

Field Value
changed_files size of the changed set
directories_touched (dirs) distinct parent directories of changed files
diff_crap_max highest CRAP score of a function that overlaps changed lines, if coverage is available
new_suppressions number of CK_GUARD_* findings
new_dependencies number of CK_DEP_PHANTOM and CK_DEP_SLOPSQUAT_RISK findings
review_risk high if any error finding, any loosening, or diff_crap_max of 30 or more; medium if any warning, more than 10 changed files or more than 4 directories; otherwise low
hotspots up to 5 changed files ranked by 2 x commit count + 5 x finding count

--since without --changed does not scope the blades. It only changes the git ref the loosening guard compares against. See Loosening Guard.

  • MCP tool codeknife_check (see MCP Tools). It runs the same static suite, guard and baseline filter and returns the JSON report. It accepts path, no_cache, changed, since, strict and max_items. It has no deep, tier or coverage argument. Its output is always JSON, so max_items has no effect on it.
  • codeknife verify runs a strict check as one stage of a pipeline; see Verify Pipeline.
  • The full rule list is on the Rule Catalogue.