Background
CodeLens currently scans the full repo on every invocation. In CI environments (PR checks, pre-merge gates), this means re-analyzing hundreds of unchanged files on every commit — wasting time and producing noise from pre-existing findings that are irrelevant to the current change.
Strix (a dynamic pentest agent) solves this with a --scope-mode diff + --diff-base pattern that limits analysis to changed files only. The same approach applies cleanly to CodeLens's static model.
Goal
Add a --diff-base <ref> global flag (and optionally --diff-base HEAD~1 as a shortcut) that pre-filters the file list for any analysis command to only files changed relative to the given ref.
# Only scan files changed vs main
codelens check . --diff-base main
codelens taint . --diff-base main
codelens vuln-scan . --diff-base origin/HEAD
codelens scan . --diff-base HEAD~1
Implementation
This is a pre-filter layer, not new analysis logic:
- When
--diff-base <ref> is provided, run:
subprocess.run(['git', 'diff', '--name-only', ref, 'HEAD'], capture_output=True)
- Parse the output into a set of changed file paths
- Pass this set as an allowlist to the existing file discovery layer — unchanged files are skipped before any parsing/analysis begins
- If the diff is empty (no changed files), exit early with a clear message
The filter should live in a shared DiffScope utility class used by all commands, so it's a single implementation point rather than per-command.
Definition of Done
Source of Truth
- Existing file discovery logic:
scripts/codelens.py + individual command files in scripts/commands/
DiffScope utility: new module, scripts/utils/diff_scope.py (suggested location)
- Strix reference:
strix/core/scope.py in https://github.com/usestrix/strix (public repo — read for inspiration, do not copy)
CI use case
- name: CodeLens diff check
run: python scripts/codelens.py check . --diff-base origin/main --format sarif > codelens.sarif
This replaces a full-repo scan on every PR with a targeted scan of only what changed — the primary use case this flag enables.
Background
CodeLens currently scans the full repo on every invocation. In CI environments (PR checks, pre-merge gates), this means re-analyzing hundreds of unchanged files on every commit — wasting time and producing noise from pre-existing findings that are irrelevant to the current change.
Strix (a dynamic pentest agent) solves this with a
--scope-mode diff+--diff-basepattern that limits analysis to changed files only. The same approach applies cleanly to CodeLens's static model.Goal
Add a
--diff-base <ref>global flag (and optionally--diff-base HEAD~1as a shortcut) that pre-filters the file list for any analysis command to only files changed relative to the given ref.Implementation
This is a pre-filter layer, not new analysis logic:
--diff-base <ref>is provided, run:The filter should live in a shared
DiffScopeutility class used by all commands, so it's a single implementation point rather than per-command.Definition of Done
--diff-base <ref>flag accepted by all analysis commands (check,scan,taint,vuln-scan,dead-code,secrets,complexity,circular)git diff --name-onlyoutput used as file allowlist before file discoveryNo changed files relative to <ref>--diff-basedocumented in--helpoutput for each affected commandSKILL.mdupdated: CI usage example with--diff-basesync_command_count.py --applyrun (count unchanged — this is a flag, not a new command)Source of Truth
scripts/codelens.py+ individual command files inscripts/commands/DiffScopeutility: new module,scripts/utils/diff_scope.py(suggested location)strix/core/scope.pyin https://github.com/usestrix/strix (public repo — read for inspiration, do not copy)CI use case
This replaces a full-repo scan on every PR with a targeted scan of only what changed — the primary use case this flag enables.