Skip to content

Loosening Guard

The loosening guard is the part of codeknife check that catches attempts to make the gate pass by weakening it instead of fixing code. It compares your configuration, arch.toml, codeknife.baseline and inline suppression comments with an earlier git ref, and it validates every suppression comment against the [suppressions] rules. It always runs; there is no toggle.

The guard produces two kinds of output:

  • Loosenings: text lines. Any loosening fails the gate. They cannot be baselined.
  • Findings: CK_GUARD_* findings, all with severity error. They fail the gate like any other error, and the baseline can absorb them.

The demo repository commits this codeknife.toml and arch.toml:

strictness = "strict"
exclude = ["target/**"]
[thresholds]
max_fn_lines = 60
max_crap = 15.0
[blades]
docs = true
[suppressions]
max_days = 90
always_block = ["@ts-ignore", "@ts-nocheck", "#[allow(clippy::all)]", "#[allow(warnings)]"]
require_reason_and_expiry = true
private_internals = ["src/internal/**"]
[[deny]]
from = "src/domain/**"
to = "src/infra/**"
[[allow_only]]
from = "src/app/**"
allow = ["src/domain/**"]

Then, without committing, both files are weakened:

exclude = ["target/**", "legacy/**"]
[thresholds]
max_fn_lines = 80
max_crap = 20.0
[blades]
docs = false
[suppressions]
max_days = 365
always_block = ["@ts-nocheck", "#[allow(clippy::all)]", "#[allow(warnings)]"]
require_reason_and_expiry = false
[[allow_only]]
from = "src/app/**"
allow = ["src/domain/**", "src/infra/**"]
Terminal window
codeknife --no-cache --format human check
echo $?
info[CK_CMT_SUPPRESSION]: MUST-RESHAPE: `noqa` lint/type suppression
--> src/util.py:1
= fix: Fix the underlying type or lint warning instead of suppressing it.
loosening warnings:
! codeknife.toml: `max_fn_lines` raised from 60 to 80
! codeknife.toml: `max_crap` raised from 15.00 to 20.00
! codeknife.toml: downgraded `strictness` from strict to default
! codeknife.toml: disabled blade `blades.docs`
! codeknife.toml: added exclude pattern `legacy/**`
! codeknife.toml: removed `@ts-ignore` from suppressions.always_block
! codeknife.toml: `suppressions.max_days` raised from 90 to 365
! codeknife.toml: disabled `suppressions.require_reason_and_expiry`
! arch.toml: removed `[[deny]]` rule `src/domain/** -> src/infra/**`
! arch.toml: expanded `allow_only` for `src/app/**` with `src/infra/**`
! arch.toml: removed `private_internals` glob `src/internal/**`
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
codeknife check: FAIL (1 files, 0 errors, 0 warnings, 1 info, 9ms)
1

There are no error or warning findings, but the loosenings alone fail the gate. In Agent format they appear as a LOOSENINGS count=N block after the header, capped at 15 lines. In JSON they are the loosenings array.

The guard finds the git repository that contains --path, then picks a base ref:

  • With --since REF: REF, if git can resolve it.
  • Without --since: the first of HEAD, main, master, origin/main that resolves.

Old file contents are read from that ref. When --path is a subdirectory of the repository, the files are read from the same subdirectory at the ref.

--since changes the guard’s base ref even without --changed. With the default (HEAD), only uncommitted changes are compared, so a loosening stops being reported once it is committed. In CI, pass the branch you merge into, for example --since origin/main, so that every loosening on the branch is reported.

When there is no git repository, or no base ref resolves, the guard compares nothing. It still scans every suppression comment, but treats none of them as new, so only two rules can fire: CK_GUARD_ALWAYS_BLOCK_SUPPRESSION and CK_GUARD_SUPPRESSION_EXPIRED.

Terminal window
codeknife --no-cache --format agent check
CODEKNIFE check status=fail files=2 errors=2 warnings=4 infos=1 elapsed_ms=3
[1] ERROR CK_GUARD_ALWAYS_BLOCK_SUPPRESSION web.ts:2-2 sym=- impact=85 | forbidden suppression `@ts-ignore` (configured in always_block) | fix: Remove the suppression and fix the underlying type, safety, or lint defect directly.
[2] ERROR CK_GUARD_SUPPRESSION_EXPIRED app.py:6-6 sym=- impact=75 | inline suppression `type: ignore` expired on 2026-01-15 | fix: Resolve the underlying issue and remove this expired suppression.
...

The same directory also has a new # noqa with no expiry; it is not reported here.

The old file is read from the base ref and compared with the configuration in effect for this run. If the old file is missing at the ref, or does not parse, the codeknife.toml checks are skipped.

Change Loosening line
An integer threshold went up codeknife.toml: `NAME` raised from OLD to NEW
A float threshold went up codeknife.toml: `NAME` raised from OLD to NEW (two decimals)
strictness went from strict to default codeknife.toml: downgraded `strictness` from strict to default
A [blades] toggle went from true to false codeknife.toml: disabled blade `blades.NAME`
A pattern in exclude is new codeknife.toml: added exclude pattern `PATTERN`
The file was deleted codeknife.toml: deleted
An entry was removed from suppressions.always_block codeknife.toml: removed `ENTRY` from suppressions.always_block
suppressions.max_days went up codeknife.toml: `suppressions.max_days` raised from OLD to NEW
suppressions.require_reason_and_expiry went from true to false codeknife.toml: disabled `suppressions.require_reason_and_expiry`

Thresholds compared (any increase is a loosening):

  • Integers: max_file_lines, warn_file_lines, max_fn_lines, max_cognitive_complexity, max_nesting, max_params, max_bool_params, held_in_mind, max_dir_members, clone_min_lines, clone_min_nodes, temporal_coupling_min_commits, thrash_min_edits.
  • Floats: max_crap, clone_similarity, dto_field_overlap, temporal_coupling_ratio.

Blade toggles compared: comments, arch, clones, dead, slop, sec, tests, churn, deps, docs.

Not compared: lowering any value, removing an exclude pattern, and every key under [coverage], [mutate], [comments] and [churn].

When codeknife.toml is deleted, the current configuration is the built-in default. Its default exclude list is then compared with the old list, so each default pattern that was not in your old exclude is also reported:

LOOSENINGS count=11
- codeknife.toml: downgraded `strictness` from strict to default
- codeknife.toml: added exclude pattern `node_modules/**`
- codeknife.toml: added exclude pattern `vendor/**`
- codeknife.toml: added exclude pattern `dist/**`
- codeknife.toml: added exclude pattern `build/**`
- codeknife.toml: added exclude pattern `.venv/**`
- codeknife.toml: added exclude pattern `__pycache__/**`
- codeknife.toml: added exclude pattern `**/*.min.js`
- codeknife.toml: added exclude pattern `**/*.generated.*`
- codeknife.toml: deleted
- arch.toml: layer specification deleted

The current configuration is compared after --strict caps are applied; the old file is compared as written. Running the weakened example above with --strict reports 8 loosenings instead of 11. The max_fn_lines and max_crap raises are capped back below the old values (40 and 10.0), and the strictness downgrade is not seen because --strict sets strict mode again.

Terminal window
codeknife --no-cache --format agent --strict check
CODEKNIFE check status=fail files=1 errors=0 warnings=0 infos=1 elapsed_ms=7
LOOSENINGS count=8
- codeknife.toml: disabled blade `blades.docs`
- codeknife.toml: added exclude pattern `legacy/**`
- codeknife.toml: removed `@ts-ignore` from suppressions.always_block
- codeknife.toml: `suppressions.max_days` raised from 90 to 365
- codeknife.toml: disabled `suppressions.require_reason_and_expiry`
- arch.toml: removed `[[deny]]` rule `src/domain/** -> src/infra/**`
- arch.toml: expanded `allow_only` for `src/app/**` with `src/infra/**`
- arch.toml: removed `private_internals` glob `src/internal/**`
...

Compared only when arch.toml exists at the base ref.

Change Loosening line
The file was deleted arch.toml: layer specification deleted
A [[deny]] rule (matched by from and to) is gone arch.toml: removed `[[deny]]` rule `FROM -> TO`
An [[allow_only]] block (matched by from) is gone arch.toml: removed `[[allow_only]]` for `FROM`
An [[allow_only]] block has a new allow entry arch.toml: expanded `allow_only` for `FROM` with `ENTRY`
A private_internals glob is gone arch.toml: removed `private_internals` glob `GLOB`

Changes to [[layers]] and to a deny rule’s reason are not compared. If the old arch.toml does not parse, the arch checks are skipped. A current arch.toml that does not parse stops check with exit code 2 before the guard runs. The arch.toml format is on Architecture.

A new key or a higher value compared with the base ref is a loosening (added new entry or grew). See Ratchet Baseline.

Every suppression comment that is new compared with the base ref is a loosening:

src/web.ts:2: added suppression `@ts-ignore`

“New” is decided per file and per marker. The guard counts the lines in the old version of the file that contain the marker text. In the current file, the suppressions with that marker are numbered in order; any beyond the old count are new. Moving a suppression within a file does not make it new. Adding one more of the same marker reports the last ones in the file, which may not be the line you added.

This applies to every new suppression, including ones with a valid reason and expiry. The Go line below passes every CK_GUARD_* rule and is still a loosening:

//nolint:errcheck // stdout close is best effort until: 2026-12-20
! src/main.go:6: added suppression `nolint`

Suppressions are found by the language parsers for every supported language (Rust, TypeScript, JavaScript, Python, Go). A line counts as a suppression when it is part of a comment and contains one of these markers. The marker list is the same for every language. The first match in this order wins:

Marker Typical use Kind
@ts-ignore TypeScript safety
@ts-nocheck TypeScript safety
@ts-expect-error TypeScript safety
eslint-disable (also matches eslint-disable-line and eslint-disable-next-line) JS / TS style
type: ignore Python (mypy) safety
pyright: ignore Python safety
noqa Python (flake8, ruff) style
pylint: disable Python style
nolint Go (golangci-lint) style

Rust attributes are found separately: any source line that starts with #[allow( or #![allow( (after leading spaces) is a suppression with the marker #[allow(...)]. It is a safety kind when the line contains warnings, clippy::all, dead_code or unused, otherwise style.

The kind is used by the Comments blade’s CK_CMT_SUPPRESSION finding (warning for safety, info for style). The guard rules below do not use it.

Reproduced on a committed, unchanged file:

#[allow(dead_code)] // kept for the FFI table until: 2026-12-20
fn unused_helper() -> u8 {
7
}
CODEKNIFE check status=fail files=1 errors=0 warnings=2 infos=0 elapsed_ms=4
LOOSENINGS count=1
- src/main.rs:1: added suppression `#[allow(...)]`
...

The guard reads an expiry date and a reason from the same source line as the marker:

  • Expiry: the first occurrence of until (any case) on the line, followed by any mix of :, = and spaces, then a date in YYYY-MM-DD form. until: 2026-12-15 and until=2026-12-15 both work. If the first until on the line is not followed by a valid date, the line has no expiry.
  • Reason: after removing the until clause, any Rust #[allow(...)] attribute, the directive words (eslint-disable-next-line, eslint-disable-line, eslint-disable, pyright: ignore, type: ignore, pylint: disable, @ts-expect-error, @ts-nocheck, @ts-ignore, nolint, noqa) and anything inside [...], the line must still contain a word of 3 or more letters, digits or underscores that is not a lint code. A lint code is 1 to 4 letters followed only by digits, like E501, F401 or TS2322.

Examples measured on new lines in a Python file:

Line Result
# noqa: E501 until: 2026-12-15 CK_GUARD_SUPPRESSION_NO_REASON (E501 is a lint code)
# type: ignore[attr-defined] until=2026-12-15 CK_GUARD_SUPPRESSION_NO_REASON (bracket content is removed)
# pylint: disable=invalid-name until: 2026-12-15 passes: invalid and name count as a reason
return x # noqa: E501 until: 2026-12-15 passes: return counts as a reason

All guard findings use blade guard, severity error, and are evaluated in this order for each suppression. The first rule that matches is reported; a line gets at most one guard finding.

Rule Severity Fires when Applies to Controlled by --strict
CK_GUARD_ALWAYS_BLOCK_SUPPRESSION error the source line contains any always_block entry every suppression suppressions.always_block no change
CK_GUARD_SUPPRESSION_EXPIRED error the until date is before today (local date) every suppression the until date no change
CK_GUARD_SUPPRESSION_HORIZON error the until date is more than max_days days after today new suppressions suppressions.max_days no change
CK_GUARD_SUPPRESSION_NO_REASON error there is an until date but no reason new suppressions, only if require_reason_and_expiry = true suppressions.require_reason_and_expiry no change
CK_GUARD_SUPPRESSION_NO_EXPIRY error there is no until date new suppressions, only if require_reason_and_expiry = true suppressions.require_reason_and_expiry no change

Impact scores: 85, 75, 60, 60 and 65 respectively. Every rule is listed with the others on the Rule Catalogue.

All five, reproduced in one run. The committed src/legacy.py has a type: ignore that expired on 2026-01-15 (today is 2026-11-30). Uncommitted: a new src/web.ts, a new src/main.go (the nolint line shown earlier), and two functions appended to the committed src/util.py:

export function parsePort(raw: string): number {
// @ts-ignore
return parseInt(raw, 10);
}
export function render(html: string): string {
// eslint-disable-next-line until: 2026-12-15
return html.trim();
}
def triple(x):
return x * 3 # noqa
def quadruple(x):
# pylint: disable=invalid-name -- legacy API name until: 2027-12-31
return x * 4
Terminal window
codeknife --no-cache --format human check
error[CK_GUARD_ALWAYS_BLOCK_SUPPRESSION]: forbidden suppression `@ts-ignore` (configured in always_block)
--> src/web.ts:2
= fix: Remove the suppression and fix the underlying type, safety, or lint defect directly.
error[CK_GUARD_SUPPRESSION_EXPIRED]: inline suppression `type: ignore` expired on 2026-01-15
--> src/legacy.py:5
= fix: Resolve the underlying issue and remove this expired suppression.
error[CK_GUARD_SUPPRESSION_NO_EXPIRY]: new suppression `noqa` lacks an `until: YYYY-MM-DD` expiry date
--> src/util.py:9
= fix: Fix the root cause instead, or annotate with `reason: ... until: YYYY-MM-DD`.
error[CK_GUARD_SUPPRESSION_HORIZON]: suppression `pylint: disable` expiry (396d) exceeds max_days (90)
--> src/util.py:13
= fix: Set `until: YYYY-MM-DD` within 90 days and include a short reason.
error[CK_GUARD_SUPPRESSION_NO_REASON]: new suppression `eslint-disable` lacks an explanatory reason before `until:`
--> src/web.ts:7
= fix: Document why the suppression is needed (e.g. `-- legacy FFI boundary until: YYYY-MM-DD`).
...
loosening warnings:
! src/main.go:6: added suppression `nolint`
! src/util.py:9: added suppression `noqa`
! src/util.py:13: added suppression `pylint: disable`
! src/web.ts:2: added suppression `@ts-ignore`
! src/web.ts:7: added suppression `eslint-disable`
note: no coverage file found (running complexity-only mode); generate one with: npx vitest run --coverage | pytest --cov --cov-report=xml:coverage.xml | go test -coverprofile=coverage.out ./...
note: analyzed 3 commit(s) over the last 90 day(s)
codeknife check: FAIL (4 files, 5 errors, 4 warnings, 5 info, 5ms)

The trimmed lines are CK_CMT_SUPPRESSION and CK_DEAD_FILE findings from other blades.

Key Type Default Used by
max_days integer 90 CK_GUARD_SUPPRESSION_HORIZON. Raising it is a loosening
always_block list of strings ["@ts-ignore", "@ts-nocheck", "#[allow(clippy::all)]", "#[allow(warnings)]"] CK_GUARD_ALWAYS_BLOCK_SUPPRESSION, substring match on the suppression’s source line. Removing an entry is a loosening
require_reason_and_expiry boolean true CK_GUARD_SUPPRESSION_NO_EXPIRY and CK_GUARD_SUPPRESSION_NO_REASON. Turning it off is a loosening

The rest of codeknife.toml is on codeknife.toml.

  • With --changed, only files in the changed set are scanned for suppressions. Config, arch.toml and baseline comparisons always run.
  • Files excluded by exclude are not parsed, so their suppressions are never seen.
  • The guard runs wherever the full static suite runs: check, baseline update, baseline prune, the codeknife_check MCP tool, and other commands built on the suite such as plan and map.

Loosenings and CK_GUARD_* findings both make check exit 1. The guard itself never makes check exit 2: a missing or unparsable old file is skipped. Errors reading the current codeknife.toml, arch.toml or codeknife.baseline still exit 2, as described on The Check Gate.

  • The codeknife_check MCP tool runs the guard and returns loosenings in its JSON. Its since argument sets the base ref. See MCP Tools.
  • The Anti-Tamper Hooks block agent edits to protected files before they happen. The guard catches what got through.
  • With --changed, the PR Risk Brief counts CK_GUARD_* findings as new_suppressions; see The Check Gate.