Skip to content

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.

Analyze a different directory:

Terminal window
codeknife --path ../other-repo --format agent check

Report only on files you changed since the last commit:

Terminal window
codeknife --changed --format agent check

Report on files changed since a branch point, plus uncommitted work:

Terminal window
codeknife --changed --since main --format agent check

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.

The walker visits every file under the root and keeps a file only if it passes all of these steps, in order:

  1. 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.
  2. Hidden files. Files and directories whose name starts with . are skipped.
  3. Ignore files. The walker enables .gitignore, .git/info/exclude and your global git excludes file. .gitignore only takes effect when the root is inside a git repository. .ignore files take effect with or without git.
  4. exclude globs. The path relative to the root (with / separators) is matched against the exclude patterns from codeknife.toml.
  5. Declaration and minified files. Paths ending in .d.ts, .d.mts, .d.cts or .min.js are always skipped.
  6. Language. The file extension must map to a supported language (table below). Other files are skipped.
  7. 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 generated or auto-generated.

Files that fail to parse are dropped from the model without an error.

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.

This demo directory has one file for each case, and no git repository:

  • .gitignore lists src/ignored_by_gitignore.rs, and .ignore lists src/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 one web/ file for each TypeScript and JavaScript extension.

The files CodeKnife analyzed, read from .codeknife/metrics.json:

Terminal window
codeknife --format json check > /dev/null
python3 -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.rs
rust src/a.rs
python src/f.py
go src/g.go
go src/h.golang
rust src/ignored_by_gitignore.rs
typescript web/c.cts
javascript web/cj.cjs
javascript web/j.js
javascript web/jx.jsx
typescript web/m.mts
javascript web/mj.mjs
typescript web/t.ts
typescript web/x.tsx

src/ignored_by_gitignore.rs is analyzed because the directory is not a git repository. After git init, it is skipped.

  • Setting exclude replaces the nine default patterns. With exclude = ["out/**"] in the demo above, out/o.rs is dropped but web/api.generated.ts comes 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/**"] leaves out/o.rs in 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 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.

CodeKnife opens the git repository that contains the root (searching upward) and collects:

  1. Every path that git status would show, including untracked files. Staged and unstaged edits both count.
  2. With --since <ref>, every path that differs between the tree at <ref> and the tree at HEAD.

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.

A repository with three committed files, each with a 6-parameter function:

Terminal window
codeknife --no-cache --changed --format agent arch
CODEKNIFE arch status=pass files=4 errors=0 warnings=0 infos=0 elapsed_ms=3

Add 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:

Terminal window
codeknife --no-cache --changed --since base --format agent arch
CODEKNIFE 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 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.

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:

Terminal window
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']}

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.

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.