Output Formats & Exit Codes
Every CodeKnife command takes the global --format flag. Pick human to read results in a terminal, agent for a compact line format that a coding agent can parse cheaply, json for scripts, sarif for code-scanning tools, and markdown for pull request comments. The exit code tells you whether the gate passed, whatever the format.
The same check in every format
Section titled “The same check in every format”The examples below run codeknife check on a one-file Rust demo with 5 warnings and 3 info findings. Each run exits with 1.
codeknife --no-cache --format human checkwarning[CK_CMT_APOLOGY]: MUST-RESHAPE: workaround/apology comment found --> src/main.rs:18 (messy) = fix: Refactor the underlying function/type or encode this constraint as a type/test, then delete the comment.
warning[CK_DEAD_SYMBOL]: unreachable internal symbol `dead_private_fn` --> src/main.rs:22-24 (sloppy_demo::dead_private_fn) = fix: Delete this unused function (or run `codeknife dead --fix --write`).
...
info[CK_CMT_NARRATION]: strippable comment: narration restating adjacent code --> src/main.rs:5 (messy) = fix: Run `codeknife comments --strip --write` to remove safely.
note: no coverage file found (running complexity-only mode); generate one with: cargo llvm-cov --lcov --output-path lcov.infonote: analyzed 1 commit(s) over the last 90 day(s)codeknife check: FAIL (1 files, 0 errors, 5 warnings, 3 info, 3ms)codeknife --no-cache --format agent checkCODEKNIFE check status=fail files=1 errors=0 warnings=5 infos=3 elapsed_ms=6[1] WARNING CK_CMT_APOLOGY src/main.rs:18-18 sym=messy impact=65 | MUST-RESHAPE: workaround/apology comment found | fix: Refactor the underlying function/type or encode this constraint as a type/test, then delete the comment.[2] WARNING CK_DEAD_SYMBOL src/main.rs:22-24 sym=sloppy_demo::dead_private_fn impact=55 | unreachable internal symbol `dead_private_fn` | fix: Delete this unused function (or run `codeknife dead --fix --write`).[3] WARNING CK_ARCH_DEEP_NESTING src/main.rs:4-20 sym=sloppy_demo::messy impact=50 | `messy` nesting depth is 5 (limit 4) | fix: Use guard clauses / early returns to reduce nesting depth.[4] WARNING CK_ARCH_TOO_MANY_PARAMS src/main.rs:4-20 sym=sloppy_demo::messy impact=45 | `messy` takes 6 parameters (limit 5) | fix: Group cohesive parameters into an options or domain context struct.[5] WARNING CK_ARCH_BOOL_TRAP src/main.rs:4-20 sym=sloppy_demo::messy impact=40 | `messy` has 2 boolean flag parameters | fix: Replace boolean flags with explicit enum variants or separate named functions.[6] INFO CK_CMT_BANNER src/main.rs:2-2 sym=- impact=25 | strippable comment: section divider banner | fix: Run `codeknife comments --strip --write` to remove safely.[7] INFO CK_CMT_AI_RESIDUE src/main.rs:3-3 sym=- impact=25 | strippable comment: conversational AI residue or trivial boilerplate | fix: Run `codeknife comments --strip --write` to remove safely.[8] INFO CK_CMT_NARRATION src/main.rs:5-5 sym=messy impact=25 | strippable comment: narration restating adjacent code | fix: Run `codeknife comments --strip --write` to remove safely.NOTE no coverage file found (running complexity-only mode); generate one with: cargo llvm-cov --lcov --output-path lcov.infoNOTE analyzed 1 commit(s) over the last 90 day(s)codeknife --no-cache --format json check{ "command": "check", "root": "/.../sloppy", "files_scanned": 1, "elapsed_ms": 3, "errors": 0, "warnings": 5, "infos": 3, "passed": false, "findings": [ { "id": "8ed604003525a8b7", "rule": "CK_CMT_APOLOGY", "blade": "comments", "severity": "warning", "location": { "file": "src/main.rs", "start_line": 18, "end_line": 18, "symbol": "messy" }, "message": "MUST-RESHAPE: workaround/apology comment found", "fix_hint": "Refactor the underlying function/type or encode this constraint as a type/test, then delete the comment.", "impact_score": 65.0 },... ], "notes": [ "no coverage file found (running complexity-only mode); generate one with: cargo llvm-cov --lcov --output-path lcov.info", "analyzed 1 commit(s) over the last 90 day(s)" ]}codeknife --no-cache --format sarif check{ "$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/main/sarif-2.1/schema/sarif-schema-2.1.0.json", "runs": [ { "results": [ { "level": "warning", "locations": [ { "physicalLocation": { "artifactLocation": { "uri": "src/main.rs" }, "region": { "endLine": 18, "startLine": 18 } } } ], "message": { "text": "MUST-RESHAPE: workaround/apology comment found — fix: Refactor the underlying function/type or encode this constraint as a type/test, then delete the comment." }, "ruleId": "CK_CMT_APOLOGY" },... ], "tool": { "driver": { "informationUri": "https://github.com/robertguss/codeknife", "name": "codeknife", "rules": [ { "defaultConfiguration": { "level": "warning" }, "help": { "text": "Replace boolean flags with explicit enum variants or separate named functions." }, "id": "CK_ARCH_BOOL_TRAP", "shortDescription": { "text": "CK_ARCH_BOOL_TRAP" } },... ], "version": "0.2.0" } } } ], "version": "2.1.0"}Markdown
Section titled “Markdown”codeknife --no-cache --format markdown check## CodeKnife `check` — FAIL
| Files | Errors | Warnings | Info | Elapsed || ---: | ---: | ---: | ---: | ---: || 1 | 0 | 5 | 3 | 3ms |
| Severity | Rule | Location | Message | Fix Hint || --- | --- | --- | --- | --- || WARNING | `CK_CMT_APOLOGY` | `src/main.rs:18` | MUST-RESHAPE: workaround/apology comment found | Refactor the underlying function/type or encode this constraint as a type/test, then delete the comment. || WARNING | `CK_DEAD_SYMBOL` | `src/main.rs:22` | unreachable internal symbol `dead_private_fn` | Delete this unused function (or run `codeknife dead --fix --write`). |...| INFO | `CK_CMT_NARRATION` | `src/main.rs:5` | strippable comment: narration restating adjacent code | Run `codeknife comments --strip --write` to remove safely. |
- _no coverage file found (running complexity-only mode); generate one with: cargo llvm-cov --lcov --output-path lcov.info_- _analyzed 1 commit(s) over the last 90 day(s)_Choosing a format
Section titled “Choosing a format”--format |
Output |
|---|---|
auto (default) |
human with colour when stdout is a terminal, otherwise agent |
human |
Compiler-style text. Coloured only when stdout is a terminal. |
agent |
Plain-text lines, no ANSI codes, worst finding first, capped by --max-items |
json |
The full run report as pretty-printed JSON |
sarif |
SARIF 2.1.0 JSON |
markdown |
GitHub-flavoured Markdown tables |
auto looks only at whether stdout is a terminal. No environment variable changes the choice. Only these six names are accepted; anything else, such as --format md, is a usage error with exit code 2:
error: invalid value 'md' for '--format <FORMAT>' [possible values: auto, human, agent, json, sarif, markdown]Human format
Section titled “Human format”Each finding is printed as a block:
<severity>[<RULE>]: <message> --> <file>:<line> (<symbol>) = note: <file>:<line> — <label> <picture lines> = fix: <fix hint>severityiserror,warningorinfo.- The location shows
file:start-endwhen the finding spans several lines andfile:startotherwise. The symbol in parentheses is shown only when the finding has one. - One
= note:line is printed per evidence item, if any. - A picture is drawn only for findings that carry one (see ASCII pictures).
- A blank line follows each block.
Findings are printed in the order the report holds them. After the findings come, when present: a loosening warnings: block with one ! <text> line each, a PR Risk Brief [<risk>]: ... line with * inspect first: <file> lines, and one note: <text> line per note. The last line is the summary:
codeknife <command>: <PASS|FAIL> (<files> files, <errors> errors, <warnings> warnings, <infos> info, <ms>ms)With check --changed on a repository where codeknife.toml loosened a threshold, the tail looks like this:
loosening warnings: ! codeknife.toml: `max_params` raised from 5 to 9
PR Risk Brief [high]: 2 files across 2 dirs | diff_crap_max=0.0 | new_suppressions=0 | new_deps=0 * inspect first: src/main.rs * inspect first: codeknife.toml
note: no coverage file found (running complexity-only mode); generate one with: cargo llvm-cov --lcov --output-path lcov.infonote: analyzed 2 commit(s) over the last 90 day(s)codeknife check: FAIL (1 files, 0 errors, 4 warnings, 5 info, 5ms)Colours
Section titled “Colours”Colour is on only when stdout is a terminal. Then:
| Element | Style |
|---|---|
error[...] badge |
red, bold |
warning[...] badge |
yellow, bold |
info[...] badge |
cyan, bold |
fix label |
green, bold |
PASS / FAIL |
green bold / red bold |
loosening warnings: |
yellow, bold |
Agent format
Section titled “Agent format”Agent output has no ANSI codes and one record per line.
| Line | Grammar |
|---|---|
| Header (always first) | CODEKNIFE <command> status=<pass|fail> files=<n> errors=<n> warnings=<n> infos=<n> elapsed_ms=<n> |
| Loosening count | LOOSENINGS count=<n>, followed by up to 15 lines - <text> |
| PR brief | PR_BRIEF risk=<risk> changed_files=<n> dirs=<n> max_diff_crap=<x.x> new_suppressions=<n> new_deps=<n>, followed by HOTSPOT <file> lines |
| Finding | [<rank>] <SEVERITY> <RULE> <file>:<start>-<end> sym=<symbol or -> impact=<n> | <message> | fix: <fix hint> |
| Truncation | ... truncated <n> additional findings (rerun with --format json or narrow scope) |
| Note | NOTE <text> |
Details:
SEVERITYis upper case:ERROR,WARNING,INFO.start-endis always printed, even for a one-line finding (18-18).impactis the impact score rounded to a whole number.max_diff_crapprints0.0when there is no Diff-CRAP value.- Findings are sorted by severity (errors first), then impact (highest first), then file path, then start line.
rankcounts from 1 in that order.
–max-items
Section titled “–max-items”Agent output shows at most 60 findings by default. --max-items <n> changes the cap. The header counts and the exit code always cover every finding.
codeknife --no-cache --format agent --max-items 2 checkCODEKNIFE check status=fail files=1 errors=0 warnings=5 infos=3 elapsed_ms=3[1] WARNING CK_CMT_APOLOGY src/main.rs:18-18 sym=messy impact=65 | MUST-RESHAPE: workaround/apology comment found | fix: Refactor the underlying function/type or encode this constraint as a type/test, then delete the comment.[2] WARNING CK_DEAD_SYMBOL src/main.rs:22-24 sym=sloppy_demo::dead_private_fn impact=55 | unreachable internal symbol `dead_private_fn` | fix: Delete this unused function (or run `codeknife dead --fix --write`).... truncated 6 additional findings (rerun with --format json or narrow scope)NOTE no coverage file found (running complexity-only mode); generate one with: cargo llvm-cov --lcov --output-path lcov.infoNOTE analyzed 1 commit(s) over the last 90 day(s)--max-items 0 prints no findings, only the header, the truncation line and notes. --max-items has no effect on other formats. codeknife plan ignores it and uses --top instead.
With check --changed and a loosened threshold, the lines before the findings look like this:
CODEKNIFE check status=fail files=1 errors=0 warnings=4 infos=5 elapsed_ms=5LOOSENINGS count=1 - codeknife.toml: `max_params` raised from 5 to 9PR_BRIEF risk=high changed_files=2 dirs=2 max_diff_crap=0.0 new_suppressions=0 new_deps=0 HOTSPOT src/main.rs HOTSPOT codeknife.toml...JSON format
Section titled “JSON format”--format json prints the run report unchanged. Top-level fields:
| Field | Type | Notes |
|---|---|---|
command |
string | check, plan, a blade name, and so on |
root |
string | Repository root from --path, canonicalized when it exists |
files_scanned |
integer | Files in the code model |
elapsed_ms |
integer | Wall time |
errors, warnings, infos |
integer | Counts after baseline filtering |
passed |
boolean | Gate result; matches the exit code |
findings |
array | Finding objects |
loosenings |
array of string | Omitted when empty |
notes |
array of string | Omitted when empty |
pr_brief |
object | Omitted when absent |
Each finding has id, rule, blade, severity, location (file, start_line, end_line, and optional start_byte, end_byte, symbol), message, fix_hint and impact_score. Optional fields appear only when set: metric_value, picture, evidence (a list of file, line, label) and autofix (file, start_byte, end_byte, replacement). severity is error, warning or info; blade is the lower-case blade name. See Findings Model for what each field means.
pr_brief has changed_files, directories_touched, diff_crap_max (number or null), new_suppressions, new_dependencies, review_risk and hotspots.
SARIF format
Section titled “SARIF format”--format sarif writes a SARIF 2.1.0 document with $schema set to the OASIS 2.1.0 schema URL and one run.
| SARIF path | Value |
|---|---|
runs[0].tool.driver.name |
codeknife |
runs[0].tool.driver.version |
Binary version, for example 0.2.0 |
runs[0].tool.driver.informationUri |
https://github.com/robertguss/codeknife |
runs[0].tool.driver.rules[] |
One entry per distinct rule ID in the findings, sorted by ID |
rules[].id and rules[].shortDescription.text |
The rule ID |
rules[].help.text |
The fix hint of the first finding with that rule |
rules[].defaultConfiguration.level |
The level of the first finding with that rule |
results[].ruleId |
Rule ID |
results[].level |
Mapped severity |
results[].message.text |
<message> — fix: <fix hint> |
results[].locations[0]...artifactLocation.uri |
Finding file path, relative to the root |
results[].locations[0]...region.startLine |
Start line, at least 1 |
results[].locations[0]...region.endLine |
End line, at least startLine |
| CodeKnife severity | SARIF level |
|---|---|
error |
error |
warning |
warning |
info |
note |
Not carried into SARIF: finding id, blade, symbol, byte offsets, impact_score, metric_value, evidence, picture, autofix, and the report’s notes, loosenings, pr_brief and passed.
Markdown format
Section titled “Markdown format”--format markdown prints, in order:
- A heading:
## CodeKnife `<command>` — PASSorFAIL. - A table with Files, Errors, Warnings, Info and Elapsed.
- When present,
### PR Risk Briefand a table with Risk (upper case, bold), Changed Files, Dirs, Max Diff-CRAP (-when there is no value), New Suppressions, New Deps and Hotspots. - When there are loosenings, a
> [!CAUTION]callout listing each one. - A findings table with Severity, Rule, Location (
file:start_line), Message and Fix Hint, sorted like Agent output. The first 25 rows go in the table. The rest go in a second table inside<details>with the summary<n> more findings. With no findings,_No findings._is printed instead. - One italic bullet per note.
Pipe characters in cell text are escaped as \|, and line breaks become spaces.
The same loosened check --changed run in Markdown:
### PR Risk Brief
| Risk | Changed Files | Dirs | Max Diff-CRAP | New Suppressions | New Deps | Hotspots || --- | ---: | ---: | ---: | ---: | ---: | --- || **HIGH** | 2 | 2 | - | 0 | 0 | src/main.rs, codeknife.toml |
> [!CAUTION]> Config or gate loosening detected:> - codeknife.toml: `max_params` raised from 5 to 9ASCII pictures
Section titled “ASCII pictures”Some findings carry a small box-drawing diagram. Pictures are drawn only in Human output, indented four spaces under the location. JSON output includes the picture as data (a picture object with a kind of circle, spread, lists or bar). Agent, SARIF and Markdown output leave pictures out.
| Kind | Drawn for | Shape |
|---|---|---|
circle |
CK_ARCH_MODULE_CYCLE, CK_ARCH_TANGLE |
A loop of members. The first step starts with ┌─▶, each step shows site uses, arrows ▼ link steps, and └─────┘ closes the loop. |
bar |
CK_ARCH_LONG_FILE, CK_ARCH_WIDE_DIR, CK_BLAST_IMPACT, CK_CHURN_HOTSPOT |
One labelled bar, 36 characters at full scale. The bar uses █ when the value is over its limit and ▓ otherwise. |
lists |
CK_ARCH_SHALLOW_MODULE |
Bars for shows, hides and each listed item, against a fixed limit of 7 |
spread |
CK_ARCH_FIELD_LEAK |
The owner, then the field with ◀ and one branch (┳━, ┣━, ┗━) per module with its reference count, then dimmed other leak: lines |
The full rules behind each finding are on 2. Architecture, 10. Blast Radius and 9. Churn.
A real codeknife --no-cache --format human arch run on a Python demo with an import cycle, a 562-line file and 18 files in the root:
error[CK_ARCH_MODULE_CYCLE]: module dependency cycle across 2 modules: pkg.a <-> pkg.b --> pkg/a.py:4 (pkg.a -> pkg.b) = note: pkg/a.py:4 — uses `fb` = note: pkg/b.py:5 — uses `fa` ┌─▶ pkg.a │ ┃ pkg/a.py:4 uses `fb` │ ▼ │ pkg.b │ │ pkg/b.py:5 uses `fa` └─────┘ = fix: Invert the dependency or extract shared types/traits into a lower-layer module so imports form a DAG. Cheapest cut: `pkg.a` -> `pkg.b` (1 site(s)).
...
warning[CK_ARCH_WIDE_DIR]: wide directory `.` has 18 items (limit 15) --> .:1 (.) . │ 18 ████████████████████████████████████ = fix: Group related files into cohesive domain subdirectories so each directory stays scannable.
warning[CK_ARCH_LONG_FILE]: file `long.py` has 562 production lines (recommended <= 500) --> long.py:1-562 (long.py) long.py │ 562 ████████████████████████████████████ = fix: Consider splitting independent responsibilities before this file becomes monolithic.
...codeknife arch: FAIL (21 files, 1 errors, 4 warnings, 0 info, 13ms)With colour on, the first step’s ┃ and ▼ and over-limit bars are red and bold, member names are bold, and under-limit bars are dimmed.
Commands with their own report shape
Section titled “Commands with their own report shape”The formats above apply to check, plan (without --grouped), map, blast, and the blade commands comments, arch, clones, dead, slop, sec, tests, mutate, churn, deps and docs. Other commands print their own report:
| Command | json and sarif |
human, agent, markdown |
|---|---|---|
fix |
Fix report as JSON | agent: a CODEKNIFE fix mode=... passes=... applied=... reverted=... conflicts=... files=... header. human and markdown: a codeknife fix (<mode>): ... sentence. Then [FIX], [REVERT] and NOTE: lines. |
test |
Smart test outcome as JSON | CODEKNIFE test status=... plus [TEST], [CMD], [FAIL] lines, in all three |
verify |
Verify report as JSON | CODEKNIFE verify status=... plus work orders, in all three |
dossier |
Dossier as JSON | CODEKNIFE dossier mode=... text, in all three |
reuse |
Reuse report as JSON | CODEKNIFE reuse query=... text, in all three |
plan --grouped |
Work orders as JSON | CODEKNIFE work_orders count=... text, in all three |
score |
Score report as JSON | Separate Human, Agent and Markdown layouts. See Health Scorecard. |
arch --infer |
Inferred rules as JSON | The inferred arch.toml text |
init, baseline, hook, skill, usage and mcp ignore --format.
Exit codes
Section titled “Exit codes”Every code below was measured by running the command against a demo repository with warnings (fail) and a clean one (pass). The format does not change the exit code: check exits 1 on the failing demo in all six formats.
| Command | 0 |
1 |
2 |
|---|---|---|---|
check |
No error or warning findings remain after the baseline, and no loosenings | An error or warning remains, or a loosening was detected | Usage or runtime error |
comments, arch, clones, dead, slop, sec, tests, mutate, churn, blast, deps, docs |
No error or warning finding remains after the baseline | An error or warning remains | Usage or runtime error |
arch --infer |
Always on success | Never | Runtime error |
plan, plan --grouped |
Always on success, even with findings | Never | Runtime error |
map |
Always on success | Never | Runtime error |
fix |
Dry run, or any patch kept | --write --verify and every patch was reverted |
Runtime error |
test |
All commands passed, or --dry-run |
A test command failed | Runtime error |
verify |
Check passed and tests passed or were skipped | Check failed or a test command failed | Runtime error |
dossier, reuse, score |
Always on success | Never | Runtime error, for example reuse --lang cobol |
init |
Files written or skipped | Never | A file could not be written |
baseline update, baseline prune |
Always on success | Never | Runtime error |
baseline merge-driver |
Merged | One of the three inputs is not a valid baseline | An input file cannot be read |
hook claude, hook cursor |
Valid event, allow or deny | Never | Stdin is not valid JSON |
skill, usage |
Always | Never | Never |
mcp |
Stdin closed | Never | I/O error, including non-UTF-8 input |
--help, --version |
Always | Never | Never |
| Unknown command or bad flag value | Never | Never | Always |
Info findings never fail a command. Runtime errors print codeknife error: <message> on stderr; usage errors print clap’s error: ... message.
A few measured runs:
1 :: --path sloppy --no-cache --format agent check0 :: --path clean --no-cache --format agent check0 :: --path sloppy --no-cache --format agent plan1 :: --path sloppy --no-cache --format agent verify --skip-tests1 :: --path clean --no-cache --format agent test --test-cmd false1 :: --path fixrepo --no-cache --format agent fix --write --verify --verify-cmd false1 :: baseline merge-driver g1 g1 g12 :: baseline merge-driver nope1 nope2 nope32 :: --path badcfg --no-cache --format agent check2 :: --path sloppy --no-cache --format agent reuse x --lang cobol2 :: frobnicate