Work Orders (plan)
codeknife plan turns the findings of the static suite into a short, ranked to-do list. Use it when you (or a coding agent) want to know what to fix first instead of reading every finding from check.
It has two modes:
- Plain (default): a ranked list of individual findings, one per symbol, in the normal report format.
- Grouped (
--grouped): findings that share a root cause are merged into work orders. Each work order has a priority score, blast radius, churn, CRAP, suggested steps and, where the evidence allows it, a structured refactor recipe.
plan never fails the build. It always exits 0 unless CodeKnife itself errors.
Quick start
Section titled “Quick start”The examples on this page use a small demo repository with a Python function that has several problems (shell injection, deep nesting, too many parameters), a Rust struct with two unrelated halves, and two near-identical TypeScript functions. The repository has five commits, and src/engine.py was changed in all of them.
Plain mode
Section titled “Plain mode”codeknife --no-cache --format agent planCODEKNIFE plan status=pass files=8 errors=1 warnings=3 infos=0 elapsed_ms=6[1] ERROR CK_SEC_CMD_INJECTION src/engine.py:11-11 sym=- impact=100 | shell command execution with shell=True / sh -c / child_process.exec | fix: Pass an explicit argument array to `Command::new` / `execFile` / `subprocess.run(..., shell=False)`.[2] WARNING CK_ARCH_COGNITIVE_COMPLEXITY src/engine.py:4-16 sym=src.engine.validate_order impact=100 | `validate_order` cognitive complexity is 16 (limit 15) | fix: Flatten nested conditionals using early returns, match tables, or domain helpers.[3] WARNING CK_ARCH_LOW_COHESION src/hub.rs:1-6 sym=shop::hub::Hub impact=72 | `Hub` has LCOM4 = 2 disjoint method/field clusters | fix: Split along natural cohesion seams: Cluster 1: methods=[billing_add, billing_clear, billing_tax] fields=[billing_rate, billing_total] | Cluster 2: methods=[cache_grow, cache_hit, cache_ratio] fields=[cache_hits, cache_size][4] WARNING CK_CLONE_BLOCK src/a.ts:1-16 sym=src/a/scoreOrder impact=60 | AST clone cluster (2 copies, 86% structural similarity, ~16 lines) | fix: Extract the shared logic into one reusable helper parameterized on the differing values.NOTE no coverage file found (running complexity-only mode); generate one with: cargo llvm-cov --lcov --output-path lcov.info | npx vitest run --coverage | pytest --cov --cov-report=xml:coverage.xmlNOTE analyzed 5 commit(s) over the last 90 day(s)NOTE showing top 4 prioritized work order(s) ranked by impact x churn + CRAPcheck reports six warnings and errors for this repository. plan shows four, because the three validate_order findings share one file and symbol and only the highest-ranked one is kept. The impact column is the plan score, not the blade’s original impact.
Grouped mode
Section titled “Grouped mode”codeknife --no-cache --format agent plan --groupedCODEKNIFE work_orders count=4[WO #1] score=100.0 sev=error auto=false blast=0/0 | [security] CK_SEC_CMD_INJECTION in `src/engine.py` | src/engine.py:11-11 cause: shell command execution with shell=True / sh -c / child_process.exec step: Pass an explicit argument array to `Command::new` / `execFile` / `subprocess.run(..., shell=False)`.[WO #2] score=100.0 sev=warning auto=false blast=1/1 | [architecture] CK_ARCH_COGNITIVE_COMPLEXITY in `src.engine.validate_order` | src/engine.py:4-16 cause: `validate_order` cognitive complexity is 16 (limit 15) (+2 related finding(s) in same scope) step: Flatten nested conditionals using early returns, match tables, or domain helpers. step: Inspect 1 upstream caller(s) via `codeknife blast --symbol src.engine.validate_order` before refactoring.[WO #3] score=81.0 sev=warning auto=false blast=0/1 | [architecture] CK_ARCH_LOW_COHESION in `shop::hub::Hub` | src/hub.rs:1-6 cause: `Hub` has LCOM4 = 2 disjoint method/field clusters recipe: cohesion_split type `shop::hub::Hub` into 2 partitions: Billing(3m/2f) | Cache(3m/2f) step: Recipe: cohesion_split type `shop::hub::Hub` into 2 partitions: Billing(3m/2f) | Cache(3m/2f) step: Split along natural cohesion seams: Cluster 1: methods=[billing_add, billing_clear, billing_tax] fields=[billing_rate, billing_total] | Cluster 2: methods=[cache_grow, cache_hit, cache_ratio] fields=[cache_hits, cache_size][WO #4] score=59.4 sev=warning auto=false blast=1/2 | [duplication] CK_CLONE_BLOCK in `src/a/scoreOrder` | src/a.ts:1-16 cause: AST clone cluster (2 copies, 86% structural similarity, ~16 lines) recipe: clone_extract (100% shared across 2 copies) params=[value_1 [order | invoice], value_2 [10 | 25]] -> Extract shared helper taking extra parameter(s): value_1 (order | invoice), value_2 (10 | 25) step: Recipe: clone_extract (100% shared across 2 copies) params=[value_1 [order | invoice], value_2 [10 | 25]] -> Extract shared helper taking extra parameter(s): value_1 (order | invoice), value_2 (10 | 25) step: Extract the shared logic into one reusable helper parameterized on the differing values. step: Inspect 1 upstream caller(s) via `codeknife blast --symbol src/a/scoreOrder` before refactoring.Work order 2 holds all three validate_order findings (+2 related finding(s)). Work orders 3 and 4 carry refactor recipes.
| Flag | Default | Effect |
|---|---|---|
--top N |
10 |
Maximum number of findings (plain) or work orders (grouped). 0 is treated as 1. |
--grouped |
off | Emit root-cause work orders instead of ranked findings. |
--coverage PATH |
none | Coverage report to load. Without it, the first entry of coverage.paths in codeknife.toml is used, and if that is empty the tests blade looks for a report itself. Coverage feeds the CRAP part of the ranking. A missing file is an error (exit 2). See Coverage Reports. |
Global flags that matter here:
--format: plain mode supports every format. Grouped mode prints JSON forjsonandsarif(the same JSON array for both, not SARIF) and the text layout shown above foragent,humanandmarkdown.--changed(with an optional--sincebase ref): the static suite runs on changed files only. See Paths, Excludes & Changed Scope.--strict: stricter thresholds, so more findings to rank.--max-items: ignored. Plain mode always passes--topas the item cap to the agent renderer.--no-cache: no.codeknife/files are written.
Both modes load codeknife.baseline first and drop every baselined finding. In plain mode a note reports how many were dropped. See Ratchet Baseline.
How plain mode ranks findings
Section titled “How plain mode ranks findings”-
Run the full static suite (the same blades as
checkat the standard tier). -
Drop baselined findings and every
infofinding. -
Score each remaining finding:
score = min(100, impact × (1 + min(churn, 10) × 0.1) + min(max_crap, 30) × 0.4)impactis the blade’simpact_scorefor the finding.churnis the number of commits that touched the file in the churn window (the churn blade’schurn.days, default 90).max_crapis the highest CRAP score of any function in the same file. It is0when no coverage is loaded.
-
Sort by score (high first), then severity, then file path, then start line.
-
Walk the sorted list and keep one finding per key. The key is the file plus the symbol, or the file plus the rule ID when the finding has no symbol. Stop after
--topfindings.
The output is a normal report (see Output Formats & Exit Codes) with these differences:
- Each finding’s
impact_scoreis replaced by the plan score. errors,warningsandinfoscount only the findings shown.passedis alwaystrue.- A note
showing top N prioritized work order(s) ranked by impact x churn + CRAPis added.
How grouped mode builds work orders
Section titled “How grouped mode builds work orders”1. Clustering
Section titled “1. Clustering”Every non-info, non-baselined finding gets a cluster key. Findings with the same key become one work order. The first rule that matches wins:
| Finding | Cluster key |
|---|---|
Rule starts with CK_CLONE_ |
clone: file : finding id. Every clone finding is its own work order. |
Rule is CK_ARCH_CYCLE or CK_ARCH_LAYER_VIOLATION |
arch: file : rule. All of these in one file merge. |
| Finding has a symbol | sym: file : symbol. All findings on that exact symbol string in that file merge, across blades. |
| Anything else | file: file : category. Symbol-less findings in one file merge by category (see below). |
The work order id is WO- followed by the first 8 hex digits of the xxh3 hash of the cluster key, so it stays the same between runs as long as the key does.
2. Primary finding and fields
Section titled “2. Primary finding and fields”Inside a cluster, findings are sorted by severity (high first), then impact (high first), then start line. The first one is the primary finding. The work order takes from it:
severity, and thecategory(table below),title: the category in brackets, the primary rule ID,in, and the symbol (or the file path when there is no symbol) in backticks, for example[architecture] CK_ARCH_LOW_COHESION in `shop::hub::Hub`,root_cause: the primary message, plus(+N related finding(s) in same scope)when the cluster has more than one finding.
Other fields: symbol is the first symbol found in the sorted cluster; start_line and end_line span all findings; rules is the sorted, de-duplicated list of rule IDs; finding_count is the cluster size; findings lists the first 8 findings.
3. Categories
Section titled “3. Categories”| Category | Assigned when |
|---|---|
complexity |
Rule is CK_ARCH_LONG_FN, CK_ARCH_COGNITIVE, CK_ARCH_DEEP_NESTING or CK_ARCH_TOO_MANY_PARAMS |
security |
Blade sec or guard |
architecture |
Any other arch finding |
duplication |
Blade clones |
dead_code |
Blade dead |
testing |
Blade tests or mutate |
docs_deps |
Blade deps or docs |
hygiene |
Blade slop or comments |
correctness |
Blade blast, churn or map |
4. Priority score
Section titled “4. Priority score”base = max_impact + min(0.25 × (sum of the other findings' impact), 30)boost = 18 for security, 10 for architecture or correctness, 0 otherwisechurn_mult = 1 + min(churn, 10) × 0.08crap_bonus = min(max_crap, 30) × 0.35priority = min(100, (base + boost) × churn_mult + crap_bonus)churnis the commit count for the work order’s file.max_crapis the CRAP score of the function whose qualified name equals the work order’s symbol, or else the highest CRAP in the file. It isnullwithout coverage.
Example from the demo: the clone work order has one finding with impact 55, no boost, and src/a.ts has one commit, so 55 × 1.08 = 59.4.
Work orders are sorted by priority, then severity, then file, then start line, then id. The list is cut to --top and numbered from 1 (rank).
5. Blast radius
Section titled “5. Blast radius”For each kept work order that has a symbol, CodeKnife runs Blast Radius for that symbol and copies blast_callers (upstream callers), blast_files (affected files), up to 6 covering_tests and up to 6 boundary_contracts. It uses the cone for the exact symbol, else any cone in the same file, else the first cone returned. Work orders without a symbol keep 0 and empty lists.
6. Suggested steps
Section titled “6. Suggested steps”Built in this order and cut to 4:
- If
autofixable:Run `codeknife fix --write --verify` to apply deterministic safe fixes cleanly. - If there is a recipe:
Recipe:plus the first recipe’s summary line. - The primary finding’s fix hint, if it is not empty.
- If there are covering tests:
Verify affected behavior with `codeknife test` covering N test(s).Otherwise, if there are upstream callers:Inspect N upstream caller(s) via `codeknife blast --symbol SYMBOL` before refactoring.
7. Autofixable rules
Section titled “7. Autofixable rules”autofixable is true when any rule in the work order is one of:
CK_CMT_STRIP, CK_DEAD_SYMBOL, CK_DEAD_UNUSED_IMPORT, CK_DEAD_ONE_CALLER_WRAPPER, CK_SLOP_DEBUG_LEFTOVER, CK_GUARD_SUPPRESSION_EXPIRED, CK_SLOP_NO_TIMEOUT, CK_DOC_DEAD_PATH, CK_DEP_UNUSED.
Example from the sloppy_polyglot fixture, where a dead private function is autofixable:
[WO #3] score=55.0 sev=warning auto=true blast=0/1 | [dead_code] CK_DEAD_SYMBOL in `sloppy_demo::dead_private_fn` | src/main.rs:22-24 cause: unreachable internal symbol `dead_private_fn` step: Run `codeknife fix --write --verify` to apply deterministic safe fixes cleanly. step: Delete this unused function (or run `codeknife dead --fix --write`).Refactor recipes
Section titled “Refactor recipes”A work order can carry up to 3 recipes, de-duplicated. Recipes come from the cluster’s findings in order. Only three rules produce one:
| Rule | Recipe | Needs |
|---|---|---|
CK_CLONE_BLOCK, CK_CLONE_REINVENTED_HELPER |
clone_extract |
At least one evidence span (a peer copy) on the finding, and both copies must parse. |
CK_ARCH_LOW_COHESION |
cohesion_split, scope type |
The finding’s symbol names a struct or class in the same file; at least 2 non-trivial methods; at least 2 LCOM4 clusters. |
CK_ARCH_LONG_FILE |
cohesion_split, scope file |
At least 4 functions, methods, structs or classes (non-test) in the file, falling into at least 2 connected groups. |
clone_extract
Section titled “clone_extract”The recipe compares the primary copy (the finding’s location) with the first peer copy from the finding’s evidence. Up to 3 peers are listed in copies, but only the first is diffed.
- Both line ranges are parsed with tree-sitter. Leaves are collected, skipping comments and the punctuation
{ } ( ) [ ] ; , : . :: => ->, up to 350 leaves per copy. - Each leaf gets a role:
literal,callee(the function being called),identifier,operatororkeyword. - The two leaf sequences are aligned with a longest-common-subsequence match on (role, node kind).
shared_structure_pct = min(100, 200 × aligned / (leaves_a + leaves_b)).- For each aligned pair whose text differs (keywords and the two function names are ignored):
- An identifier that maps one-to-one between the copies, and either appears at least twice or is a parameter, is a renamed local (
renamed_locals, entries liketotal <-> acc, at most 8). - Anything else becomes a diverging parameter (
diverging_params, at most 8). Its suggested name islabel_Nfor a literal starting with a quote,value_Nfor other literals,op_fn_Nfor a callee,op_Nfor an operator andarg_Nfor an identifier.
- An identifier that maps one-to-one between the copies, and either appears at least twice or is a parameter, is a renamed local (
suggested_signatureisExtract shared helper taking extra parameter(s): ...or, with no diverging parameters,Unify into one shared helper (identical logic after renaming locals); no extra parameters needed.
Summary line format: clone_extract (PCT% shared across N copies) params=[...] -> SIGNATURE. With no parameters it reads params=[none (rename-only)].
cohesion_split, scope type
Section titled “cohesion_split, scope type”Uses the LCOM4 clusters of the type’s methods. Methods that are trait implementations, tests, or trivial are left out. Trivial means named new, default, from or into, or starting with with_, set_, get_ or is_.
shared_fields: fields used by two or more clusters. They are removed from each partition’sfields.- Each partition lists
methodsasname (Lline), itsfields, up to 6inbound_callers(qualified names of callers outside the partition) and up to 6outbound_deps.
cohesion_split, scope file
Section titled “cohesion_split, scope file”Items in the file are linked when one owns the other (method to type) or one calls the other. Each connected group is a partition. Groups are sorted by size, then by first line. Partition fields is the union of the items’ fields. Callers and dependencies in the same file are not listed.
[WO #1] score=59.4 sev=warning auto=false blast=0/0 | [architecture] CK_ARCH_LONG_FILE in `src/monolith.rs` | src/monolith.rs:1-9 cause: file `src/monolith.rs` has 9 production lines (recommended <= 8) recipe: cohesion_split file `src/monolith.rs` into 2 partitions: Render(5m/0f) | Parse(4m/0f) step: Recipe: cohesion_split file `src/monolith.rs` into 2 partitions: Render(5m/0f) | Parse(4m/0f) step: Consider splitting independent responsibilities before this file becomes monolithic.This run used warn_file_lines = 8 under [thresholds] in codeknife.toml to trigger CK_ARCH_LONG_FILE on a small file.
Partition names
Section titled “Partition names”For both scopes, each name (methods and fields) is lowercased and its first _-separated segment of 3 or more characters is taken as the stem. The most frequent stem wins, ignoring get, set, run, new, from, into, make, build, check and handle. It is used, capitalised, when it occurs at least twice or the partition has at most 2 methods. Otherwise the name is Part1, Part2, and so on.
Summary line format: cohesion_split SCOPE `TARGET` into N partitions: Name(Mm/Ff) | ..., followed by shared=[...] when there are shared fields.
Output size limits
Section titled “Output size limits”plan has no character or token budget. Output size is bounded by counts:
| Item | Limit |
|---|---|
| Findings (plain) or work orders (grouped) | --top, default 10 |
findings per work order |
8 |
covering_tests, boundary_contracts per work order |
6 each |
suggested_steps |
4 |
recipes per work order |
3 |
copies per clone recipe |
1 primary + 3 peers |
diverging_params, renamed_locals |
8 each |
inbound_callers, outbound_deps per partition |
6 each |
For a character-budgeted view with source excerpts, use Dossier.
JSON output
Section titled “JSON output”Plain mode
Section titled “Plain mode”A standard report (command is "plan"). Trimmed to --top 2:
codeknife --no-cache --format json plan --top 2{ "command": "plan", "root": ".../shop", "files_scanned": 8, "elapsed_ms": 8, "errors": 1, "warnings": 1, "infos": 0, "passed": true, "findings": [ { "id": "81aa40452b6f214f", "rule": "CK_SEC_CMD_INJECTION", "blade": "sec", "severity": "error", "location": { "file": "src/engine.py", "start_line": 11, "end_line": 11 }, "message": "shell command execution with shell=True / sh -c / child_process.exec", "fix_hint": "Pass an explicit argument array to `Command::new` / `execFile` / `subprocess.run(..., shell=False)`.", "impact_score": 100.0 },... ], "notes": [ "no coverage file found (running complexity-only mode); generate one with: cargo llvm-cov --lcov --output-path lcov.info | npx vitest run --coverage | pytest --cov --cov-report=xml:coverage.xml", "analyzed 5 commit(s) over the last 90 day(s)", "showing top 2 prioritized work order(s) ranked by impact x churn + CRAP" ]}The finding fields are described on Findings Model.
Grouped mode
Section titled “Grouped mode”A JSON array of work orders. Trimmed to the cohesion work order:
codeknife --no-cache --format json plan --grouped --top 4[... { "id": "WO-25d035c3", "rank": 3, "category": "architecture", "title": "[architecture] CK_ARCH_LOW_COHESION in `shop::hub::Hub`", "file": "src/hub.rs", "start_line": 1, "end_line": 6, "symbol": "shop::hub::Hub", "severity": "warning", "priority_score": 81.0, "rules": [ "CK_ARCH_LOW_COHESION" ], "finding_count": 1, "autofixable": false, "root_cause": "`Hub` has LCOM4 = 2 disjoint method/field clusters", "suggested_steps": [ "Recipe: cohesion_split type `shop::hub::Hub` into 2 partitions: Billing(3m/2f) | Cache(3m/2f)", "Split along natural cohesion seams: Cluster 1: methods=[billing_add, billing_clear, billing_tax] fields=[billing_rate, billing_total] | Cluster 2: methods=[cache_grow, cache_hit, cache_ratio] fields=[cache_hits, cache_size]" ], "blast_callers": 0, "blast_files": 1, "covering_tests": [], "boundary_contracts": [], "churn_commits": 1, "max_crap": null, "findings": [ { "rule": "CK_ARCH_LOW_COHESION", "severity": "warning", "line": 1, "message": "`Hub` has LCOM4 = 2 disjoint method/field clusters", "fix_hint": "Split along natural cohesion seams: Cluster 1: methods=[billing_add, billing_clear, billing_tax] fields=[billing_rate, billing_total] | Cluster 2: methods=[cache_grow, cache_hit, cache_ratio] fields=[cache_hits, cache_size]" } ], "recipes": [ { "kind": "cohesion_split", "scope": "type", "target": "shop::hub::Hub", "shared_fields": [], "partitions": [ { "suggested_name": "Billing", "methods": [ "billing_add (L9)", "billing_clear (L10)", "billing_tax (L11)" ], "fields": [ "billing_rate", "billing_total" ], "inbound_callers": [ "shop::main" ], "outbound_deps": [] },... ] } ] },...]The clone work order’s recipe from the same run:
{ "kind": "clone_extract", "copies": [ "src/a.ts:1-16 (src/a/scoreOrder)", "src/b.ts:1-16 (src/b/scoreInvoice)" ], "shared_structure_pct": 100, "diverging_params": [ { "suggested_name": "value_1", "kind": "literal", "values": [ "order", "invoice" ] }, { "suggested_name": "value_2", "kind": "literal", "values": [ "10", "25" ] } ], "renamed_locals": [ "items <-> rows", "rate <-> mult", "total <-> acc", "item <-> row", "taxed <-> scaled" ], "suggested_signature": "Extract shared helper taking extra parameter(s): value_1 (order | invoice), value_2 (10 | 25)"}Work order fields
Section titled “Work order fields”| Field | Type | Meaning |
|---|---|---|
id |
string | WO- plus 8 hex digits of the cluster key hash |
rank |
number | Position after sorting, from 1 |
category |
string | One of the categories above |
title |
string | Category, primary rule and target, as described above |
file |
string | File of the primary finding |
start_line, end_line |
number | Span over all findings in the cluster |
symbol |
string or null | First symbol in the cluster |
severity |
string | Severity of the primary finding |
priority_score |
number | 0 to 100, formula above |
rules |
string array | Sorted, unique rule IDs |
finding_count |
number | Findings in the cluster |
autofixable |
bool | Any rule is in the autofixable list |
root_cause |
string | Primary message, plus the related count |
suggested_steps |
string array | Up to 4 steps |
blast_callers, blast_files |
number | From the blast cone, 0 without a symbol |
covering_tests, boundary_contracts |
string array | Up to 6 each |
churn_commits |
number | Commits touching the file |
max_crap |
number or null | CRAP of the symbol or the file’s worst function |
findings |
array | Up to 8 of rule, severity, line, message, fix_hint |
recipes |
array | Omitted when empty. Tagged by kind: clone_extract or cohesion_split |
Recipe fields:
| Recipe | Fields |
|---|---|
clone_extract |
copies (strings file:start-end (symbol)), shared_structure_pct (0 to 100), diverging_params (each suggested_name, kind, values), renamed_locals (strings a <-> b), suggested_signature |
cohesion_split |
scope (type or file), target (qualified type name or file path), shared_fields, partitions (each suggested_name, methods, fields, inbound_callers, outbound_deps) |
Using coverage
Section titled “Using coverage”With a coverage report loaded, CRAP scores feed both modes. In the demo, loading a hand-written lcov file gave the clone work order a max_crap of 12 and raised its priority from 59.4 to 63.6 (+ 12 × 0.35). How CRAP is computed is described on Tests & CRAP.
codeknife --no-cache --format json plan --grouped --coverage ../engine.lcov... "priority_score": 63.600002,... "max_crap": 12.0,Rule IDs
Section titled “Rule IDs”plan does not emit findings of its own. It re-ranks findings from the other blades. The rule IDs it treats specially are listed in the sections above: the autofixable list, the complexity category list, the two clustering rules, and the three recipe rules. The full catalogue is on Rule Catalogue.
Exit codes
Section titled “Exit codes”| Code | When |
|---|---|
0 |
Always, in both modes, whatever the findings |
2 |
CodeKnife error, for example an unreadable codeknife.toml |
An empty grouped result prints:
CODEKNIFE work_orders count=0 (no active actionable findings outside codeknife.baseline)Also available via
Section titled “Also available via”- Dossier (
codeknife dossier, and the MCP toolcodeknife_dossier) embeds the same grouped work orders, default--top 8, plus source excerpts. - Verify Pipeline (
codeknife verify, MCP toolcodeknife_verify) attaches up to 6 work orders when the check fails. - There is no MCP tool for
planitself.