Skip to content

codeknife.toml

codeknife.toml sets the thresholds, excludes, blade toggles and policy that CodeKnife applies to a repository. You do not need one: with no file, CodeKnife runs with built-in defaults. Add one when you want to tune a limit, turn a blade off in the gate, or point CodeKnife at a coverage report.

codeknife init writes a starter file that contains every default value:

Terminal window
codeknife init
wrote .../init/codeknife.toml
wrote .../init/codeknife.baseline
wrote .../init/arch.toml

The starter codeknife.toml it writes is the full default configuration:

strictness = "default"
exclude = [
"target/**",
"node_modules/**",
"vendor/**",
"dist/**",
"build/**",
".venv/**",
"__pycache__/**",
"**/*.min.js",
"**/*.generated.*",
]
[thresholds]
max_file_lines = 1000
warn_file_lines = 500
max_fn_lines = 60
max_cognitive_complexity = 15
max_nesting = 4
max_params = 5
max_bool_params = 2
held_in_mind = 7
max_dir_members = 15
clone_similarity = 0.82
clone_min_lines = 10
clone_min_nodes = 45
dto_field_overlap = 0.8
max_crap = 15.0
temporal_coupling_min_commits = 5
temporal_coupling_ratio = 0.6
thrash_min_edits = 4
[blades]
comments = true
arch = true
clones = true
dead = true
slop = true
sec = true
tests = true
churn = true
deps = true
docs = true
[suppressions]
max_days = 90
always_block = [
"@ts-ignore",
"@ts-nocheck",
"#[allow(clippy::all)]",
"#[allow(warnings)]",
]
require_reason_and_expiry = true
[coverage]
paths = []
[mutate]
timeout_multiplier = 3
min_timeout_secs = 5
max_jobs = 4
top_crap = 10
[comments]
keep_pub_docs = true
narration_overlap_threshold = 0.65
max_inline_prose_lines = 4
[churn]
days = 90

The two optional keys coverage.command and mutate.test_command have no default, so the starter file leaves them out.

init only writes codeknife.toml when it does not exist, or when you pass --force. Otherwise it prints exists .../codeknife.toml (pass --force to overwrite) and exits 0. See Init, Skill & Usage Spec for the other files init writes.

A real configuration usually sets only the keys it changes. Every section and key is optional, and any key you leave out keeps its default:

[thresholds]
max_fn_lines = 100
max_params = 2
  • CodeKnife reads codeknife.toml from the analysis root only, which is the --path directory (default: the current directory). It does not search parent directories.
  • If the file does not exist, CodeKnife uses the defaults shown above.
  • Every command that analyzes code loads it. This includes check, plan, map, score, dossier, verify, fix, test, baseline update, baseline prune, every single-blade command, and the MCP server tools. init, skill, usage, hook and baseline merge-driver do not load it.
  • arch.toml is a separate file in the same root. It holds layer rules for the Architecture blade. Its format is on 2. Architecture.

Each section fills in missing keys with their defaults. For example, this file changes two thresholds and keeps the other fifteen at their defaults:

[thresholds]
max_fn_lines = 100
max_params = 2
Terminal window
codeknife --no-cache --format agent arch
CODEKNIFE arch status=fail files=1 errors=0 warnings=1 infos=0 elapsed_ms=3
[1] WARNING CK_ARCH_TOO_MANY_PARAMS src/lib.rs:50-52 sym=cfgdemo::five impact=45 | `five` takes 5 parameters (limit 2) | fix: Group cohesive parameters into an options or domain context struct.

exclude is a list. If you set it, your list replaces the nine default patterns. It is not merged with them. To keep the defaults, copy them into your list. For example, with exclude = ["out/**"], a file named web/api.generated.ts is analyzed again, because **/*.generated.* is no longer in the list. The walker still skips some directories by name whatever exclude says. See Paths, Excludes & Changed Scope.

Key Type Default What reads it
strictness "default" or "strict" "default" Config loading. "strict" has the same effect as --strict. See Strict mode.
exclude list of glob strings the nine patterns above The file walker, for every command that builds the code model. Patterns match the path relative to the root.
Key Type Default Strict value What reads it
max_file_lines integer 1000 min(value, 400) Arch blade: CK_ARCH_LONG_FILE as an error when a file’s production line count is greater than this.
warn_file_lines integer 500 not changed Arch blade: CK_ARCH_LONG_FILE as a warning above this. Also gates the arch cohesion check (files at or under this size need 6 or more methods on a type to be checked) and CK_CHURN_BLOAT_VELOCITY (files below this size are skipped).
max_fn_lines integer 60 min(value, 40) Arch blade: CK_ARCH_LONG_FN when a function has more lines than this.
max_cognitive_complexity integer 15 min(value, 10) Arch blade: CK_ARCH_COGNITIVE_COMPLEXITY above this. Churn blade: a CK_CHURN_HOTSPOT becomes a warning when a file’s most complex function exceeds it (and the file has 6 or more commits).
max_nesting integer 4 min(value, 3) Arch blade: CK_ARCH_DEEP_NESTING above this.
max_params integer 5 min(value, 4) Arch blade: CK_ARCH_TOO_MANY_PARAMS above this.
max_bool_params integer 2 not changed Arch blade: CK_ARCH_BOOL_TRAP when a function has this many or more boolean parameters. Note that this comparison is “at least”, not “more than”.
held_in_mind integer 7 not changed Arch blade: the limit for CK_ARCH_SHALLOW_MODULE. In CK_ARCH_TANGLE, a tangle inside one module is only reported when it has more items than this, and the diagram lists at most this many items.
max_dir_members integer 15 not changed Arch blade: CK_ARCH_WIDE_DIR when a directory has more entries than this.
clone_similarity float 0.82 not changed Clones blade: minimum similarity for CK_CLONE_BLOCK. codeknife clones --threshold overrides it for that command.
clone_min_lines integer 10 not changed Clones blade: minimum function length to be a clone candidate. Clusters are only reported when the fragments are at least max(clone_min_lines, 12) lines.
clone_min_nodes integer 45 not changed Clones blade: minimum normalized token count to be a clone candidate.
dto_field_overlap float 0.8 not changed Clones blade: minimum field overlap for CK_CLONE_DTO_SHAPE.
max_crap float 15.0 min(value, 10.0) Tests blade: CK_TEST_HIGH_CRAP when a function’s CRAP score is greater than this. The finding is an error at a score of 30 or more, otherwise a warning.
temporal_coupling_min_commits integer 5 not changed Churn blade: minimum shared commits for CK_CHURN_TEMPORAL_COUPLING. Values below 3 act as 3.
temporal_coupling_ratio float 0.6 not changed Churn blade: minimum co-change ratio for CK_CHURN_TEMPORAL_COUPLING.
thrash_min_edits integer 4 not changed Churn blade: CK_CHURN_THRASH uses max(value, 3) edits in the last 7 days. CK_CHURN_HOTSPOT uses max(value, 4) commits in the window.

Integer thresholds must be non-negative whole numbers. A negative value is a parse error.

Key Type Default What reads it
comments bool true The static suite
arch bool true The static suite
clones bool true The static suite
dead bool true The static suite
slop bool true The static suite
sec bool true The static suite
tests bool true The static suite (see below)
churn bool true The static suite
deps bool true The static suite
docs bool true The static suite

The “static suite” is the shared run used by check, plan, map, score, dossier, verify, baseline update, baseline prune and the MCP codeknife_check tool. Setting a toggle to false removes that blade’s findings from those commands.

The toggles do not affect the single-blade commands. With arch = false, codeknife check reports nothing from the Architecture blade, but codeknife arch still runs it and reports:

Terminal window
codeknife --no-cache --format agent check
CODEKNIFE check status=pass files=1 errors=0 warnings=0 infos=0 elapsed_ms=6
NOTE no coverage file found (running complexity-only mode); generate one with: cargo llvm-cov --lcov --output-path lcov.info
NOTE no git repository found; skipping churn forensics
Terminal window
codeknife --no-cache --format agent arch
CODEKNIFE arch status=fail files=1 errors=0 warnings=1 infos=0 elapsed_ms=2
[1] WARNING CK_ARCH_TOO_MANY_PARAMS src/lib.rs:50-52 sym=cfgdemo::five impact=45 | `five` takes 5 parameters (limit 2) | fix: Group cohesive parameters into an options or domain context struct.

When tests = false, the Tests blade still runs inside the static suite, because its per-function CRAP metrics feed .codeknife/metrics.json, plan ranking and the PR risk brief. Only its findings and notes are dropped.

There are no toggles for Mutation Testing, Blast Radius or the Garden Map. Those run only when you ask for them. In check --changed, the Blast Radius blade always runs when the changed set is not empty.

Turning a blade off is a loosening. The Loosening Guard reports codeknife.toml: disabled blade `blades.<name>` when a toggle goes from true to false against the base ref.

Key Type Default What reads it
max_days integer 90 The guard’s suppression check: a new suppression whose expiry is further away than this is reported.
always_block list of strings @ts-ignore, @ts-nocheck, #[allow(clippy::all)], #[allow(warnings)] The guard: suppressions matching these markers are reported as CK_GUARD_ALWAYS_BLOCK_SUPPRESSION.
require_reason_and_expiry bool true The guard: when true, new suppressions without a reason or an expiry are reported.

The guard runs inside the static suite. The rules it emits and the until: YYYY-MM-DD syntax are on The Check Gate and Loosening Guard. Raising max_days, removing an always_block entry or turning off require_reason_and_expiry are all reported as loosenings.

Key Type Default What reads it
paths list of strings [] Coverage loading. In the Tests and Mutation blades, these paths are tried first, relative to the root, before the built-in discovery list. In the static suite, only the first entry is used, and it is opened as given. See Coverage Reports.
command string not set Nothing. The key is parsed and never read.
Key Type Default What reads it
test_command string not set Mutation blade: the test command when --test-command is not given.
timeout_multiplier integer 3 Mutation blade: multiplier applied to the measured baseline test time to get each mutant’s timeout.
min_timeout_secs integer 5 Mutation blade: lower bound for that timeout, in seconds.
max_jobs integer 4 Mutation blade: worker count when --jobs is not given.
top_crap integer 10 Mutation blade: how many highest-CRAP functions to mutate when --top is not given. check --tier full always passes this value.

With codeknife mutate --changed and no --top, the mutation blade does not apply top_crap: it takes every scored function. Details are on 8. Mutation Testing.

Key Type Default What reads it
keep_pub_docs bool true Comments blade classifier: when true, doc comments are kept (unless they only echo the symbol), except when you pass --strip-pub-docs.
narration_overlap_threshold float 0.65 Comments blade classifier: overlap threshold for classifying a comment as narration that restates the adjacent code.
max_inline_prose_lines integer 4 Comments blade classifier: a comment inside a function body that spans more lines than this is classified as an apology or “sermon” comment.

See 1. Comments for the rules these feed.

Key Type Default What reads it
days integer 90 The static suite’s Churn run: the history window in days.

Strict mode is on when you pass --strict or set strictness = "strict". Both do the same thing. Strict mode only tightens: each threshold becomes the smaller of your value and the strict limit.

Threshold Default Strict limit
max_file_lines 1000 400
max_fn_lines 60 40
max_cognitive_complexity 15 10
max_crap 15.0 10.0
max_params 5 4
max_nesting 4 3

So max_fn_lines = 100 with --strict gives 40, and max_params = 2 with --strict stays 2.

Strict mode also changes these rules:

Rule Default behaviour Strict behaviour
CK_TEST_ZERO_ASSERT warning error
CK_TEST_WEAK_ASSERT warning error
CK_SLOP_PLACEHOLDER matches changeme, lorem ipsum, replace_me, and strings starting your-api-key also matches the strings placeholder and todo
CK_CHURN_THRASH warning at thrash_min + 2 edits in 7 days warning at more than thrash_min edits in 7 days

A file with no config, then with --strict:

Terminal window
codeknife --no-cache --format agent arch
CODEKNIFE arch status=pass files=1 errors=0 warnings=0 infos=0 elapsed_ms=3
Terminal window
codeknife --no-cache --strict --format agent arch
CODEKNIFE arch status=fail files=1 errors=0 warnings=2 infos=0 elapsed_ms=2
[1] WARNING CK_ARCH_LONG_FN src/lib.rs:1-48 sym=cfgdemo::long_fn impact=60 | `long_fn` is 48 lines (limit 40) | fix: Extract meaningful phase-level abstractions rather than mechanical line cuts.
[2] WARNING CK_ARCH_TOO_MANY_PARAMS src/lib.rs:50-52 sym=cfgdemo::five impact=45 | `five` takes 5 parameters (limit 4) | fix: Group cohesive parameters into an options or domain context struct.

Changing strictness from "strict" to "default" is reported by the Loosening Guard.

The guard compares your codeknife.toml with the copy at the base ref. It reports a loosening when any integer or float threshold is raised, strictness goes from strict to default, a blade is disabled, an exclude pattern is added, the file is deleted, an always_block marker is removed, max_days is raised, or require_reason_and_expiry is turned off. A loosening fails the gate. Full details: Loosening Guard.

arch.toml is parsed by the same module. Its top-level keys are layers (array of tables with name and paths), deny (array of tables with from, to and an optional reason), allow_only (array of tables with from and allow) and private_internals (list of globs). All four default to empty. init writes a commented-out sample [[deny]] rule. What the rules do is on 2. Architecture.

CodeKnife does not reject keys it does not know. A typo such as stricness or max_fn_linez, or a whole unknown section, is silently ignored and the default applies:

stricness = "strict"
[thresholds]
max_fn_linez = 10
[nonsense]
a = 1
Terminal window
codeknife --no-cache --format agent arch
CODEKNIFE arch status=pass files=1 errors=0 warnings=0 infos=0 elapsed_ms=2
Terminal window
echo $?
0

Invalid TOML, a value of the wrong type, a negative integer, or an unknown strictness value stops the command. CodeKnife prints the error to stderr and exits with code 2:

[thresholds]
max_fn_lines = "forty"
codeknife error: parsing codeknife.toml: TOML parse error at line 2, column 16
|
2 | max_fn_lines = "forty"
| ^^^^^^^
invalid type: string "forty", expected usize
codeknife error: parsing codeknife.toml: TOML parse error at line 1, column 14
|
1 | strictness = "STRICT"
| ^^^^^^^^
unknown variant `STRICT`, expected `default` or `strict`

An invalid glob in exclude also exits with code 2:

codeknife error: error parsing glob 'src/[bad': unclosed character class; missing ']'
Situation Result Exit code
No codeknife.toml Defaults are used normal
Unknown key or section Ignored normal
Invalid TOML or wrong value type codeknife error: parsing codeknife.toml: ... 2
Invalid exclude glob codeknife error: error parsing glob ... 2

In the guard, a codeknife.toml at the base ref that does not parse is skipped without an error, so no loosenings are reported against it.

  • codeknife init writes the starter file. See Init, Skill & Usage Spec.
  • The MCP tools load the same file from their path argument. codeknife_check accepts a strict argument. See MCP Tools.
  • The anti-tamper hooks block agent edits to codeknife.toml. See Anti-Tamper Hooks.