Paths, Excludes & Changed Scope
Every analysis command starts by walking the repository root and building one code model from the source files it finds. This page explains which files get in, and how --changed and --since narrow the findings to the files you touched.
Quick start
Section titled “Quick start”Analyze a different directory:
codeknife --path ../other-repo --format agent checkReport only on files you changed since the last commit:
codeknife --changed --format agent checkReport on files changed since a branch point, plus uncommitted work:
codeknife --changed --since main --format agent checkGlobal flags
Section titled “Global flags”These flags are global, so you can put them before or after the subcommand.
| Flag | Default | Effect |
|---|---|---|
--path <dir> |
. |
The analysis root. CodeKnife canonicalizes it, loads codeknife.toml and arch.toml from it, walks it for source files, and writes .codeknife/ inside it. |
--changed |
off | Limits findings to files in the git change set. See Changed scope. |
--since <ref> |
none | A base git ref. With --changed, adds files that differ between this ref and HEAD. Also sets the base for the loosening guard and Diff-CRAP. |
How files are discovered
Section titled “How files are discovered”The walker visits every file under the root and keeps a file only if it passes all of these steps, in order:
- Directory names. Any directory with one of these names is skipped at any depth, whatever your config says:
target,node_modules,.git,.codeknife,vendor,dist,build,.venv,venv,__pycache__,.next. - Hidden files. Files and directories whose name starts with
.are skipped. - Ignore files. The walker enables
.gitignore,.git/info/excludeand your global git excludes file..gitignoreonly takes effect when the root is inside a git repository..ignorefiles take effect with or without git. excludeglobs. The path relative to the root (with/separators) is matched against theexcludepatterns from codeknife.toml.- Declaration and minified files. Paths ending in
.d.ts,.d.mts,.d.ctsor.min.jsare always skipped. - Language. The file extension must map to a supported language (table below). Other files are skipped.
- Generated code. When the file is read for parsing, it is dropped if any of its first 8 lines contains (case-insensitively)
code generated,@generated,do not edit,automatically generatedorauto-generated.
Files that fail to parse are dropped from the model without an error.
Extension to language
Section titled “Extension to language”| Extensions | Language |
|---|---|
.rs |
Rust |
.ts, .tsx, .mts, .cts |
TypeScript |
.js, .jsx, .mjs, .cjs |
JavaScript |
.py |
Python |
.go |
Go |
Matching is case-insensitive. The same lookup also accepts the language names as extensions (.rust, .typescript, .javascript, .python, .golang), so a file named h.golang is parsed as Go. What each language supports is on Language Support.
Example
Section titled “Example”This demo directory has one file for each case, and no git repository:
.gitignorelistssrc/ignored_by_gitignore.rs, and.ignorelistssrc/ignored_by_ignorefile.rs.- Hidden:
.hidden/h.rs,src/.dotfile.rs. - Skipped directory names:
app/build/b.rs,lib/node_modules/pkg/index.js,pkg/vendor/v.rs. - Default
exclude, declaration and minified files:web/api.generated.ts,web/types.d.ts,web/app.min.js. - Generated marker:
gen/proto.ts, whose first line is// Code generated by protoc. DO NOT EDIT. - No language:
notes.txt. - Plain sources:
out/o.rs,src/a.rs,src/f.py,src/g.go,src/h.golang, and oneweb/file for each TypeScript and JavaScript extension.
The files CodeKnife analyzed, read from .codeknife/metrics.json:
codeknife --format json check > /dev/nullpython3 -c 'import json; d=json.load(open(".codeknife/metrics.json")); [print(f["language"].ljust(11), f["path"]) for f in d["files"]]'rust out/o.rsrust src/a.rspython src/f.pygo src/g.gogo src/h.golangrust src/ignored_by_gitignore.rstypescript web/c.ctsjavascript web/cj.cjsjavascript web/j.jsjavascript web/jx.jsxtypescript web/m.mtsjavascript web/mj.mjstypescript web/t.tstypescript web/x.tsxsrc/ignored_by_gitignore.rs is analyzed because the directory is not a git repository. After git init, it is skipped.
exclude patterns
Section titled “exclude patterns”- Setting
excludereplaces the nine default patterns. Withexclude = ["out/**"]in the demo above,out/o.rsis dropped butweb/api.generated.tscomes back, because**/*.generated.*is no longer in the list. - In these globs
*also matches/.exclude = ["*.rs"]drops every Rust file at any depth, not only files in the root. - Patterns are relative to the root. A leading
./does not match:exclude = ["./out/**"]leavesout/o.rsin the scan. - An invalid pattern stops the run with exit code 2, for example
codeknife error: error parsing glob 'src/[bad': unclosed character class; missing ']'. - Adding a pattern is reported by the Loosening Guard.
Changed scope
Section titled “Changed scope”--changed asks git which files changed, then tells each blade to report only on those files. All files are still parsed, so cross-file analysis such as call graphs and dead-code reachability sees the whole repository.
What counts as changed
Section titled “What counts as changed”CodeKnife opens the git repository that contains the root (searching upward) and collects:
- Every path that
git statuswould show, including untracked files. Staged and unstaged edits both count. - With
--since <ref>, every path that differs between the tree at<ref>and the tree atHEAD.
Deleted files are dropped from the set. Non-source files (for example Cargo.lock or README.md) stay in the set, so they count in the PR risk brief, but no blade reports on them.
For each changed file, CodeKnife also computes the added or modified line ranges against a base: the --since ref when given, otherwise the first of HEAD, main, master, origin/main that exists. These line ranges are only used for diff_crap_max in the PR risk brief. Blades scope by whole file.
Walkthrough
Section titled “Walkthrough”A repository with three committed files, each with a 6-parameter function:
codeknife --no-cache --changed --format agent archCODEKNIFE arch status=pass files=4 errors=0 warnings=0 infos=0 elapsed_ms=3Add a function to src/a.rs without staging it:
CODEKNIFE arch status=fail files=4 errors=0 warnings=2 infos=0 elapsed_ms=8[1] WARNING CK_ARCH_TOO_MANY_PARAMS src/a.rs:1-1 sym=chg::a::a impact=45 | `a` takes 6 parameters (limit 5) | fix: Group cohesive parameters into an options or domain context struct.[2] WARNING CK_ARCH_TOO_MANY_PARAMS src/a.rs:3-3 sym=chg::a::a2 impact=45 | `a2` takes 6 parameters (limit 5) | fix: Group cohesive parameters into an options or domain context struct.Both findings in src/a.rs are reported, including the old function on line 1, because scoping is by file. After git commit, --changed alone reports nothing again. Adding --since brings the committed change back:
codeknife --no-cache --changed --since base --format agent archCODEKNIFE arch status=fail files=4 errors=0 warnings=2 infos=0 elapsed_ms=10[1] WARNING CK_ARCH_TOO_MANY_PARAMS src/a.rs:1-1 sym=chg::a::a impact=45 | `a` takes 6 parameters (limit 5) | fix: Group cohesive parameters into an options or domain context struct.[2] WARNING CK_ARCH_TOO_MANY_PARAMS src/a.rs:3-3 sym=chg::a::a2 impact=45 | `a2` takes 6 parameters (limit 5) | fix: Group cohesive parameters into an options or domain context struct.A new untracked file is in scope without git add:
CODEKNIFE arch status=fail files=5 errors=0 warnings=1 infos=0 elapsed_ms=6[1] WARNING CK_ARCH_TOO_MANY_PARAMS src/d.rs:1-1 sym=chg::d::d impact=45 | `d` takes 6 parameters (limit 5) | fix: Group cohesive parameters into an options or domain context struct.--since without --changed
Section titled “--since without --changed”--since on its own does not scope findings. codeknife --since base arch reports on every file. It still sets the base ref for the loosening guard and for the commands that fall back to the git change set (below).
Commands that use the change set without --changed
Section titled “Commands that use the change set without --changed”codeknife test, codeknife verify (its test step) and the smart-test commands inside dossier use the git change set even when you do not pass --changed. If git reports no changes, test and verify target every file. See Smart Test Selection.
Edge cases
Section titled “Edge cases”| Situation | Behaviour |
|---|---|
Clean working tree, no --since |
Empty change set. Every blade reports nothing and the run passes. |
| Root is not inside a git repository | Empty change set, no error. The run passes with no findings. check still adds a PR brief with changed_files: 0. |
--since names a ref that does not exist |
No error. The ref diff is skipped, so only working-tree changes are in scope, and every changed file is treated as fully new for Diff-CRAP. |
| Untracked files | Included. Files git ignores are not. |
.codeknife/ not in .gitignore |
CodeKnife’s own cache files appear as untracked files. They count toward changed_files, directories_touched and hotspots in the PR brief. |
| Root is a subdirectory of the git repository | See the caution below. |
Add .codeknife/ to your .gitignore. Here is the pr_brief of a second check --changed run, with only src/d.rs edited, before and after adding it:
codeknife --changed --format json check | python3 -c 'import sys,json; print(json.load(sys.stdin)["pr_brief"])'{'changed_files': 3, 'directories_touched': 2, 'diff_crap_max': None, 'new_suppressions': 0, 'new_dependencies': 0, 'review_risk': 'medium', 'hotspots': ['src/d.rs', '.codeknife/metrics.json', '.codeknife/parse-cache.json']}{'changed_files': 1, 'directories_touched': 1, 'diff_crap_max': None, 'new_suppressions': 0, 'new_dependencies': 0, 'review_risk': 'medium', 'hotspots': ['src/d.rs']}Exit codes
Section titled “Exit codes”Scoping itself never fails a run. An invalid exclude glob or an unreadable codeknife.toml exits with code 2. Everything else on this page falls back silently as described above. For the full exit code table see Output Formats & Exit Codes.
Also available via
Section titled “Also available via”The MCP tools codeknife_check, codeknife_dossier, codeknife_blast, codeknife_test and codeknife_verify take path, changed and since arguments with the same meaning. See MCP Tools.