Init, Skill & Usage Spec
Three small commands help you set a repository up for CodeKnife and teach an agent how to use it. codeknife init writes starter config files. codeknife skill prints a skill document for coding agents. codeknife usage prints a machine-readable spec of every command and flag.
codeknife init
Section titled “codeknife init”Run it once in the repository root:
mkdir initdemo && cd initdemo && git init -qcodeknife initecho "exit=$?"wrote .../initdemo/codeknife.tomlwrote .../initdemo/codeknife.baselinewrote .../initdemo/arch.tomlexit=0The resulting tree, excluding .git/:
./arch.toml./codeknife.baseline./codeknife.tomlThe status lines go to stderr with absolute paths. Stdout stays empty.
Files it writes
Section titled “Files it writes”| File | Content |
|---|---|
codeknife.toml |
The default config serialized as TOML: strictness = "default", the default exclude list, and the [thresholds], [blades], [suppressions], [coverage], [mutate], [comments] and [churn] tables. See codeknife.toml for each key. |
codeknife.baseline |
An empty baseline: one header comment line, no entries. See Ratchet Baseline. |
arch.toml |
Commented-out sample. Nothing in it is active. |
The starter codeknife.toml begins like this:
strictness = "default"exclude = [ "target/**", "node_modules/**", "vendor/**", "dist/**", "build/**", ".venv/**", "__pycache__/**", "**/*.min.js", "**/*.generated.*",]
[thresholds]max_file_lines = 1000warn_file_lines = 500max_fn_lines = 60...The file is the serialized default config, so the global --strict flag does not change what init writes.
The full codeknife.baseline:
# codeknife baseline v1: shrink-only violation ratchet. Prune with `codeknife baseline prune`.The full arch.toml:
# Optional Clean Architecture / layer rules for `codeknife arch`# [[deny]]# from = "domain/**"# to = "infra/**"# reason = "Domain must not depend on infrastructure"What it does not do
Section titled “What it does not do”To add those yourself, see Anti-Tamper Hooks for the agent hook commands and MCP Server for the server command.
Existing files and –force
Section titled “Existing files and –force”| File | Exists, no --force |
Exists, --force |
|---|---|---|
codeknife.toml |
Kept. Prints exists <path> (pass --force to overwrite) |
Overwritten with the defaults |
codeknife.baseline |
Kept silently | Overwritten with an empty baseline |
arch.toml |
Kept silently | Kept silently |
A second run in the same directory:
exists .../initdemo/codeknife.toml (pass --force to overwrite)exit=0With --force, after replacing arch.toml with # custom:
wrote .../initdemo/codeknife.tomlwrote .../initdemo/codeknife.baselineexit=0arch.toml still contained # custom afterwards.
Outside a git repository
Section titled “Outside a git repository”init does not use git. In a plain directory it writes the same three files and exits 0. It writes into --path (default: the current directory). If that directory does not exist, it fails:
codeknife --path /nonexistent/dir initecho "exit=$?"codeknife error: writing /nonexistent/dir/codeknife.toml: No such file or directory (os error 2)exit=2| Flag | Default | Effect |
|---|---|---|
--force |
off | Overwrite codeknife.toml and codeknife.baseline if present |
--path <dir> (global) |
. |
Directory to write into |
codeknife skill
Section titled “codeknife skill”codeknife skill prints a bundled skill document to stdout and exits 0. The text is compiled into the binary; it does not depend on the repository or on any flag.
codeknife skill---name: codeknifedescription: "Deterministic polyglot code-quality gate, transactional autofixer, reuse oracle, focused dossier generator, and stdio MCP server (comments, architecture, clones, dead code, slop, security, tests/CRAP, mutation, churn, blast, deps, docs, map)."---
# CodeKnife — Deterministic Codebase Swiss Army Knife (AX Guide)
Run CodeKnife before writing code, during refactoring, and before declaring any task done. Let CodeKnife handle deterministic fixes cleanly so you only make architectural and semantic judgments.
## Recommended Agent Loop
1. **Before writing new helpers**: `codeknife reuse "<intent>" --format agent` to reuse existing utilities and avoid `CK_CLONE_*`.2. **Orient on unfamiliar modules**: `codeknife dossier --top 5 --budget 12000 --format agent` (or `codeknife dossier --target <symbol_or_file>`) for grouped Root-Cause Work Orders, blast radius, arch rules, and budgeted excerpts in one call.3. **Strip mechanical noise first**: `codeknife fix --write --verify` cleans narration comments, dead symbols/imports, debug leftovers, expired suppressions, and broken doc links with compiler-verified binary-search rollback.4. **Verify end-to-end**: `codeknife verify` runs `--strict`-compatible checks and blast-scoped smart tests (`codeknife test`) in one command, or pass `--deep` to `codeknife check` to fuse `cargo clippy`, `ruff`, `tsc`, and `go vet`.5. **Native MCP Server**: run `codeknife mcp` in stdio JSON-RPC 2.0 mode to invoke `codeknife_reuse`, `codeknife_dossier`, `codeknife_fix`, `codeknife_blast`, `codeknife_test`, `codeknife_check`, and `codeknife_verify`.
## Core Commands & Blades...
## Rules When Fixing CodeKnife Findings
1. Fix from first principles — never game metrics by splitting one function into single-caller helper chains or silencing linters without an approved `until: YYYY-MM-DD` expiry.2. When `CK_TEST_ZERO_ASSERT` or `CK_MUTATE_SURVIVOR` fires, assert observable behavior, not mocks or internal helpers.3. Always re-run `codeknife verify` (or `codeknife --strict --no-cache check`) after edits to confirm zero regressions.The output is 37 lines: YAML frontmatter with name and description, then three sections: a five-step agent loop, a list of commands, and rules for fixing findings.
Installing the skill
Section titled “Installing the skill”The command’s help names Claude Code, Cursor, Codex and Antigravity. CodeKnife has no install logic for any of them: it only prints the text. Redirect the output into the file your agent reads skills or rules from, for example:
codeknife skill > SKILL.mdWhere that file goes depends on the agent, and CodeKnife does not create the directory for you. Re-run the command after upgrading CodeKnife to pick up a new version of the text.
codeknife usage
Section titled “codeknife usage”codeknife usage prints a Usage specification (its help text points to usage.jdx.dev for the format), generated at runtime from the same clap definition that produces --help. It always matches the binary you run. It exits 0.
codeknife usage// @generated by usage-cli from clap metadataname codeknifebin codeknifeversion "0.2.0"about "CodeKnife — The Swiss Army Knife for deterministic code quality (DX + AX)"usage "Usage: codeknife [OPTIONS] <COMMAND>"flag --path help="Repository root path (defaults to current working directory)" global=#true default=. { arg <PATH>}flag --format help="Output format (auto switches between TTY Human and non-TTY Agent)" global=#true default=auto { arg <FORMAT> { choices auto human agent json sarif markdown }}...cmd hook subcommand_required=#true help="AI coding agent PreToolUse anti-tamper hook (`claude` or `cursor`)" { cmd claude help="Handle Claude Code PreToolUse JSON event on stdin" cmd cursor help="Handle Cursor PreToolUse JSON event on stdin"}cmd skill help="Print bundled `SKILL.md` for Claude Code, Cursor, Codex, and Antigravity"cmd usage help="Print the Usage specification (`usage.jdx.dev`) generated from clap metadata"...The spec lists every global flag (with global=#true), every command as a cmd block, each flag’s help, default and choices, and positional arguments as arg. The full output is 198 lines. The CLI Reference shows the same information as --help text.
Exit codes
Section titled “Exit codes”| Command | Code | When |
|---|---|---|
init |
0 |
Files written or skipped |
init |
2 |
A file could not be written (for example, --path does not exist) |
skill |
0 |
Always |
usage |
0 |
Always |