Skip to content

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.

Run it once in the repository root:

Terminal window
mkdir initdemo && cd initdemo && git init -q
codeknife init
echo "exit=$?"
wrote .../initdemo/codeknife.toml
wrote .../initdemo/codeknife.baseline
wrote .../initdemo/arch.toml
exit=0

The resulting tree, excluding .git/:

./arch.toml
./codeknife.baseline
./codeknife.toml

The status lines go to stderr with absolute paths. Stdout stays empty.

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 = 1000
warn_file_lines = 500
max_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"

To add those yourself, see Anti-Tamper Hooks for the agent hook commands and MCP Server for the server command.

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=0

With --force, after replacing arch.toml with # custom:

wrote .../initdemo/codeknife.toml
wrote .../initdemo/codeknife.baseline
exit=0

arch.toml still contained # custom afterwards.

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:

Terminal window
codeknife --path /nonexistent/dir init
echo "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 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.

Terminal window
codeknife skill
---
name: codeknife
description: "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.

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:

Terminal window
codeknife skill > SKILL.md

Where 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 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.

Terminal window
codeknife usage
// @generated by usage-cli from clap metadata
name codeknife
bin codeknife
version "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.

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