Quickstart
This page walks you through a full CodeKnife session on a tiny repository with Rust, Python and TypeScript files and a few deliberate problems. It takes about ten minutes. Every command below was run in the order shown, and every output block is the real output.
You need codeknife on your PATH (see Installation) and git. CodeKnife does not need Cargo, Python or Node to analyze these files.
-
Create the demo repository.
Terminal window mkdir ledger && cd ledgermkdir src app webcat > Cargo.toml <<'EOF'[package]name = "ledger"version = "0.1.0"edition = "2021"EOFcat > src/main.rs <<'EOF'fn parse_amount(raw: &str) -> i64 {let value: i64 = raw.trim().parse().unwrap();dbg!(value);value}fn old_total(values: &[i64]) -> i64 {values.iter().sum()}fn main() {let mut total = 0;for raw in ["10", "32"] {// add the amount to the totaltotal += parse_amount(raw);}println!("{total}");}EOFcat > app/report.py <<'EOF'import requestsDATABASE_URL = "postgres://admin:hunter2@db.internal:5432/ledger"def fetch_report(url):response = requests.get(url)return response.json()EOFecho 'requests==2.32.3' > requirements.txtcat > web/client.ts <<'EOF'export async function loadUser(id: string) {const res = await fetch(`/api/users/${id}`);const body = (await res.json()) as any;return body.name as string;}EOFprintf '# Ledger\n\nSee [setup notes](docs/setup.md) before running.\n' > README.mdgit init -b main && git add -A && git commit -m "initial ledger demo"The problems planted here: a hard-coded database password, an
unwrap(), a leftoverdbg!, an unused private function, a comment that narrates the next line, HTTP calls without a timeout, anas anycast, and a README link to a file that does not exist. -
Create the starter files with
codeknife init.Terminal window codeknife initwrote /path/to/ledger/codeknife.tomlwrote /path/to/ledger/codeknife.baselinewrote /path/to/ledger/arch.tomlinitwrites three files and exits with code 0:codeknife.tomlholds every config key with its default value. See codeknife.toml.codeknife.baselinestarts with only a header comment. See Ratchet Baseline.arch.tomlcontains a commented-out[[deny]]example for layer rules. See 2. Architecture.
Commit them. The Loosening Guard compares these files against Git, so they need to be in a commit before you start changing them.
Terminal window git add -A && git commit -m "add codeknife starter files" -
Run the gate with
codeknife check.Terminal window codeknife check --format humanerror[CK_SEC_HARDCODED_SECRET]: potential hardcoded secret (database connection URL with embedded credentials) in source code--> app/report.py:3= fix: Move credentials to environment variables or an Age/secret manager vault.warning[CK_DEAD_FILE]: orphan file `app/report.py` has no inbound imports or reachable symbols--> app/report.py:1-8 (app/report.py)= fix: Delete this unreferenced file or wire its module into an entrypoint.warning[CK_SLOP_NO_TIMEOUT]: outbound HTTP request made without an explicit timeout--> app/report.py:7= fix: Use a client configured with explicit connect/request timeouts or `AbortSignal.timeout(...)`.warning[CK_DEAD_FILE]: orphan file `web/client.ts` has no inbound imports or reachable symbols--> web/client.ts:1-5 (web/client.ts)= fix: Delete this unreferenced file or wire its module into an entrypoint.warning[CK_SLOP_NO_TIMEOUT]: outbound HTTP request made without an explicit timeout--> web/client.ts:2= fix: Use a client configured with explicit connect/request timeouts or `AbortSignal.timeout(...)`.warning[CK_SLOP_TYPE_ESCAPE]: panic-prone `unwrap` in production code--> src/main.rs:2= fix: Propagate `Result`/`Option` cleanly with `?` or `.ok_or(...)` instead of panicking.warning[CK_DEAD_SYMBOL]: unreachable internal symbol `old_total`--> src/main.rs:7-9 (ledger::old_total)= fix: Delete this unused function (or run `codeknife dead --fix --write`).warning[CK_SLOP_TYPE_ESCAPE]: TypeScript type-safety escape (`(await res.json()) as any`)--> web/client.ts:3= fix: Parse/validate external data at the boundary instead of casting through `any` or `unknown`.warning[CK_DOC_DEAD_PATH]: broken markdown link target `docs/setup.md`--> README.md:3 (docs/setup.md)= fix: Update or remove the broken path reference in documentation.warning[CK_SLOP_DEBUG_LEFTOVER]: leftover debug macro/breakpoint in production code--> src/main.rs:3= fix: Remove debugging calls before committing.info[CK_CMT_NARRATION]: strippable comment: narration restating adjacent code--> src/main.rs:14 (main)= 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.info | npx vitest run --coverage | pytest --cov --cov-report=xml:coverage.xmlnote: analyzed 2 commit(s) over the last 90 day(s)codeknife check: FAIL (3 files, 1 errors, 9 warnings, 1 info, 13ms)The exit code is 1.
-
Read the output.
Each finding has the same shape:
- The first line is
severity[RULE_ID]: message. Severity iserror,warningorinfo. The rule ID tells you which check fired. Every ID is listed in the Rule Catalogue. - The
-->line is the file and line range. The name in parentheses, when present, is the symbol the finding is attached to. - The
= fix:line is a hint for the change that resolves the finding.
Findings are sorted by severity, then by impact score, then by file and line.
note:lines report what the run did or skipped. The last line is the verdict, the number of files scanned, the counts per severity and the elapsed time.checkfails (exit code 1) if any error or warning is left after the baseline is applied, or if the loosening guard reports anything. Info findings alone do not fail it. See The Check Gate.checkalso writes a cache to.codeknife/(heremetrics.jsonandparse-cache.json). Pass the global--no-cacheflag to keep the run read-only. See The .codeknife Directory. - The first line is
-
Run single blades.
Each blade is also its own subcommand. It runs only that blade and uses the same output and exit rules as
check, without the loosening guard.Terminal window codeknife sec --format humanerror[CK_SEC_HARDCODED_SECRET]: potential hardcoded secret (database connection URL with embedded credentials) in source code--> app/report.py:3= fix: Move credentials to environment variables or an Age/secret manager vault.codeknife sec: FAIL (3 files, 1 errors, 0 warnings, 0 info, 3ms)The
agentformat puts one finding on each line, which is easier to grep and cheaper for an AI agent to read:Terminal window codeknife slop --format agentCODEKNIFE slop status=fail files=3 errors=0 warnings=5 infos=0 elapsed_ms=2[1] WARNING CK_SLOP_NO_TIMEOUT app/report.py:7-7 sym=- impact=60 | outbound HTTP request made without an explicit timeout | fix: Use a client configured with explicit connect/request timeouts or `AbortSignal.timeout(...)`.[2] WARNING CK_SLOP_NO_TIMEOUT web/client.ts:2-2 sym=- impact=60 | outbound HTTP request made without an explicit timeout | fix: Use a client configured with explicit connect/request timeouts or `AbortSignal.timeout(...)`.[3] WARNING CK_SLOP_TYPE_ESCAPE src/main.rs:2-2 sym=- impact=55 | panic-prone `unwrap` in production code | fix: Propagate `Result`/`Option` cleanly with `?` or `.ok_or(...)` instead of panicking.[4] WARNING CK_SLOP_TYPE_ESCAPE web/client.ts:3-3 sym=- impact=55 | TypeScript type-safety escape (`(await res.json()) as any`) | fix: Parse/validate external data at the boundary instead of casting through `any` or `unknown`.[5] WARNING CK_SLOP_DEBUG_LEFTOVER src/main.rs:3-3 sym=- impact=45 | leftover debug macro/breakpoint in production code | fix: Remove debugging calls before committing.Some blades can repair what they find.
dead --fixpreviews the removal of strictly private dead functions:Terminal window codeknife dead --fix --format humanwarning[CK_DEAD_SYMBOL]: unreachable internal symbol `old_total`--> src/main.rs:7-9 (ledger::old_total)= fix: Delete this unused function (or run `codeknife dead --fix --write`).warning[CK_DEAD_FILE]: orphan file `app/report.py` has no inbound imports or reachable symbols--> app/report.py:1-8 (app/report.py)= fix: Delete this unreferenced file or wire its module into an entrypoint.warning[CK_DEAD_FILE]: orphan file `web/client.ts` has no inbound imports or reachable symbols--> web/client.ts:1-5 (web/client.ts)= fix: Delete this unreferenced file or wire its module into an entrypoint.note: dry-run: 1 strictly private dead symbol(s) can be removed with `--fix --write`codeknife dead: FAIL (3 files, 0 errors, 3 warnings, 0 info, 2ms)All 13 blades are described under Blades, starting with 1. Comments.
-
See the health score and the work queue.
Terminal window codeknife score --format humanCodeKnife Health Scorecard: 88.3/100 (Grade B+) | trend ▇ (n/a)Files: 3 | Code lines: 25 | Errors: 1 | Warnings: 9 | Info: 1Architecture (25%) 100.0/100 [0 finding(s)]Security (25%) 78.2/100 [1 finding(s)]Reliability (15%) 73.0/100 [5 finding(s)]Dead & Deps (10%) 83.8/100 [3 finding(s)]Testing (15%) 100.0/100 [0 finding(s)]Docs & Churn (10%) 94.1/100 [2 finding(s)]scorealways exits with code 0. See Health Scorecard.planranks the error and warning findings into an ordered to-do list. Info findings are left out, and the default is the top 10 (--top).Terminal window codeknife plan --format agentCODEKNIFE plan status=pass files=3 errors=1 warnings=9 infos=0 elapsed_ms=8[1] ERROR CK_SEC_HARDCODED_SECRET app/report.py:3-3 sym=- impact=100 | potential hardcoded secret (database connection URL with embedded credentials) in source code | fix: Move credentials to environment variables or an Age/secret manager vault.[2] WARNING CK_DEAD_FILE app/report.py:1-8 sym=app/report.py impact=66 | orphan file `app/report.py` has no inbound imports or reachable symbols | fix: Delete this unreferenced file or wire its module into an entrypoint....[10] WARNING CK_DOC_DEAD_PATH README.md:3-3 sym=docs/setup.md impact=45 | broken markdown link target `docs/setup.md` | fix: Update or remove the broken path reference in documentation.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 2 commit(s) over the last 90 day(s)NOTE showing top 10 prioritized work order(s) ranked by impact x churn + CRAPThe
impactvalues differ fromcheckbecauseplanre-ranks findings.planalways exits with code 0, and its status is alwayspass. See Work Orders (plan). -
Preview the automatic fixes.
codeknife fixis a dry run unless you pass--write:Terminal window codeknife fix --format humancodeknife fix (dry-run): planned 3 patch(es) across 1 file(s), 0 reverted (1 pass(es))[FIX] CK_CMT_STRIP | Remove 1 strippable comment(s) in src/main.rs[FIX] CK_DEAD_SYMBOL | Remove unreachable private function in src/main.rs[FIX] CK_SLOP_DEBUG_LEFTOVER | Remove debug leftover at src/main.rs:3The timeout findings are not in this list because that fixer only runs with
--aggressive. With--aggressive, the same dry run plans 5 patches:Terminal window codeknife fix --aggressive --format humancodeknife fix (dry-run): planned 5 patch(es) across 3 file(s), 0 reverted (1 pass(es))[FIX] CK_CMT_STRIP | Remove 1 strippable comment(s) in src/main.rs[FIX] CK_DEAD_SYMBOL | Remove unreachable private function in src/main.rs[FIX] CK_SLOP_NO_TIMEOUT | Inject explicit HTTP timeout at app/report.py:7[FIX] CK_SLOP_DEBUG_LEFTOVER | Remove debug leftover at src/main.rs:3[FIX] CK_SLOP_NO_TIMEOUT | Inject explicit HTTP timeout at web/client.ts:2This walkthrough keeps to the default set.
-
Apply the fixes.
Terminal window codeknife fix --write --format humancodeknife fix (write): applied 3 patch(es) across 1 file(s), 0 reverted (1 pass(es))[FIX] CK_CMT_STRIP | Remove 1 strippable comment(s) in src/main.rs[FIX] CK_DEAD_SYMBOL | Remove unreachable private function in src/main.rs[FIX] CK_SLOP_DEBUG_LEFTOVER | Remove debug leftover at src/main.rs:3git diffshows the edits:diff --git a/src/main.rs b/src/main.rsindex 509a98c..2d8affd 100644--- a/src/main.rs+++ b/src/main.rs@@ -1,17 +1,11 @@fn parse_amount(raw: &str) -> i64 {let value: i64 = raw.trim().parse().unwrap();- dbg!(value);value}-fn old_total(values: &[i64]) -> i64 {- values.iter().sum()-}-fn main() {let mut total = 0;for raw in ["10", "32"] {- // add the amount to the totaltotal += parse_amount(raw);}println!("{total}");The patched program still builds and prints
42. See Autofix Engine for--verify,--aggressiveand--toolchains. -
Fix the secret by hand and check again.
No fixer handles secrets. Change
app/report.pyto read the URL from the environment:import osimport requestsDATABASE_URL = os.environ["DATABASE_URL"]def fetch_report(url):response = requests.get(url)return response.json()Terminal window codeknife check --format humanwarning[CK_DEAD_FILE]: orphan file `app/report.py` has no inbound imports or reachable symbols--> app/report.py:1-10 (app/report.py)= fix: Delete this unreferenced file or wire its module into an entrypoint....warning[CK_DOC_DEAD_PATH]: broken markdown link target `docs/setup.md`--> README.md:3 (docs/setup.md)= fix: Update or remove the broken path reference in documentation.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 2 commit(s) over the last 90 day(s)codeknife check: FAIL (3 files, 0 errors, 7 warnings, 0 info, 6ms)The error is gone. Seven warnings remain, and the exit code is still 1. Commit the work so far:
Terminal window git add app src && git commit -m "apply fixes, read DB URL from env" -
Accept the remaining findings into the baseline.
When you adopt CodeKnife on an existing codebase, you usually cannot fix everything at once.
baseline updaterecords the current findings so thatcheckonly fails on new ones:Terminal window codeknife baseline updateupdated /path/to/ledger/codeknife.baseline (7 entries)The baseline is a plain text file, one entry per line:
# codeknife baseline v1: shrink-only violation ratchet. Prune with `codeknife baseline prune`.CK_DEAD_FILE app/report.py app/report.py 1CK_DEAD_FILE web/client.ts web/client.ts 1CK_DOC_DEAD_PATH README.md docs/setup.md 1CK_SLOP_NO_TIMEOUT app/report.py h:42bc78d5e4d7 1CK_SLOP_NO_TIMEOUT web/client.ts h:42bc78d5e4d7 1CK_SLOP_TYPE_ESCAPE src/main.rs h:66fa81ab1ff6 1CK_SLOP_TYPE_ESCAPE web/client.ts h:9f744db6ae73 1 -
Run
checkagain, and see the guard at work.Terminal window codeknife check --format humanloosening warnings:! codeknife.baseline: added new entry `CK_DEAD_FILE app/report.py app/report.py` (1)! codeknife.baseline: added new entry `CK_DEAD_FILE web/client.ts web/client.ts` (1)! codeknife.baseline: added new entry `CK_DOC_DEAD_PATH README.md docs/setup.md` (1)! codeknife.baseline: added new entry `CK_SLOP_NO_TIMEOUT app/report.py h:42bc78d5e4d7` (1)! codeknife.baseline: added new entry `CK_SLOP_NO_TIMEOUT web/client.ts h:42bc78d5e4d7` (1)! codeknife.baseline: added new entry `CK_SLOP_TYPE_ESCAPE src/main.rs h:66fa81ab1ff6` (1)! codeknife.baseline: added new entry `CK_SLOP_TYPE_ESCAPE web/client.ts h:9f744db6ae73` (1)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 3 commit(s) over the last 90 day(s)note: 7 finding(s) suppressed by codeknife.baselinecodeknife check: FAIL (3 files, 0 errors, 0 warnings, 0 info, 7ms)All seven findings are now suppressed, but
checkstill fails. The loosening guard compares the baseline in your working tree with the one inHEAD(or in the ref you pass with--since) and reports every new entry. Growing the baseline is a deliberate act, so it has to go into a commit:Terminal window git add codeknife.baseline && git commit -m "accept remaining findings into baseline"codeknife check --format humannote: 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 4 commit(s) over the last 90 day(s)note: 7 finding(s) suppressed by codeknife.baselinecodeknife check: PASS (3 files, 0 errors, 0 warnings, 0 info, 5ms)The exit code is 0. From now on, any new finding fails the gate, while the seven recorded ones do not.
-
Score the repository again.
Terminal window codeknife score --format humanCodeKnife Health Scorecard: 100.0/100 (Grade A+) | trend █ (n/a)Files: 3 | Code lines: 22 | Errors: 0 | Warnings: 0 | Info: 0Architecture (25%) 100.0/100 [0 finding(s)]Security (25%) 100.0/100 [0 finding(s)]Reliability (15%) 100.0/100 [0 finding(s)]Dead & Deps (10%) 100.0/100 [0 finding(s)]Testing (15%) 100.0/100 [0 finding(s)]Docs & Churn (10%) 100.0/100 [0 finding(s)]scoreandplanboth skip findings recorded in the baseline, so the score is 100 andplanwould now list no work orders. The baselined findings still exist in the code and are listed incodeknife.baseline.
Where to go next
Section titled “Where to go next”- Core Concepts: blades, findings, severities and the gate.
- The Check Gate: every
checkflag, including--changed,--deepand--tier full. - Ratchet Baseline: how entries are matched,
baseline pruneand the Git merge driver. - Loosening Guard: what counts as loosening, and inline suppression rules.
- codeknife.toml: every config key that
initwrote. - Rule Catalogue: every rule ID CodeKnife can emit.
- Init, Skill & Usage Spec and MCP Server: set CodeKnife up for an AI coding agent.