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.
Run it
Section titled “Run it”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.
codeknife --no-cache --format human checkecho $?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.xmlnote: analyzed 2 commit(s) over the last 90 day(s)codeknife check: FAIL (2 files, 1 errors, 3 warnings, 0 info, 6ms)
1The same run in Agent format. Findings are ranked worst first, one per line, with no colour codes:
codeknife --no-cache --format agent checkCODEKNIFE 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.xmlNOTE analyzed 2 commit(s) over the last 90 day(s)And in JSON format (the root value is shortened here):
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.
What check runs, in order
Section titled “What check runs, in order”- Load context. Read
codeknife.toml(or the built-in defaults), apply strict thresholds if--strictis passed orstrictness = "strict"is set, readarch.tomlif present, parse every source file into the code model and build the import graph. With--changed, collect the changed file set from git. - 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.
- Group A:
- Blast radius. Only with
--changed, and only when the changed set is not empty: theblastblade runs over the changed files and addsCK_BLAST_*findings (severityinfoin the runs shown on this page). - Metrics. All findings are sorted (severity, then impact, then file, line and rule). Unless
--no-cacheis set,.codeknife/metrics.jsonis written. With--changed, the PR Risk Brief is built. --deep(optional): run native linters and append their findings. See Deep Mode.--tier full(optional): run mutation testing, then write the HTML Garden Map.- Report. Load
codeknife.baseline, drop findings the baseline still allows, decide pass or fail, and print the report.
Standard tier
Section titled “Standard tier”--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 = falsetests = falsechurn = falsecodeknife --no-cache --format agent checkCODEKNIFE 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.Full tier
Section titled “Full tier”--tier full adds two steps after the static suite (and after --deep, if set):
- Mutation testing. The Mutation Testing blade runs with
top_crapset from[mutate] top_crap(default10), the--coveragepath if given, and the--changedset if given. Its findings are merged in. This step runs a real test command; if it cannot be started,checkexits2. - Garden Map. The Garden Map HTML file is written to
--map-outif given, otherwise to.codeknife/map.html. With--no-cacheand no--map-out, the map is not written and a note says so.
[mutate]test_command = "python3 -m unittest -q"codeknife --no-cache --format agent check --tier fullCODEKNIFE 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.xmlNOTE 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/12NOTE --no-cache skipped default .codeknife/map.html writeWith --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.
How pass or fail is decided
Section titled “How pass or fail is decided”After the baseline filter, the run fails if either is true:
- at least one remaining finding has severity
errororwarning, 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:
- Every blade, guard, deep and mutation finding is collected.
- If
codeknife.baselineexists, eachwarninganderrorfinding is checked against it. Findings still inside their baselined limit are removed and counted in a note.infofindings always pass through. See Ratchet Baseline. - Guard findings (
CK_GUARD_*, allerror) 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.xmlNOTE analyzed 2 commit(s) over the last 90 day(s)NOTE 1 finding(s) suppressed by codeknife.baselineExit codes
Section titled “Exit codes”| 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 8codeknife error: codeknife.baseline:4: expected 4 tab-separated columns, found 3codeknife 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
Section titled “--strict”--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:
codeknife --no-cache --format agent --strict checkCODEKNIFE 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.
--changed and --since
Section titled “--changed and --since”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
blastblade over the changed files (only if the set is not empty); - the PR Risk Brief (
PR_BRIEFline in Agent format,PR Risk Briefin Human format,pr_briefin JSON).
On a clean working tree the set is empty and the gate passes:
codeknife --no-cache --format agent --changed checkCODEKNIFE check status=pass files=2 errors=0 warnings=0 infos=0 elapsed_ms=4PR_BRIEF risk=low changed_files=0 dirs=0 max_diff_crap=0.0 new_suppressions=0 new_deps=0NOTE no coverage file found (running complexity-only mode); generate one with: pytest --cov --cov-report=xml:coverage.xmlNOTE analyzed 2 commit(s) over the last 90 day(s)Against the previous commit:
codeknife --no-cache --format agent --changed --since HEAD~1 checkCODEKNIFE check status=fail files=2 errors=1 warnings=3 infos=4 elapsed_ms=4PR_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.
Also available via
Section titled “Also available via”- MCP tool
codeknife_check(see MCP Tools). It runs the same static suite, guard and baseline filter and returns the JSON report. It acceptspath,no_cache,changed,since,strictandmax_items. It has nodeep,tierorcoverageargument. Its output is always JSON, somax_itemshas no effect on it. codeknife verifyruns a strict check as one stage of a pipeline; see Verify Pipeline.- The full rule list is on the Rule Catalogue.