| name | codelens |
|---|---|
| description | CodeLens — AI-Native Code Intelligence. 12 commands for AI-powered code analysis, security auditing, quality scoring, AST-based taint analysis, live CVE scanning, and pre-write safety checks (each command is an umbrella over focused --check sub-modes). Tree-sitter parsing for 7 core languages (Rust, TypeScript, TSX, JavaScript, Python, HTML, CSS) plus 28+ languages via regex fallback. MCP server exposes 12 tools for AI agent integration. For quick command reference with validated output schemas, see SKILL-QUICK.md. For version history, see CHANGELOG.md. |
Before an AI writes a new class/id/function, CodeLens must be checked. This is not optional.
Quick command reference → SKILL-QUICK.md (validated output schemas, error behavior, trigger maps) Version history → CHANGELOG.md Verified per-language coverage & known gaps → docs/agent-usage-guide.md
CodeLens consolidated ~78 legacy commands into 12 umbrella commands (issue #195/#199/#200). If you have seen CodeLens before and remember query, init, smell, dead-code, secrets, trace, impact, circular, guard, or serve as top-level commands — those no longer exist as standalone commands. They are now --check <sub-mode> flags under one of the 12 umbrellas below:
codelens query "name" . → DROPPED (no direct replacement; use `search --mode symbol`)
codelens dead-code . → codelens audit . --check dead-code
codelens secrets . → codelens security . --check secrets
codelens trace "name" . → codelens context . --check trace --name "name"
codelens impact "name" . → codelens impact . --check impact --name "name"
codelens circular . → codelens deps . --check circular
codelens init . → DROPPED (scan auto-inits)
codelens serve → DROPPED (MCP tools invoked by an MCP-aware client, not this CLI)
codelens guard --pre --file X → DROPPED
| Command | --check sub-modes |
|---|---|
scan |
scan (default) · rescan |
search |
semantic (default) · symbol · regex · graph — pattern comes first, workspace second, opposite of every other command here |
context |
orient (default) · outline · trace · context · diagnostics (LSP lint, needs --file) · overview (token-efficient symbol map) · tags (@FLOW/@ENTRY doc-tag audit) · flow (collect a named @FLOW's scattered functions, --name X) · source (a function's source by name, --name X — skip reading the whole file) |
deps |
affected · dependents · circular (default: all three) · import-snapshot · export-snapshot |
audit |
dead-code · complexity · smell · staleness · perf-hint · side-effect · css (deep CSS) · a11y (WCAG 2.1) (default: all) |
security |
secrets · vuln-scan · taint · binary-scan · regex-audit (default: all) |
summary |
summary (default) · dashboard · arch-metrics · architecture |
impact |
impact (default) · diff · dataflow · flow-diff (named @FLOW shape change between two snapshots, --name X) |
api-map |
api-map (default) · graph-schema |
doctor |
doctor (default) · env-check · lsp-status |
history |
history (default) · ownership · git-status |
graph |
— (raw Cypher; casual callers use search --mode graph instead) |
Two additional commands are registered but hidden from --help (pending a maintainer decision on their final home, issue #200): check (CI/CD quality gate) and plugin (plugin management). Both work today — call them directly, e.g. codelens check . --severity high.
If no .codelens/ registry exists, running any analysis command automatically triggers scan first:
codelens search "myFunction" . --mode symbol --lite
# → If no .codelens/ exists: auto-scan → then search
# → Returns: {status:"ok", ...} — see the specific command's Lite Mode row below| Flag | Effect | When to use |
|---|---|---|
--top N |
Limit list results to top N items (sorts by relevance first) | Large repos, token budget concerns |
--max-tokens N |
Truncate output to fit ~N tokens | Strict context window limits |
--lite |
Minimal output: command-specific tailored response | Quick checks, decision-making — use this by default in an agent loop |
--format ai |
Normalized schema: {stats, items[], truncated, recommendations} |
Consistent parsing across commands |
--format compact |
Single-char keys, ~50% smaller than json |
High-volume MCP tool calls |
| Command | --lite returns |
|---|---|
search --mode symbol |
full symbol result (no dedicated reducer — small payload already) |
impact --check impact / impact --check diff |
{status, risk, action} |
audit --check smell |
{status, health_score, total_findings, action, top_findings[], stats} |
audit --check complexity |
{status, stats, top_complex[], high_complexity_count} |
audit --check dead-code |
{status, removal_safety, recommended_action, stats, top_items[], total_dead} |
security --check secrets |
{status, risk, action, stats, top_findings[]} |
security --check taint |
{status, risk, stats, top_findings[], recommendations} |
summary |
{status, workspace, identity, frameworks, recommendations, findings[]} — each finding's top_items capped to 3, nested flow_chain stripped |
history |
{status, workspace, snapshots, latest{health_score,...}, trends, deltas} |
| Other | generic fallback: {status, stats, top 5 items, recommendations} — adequate, not hand-tuned |
codelens search "handleAuth" . --mode symbol --liteIf not found → safe to write. If found + status: active → extend, don't overwrite. If found + status: dead → ask before reusing.
- Python 3.8+ installed
- Target codebase accessible on filesystem
pip install codelens(For a source checkout: bash setup.sh && pip install -e . — installs tree-sitter grammars. If tree-sitter is unavailable, CodeLens automatically falls back to regex-based parsing.)
codelens scan /path/to/projectNo separate init step — scan handles workspace detection and registry creation in one call.
Timing: <500 files: ~5-15s · 1,000-5,000 files: ~30-120s · 5,000+ files: use --max-files 3000 to prevent timeout.
Output: {status:"ok", files_scanned{...}, frontend{classes,ids}, backend{nodes,edges}}
codelens search "main" /path/to/project --mode symbolAny valid JSON response means setup is complete.
codelens scan /path/to/project --incrementalWithout this, queries return stale data.
| Issue | Cause | Fix |
|---|---|---|
WARNING: TSBackendParser init failed |
tree-sitter not installed | bash setup.sh, or ignore (regex fallback works) |
Auto-detected workspace: ... |
Invalid workspace arg | Check the returned workspace field matches your project |
| Search silently returns 0 results | Argument order backwards | search takes pattern first, workspace second — every other command is the reverse |
| Empty results after scan | No recognized source files | Check .codelens/codelens.config.json ignore list |
status: "error" on any command |
Registry not built | Run scan first |
| Scan takes too long | Very large repo | Use --max-files 3000 |
The workspace argument is optional for every command:
codelens scan # Auto-detect → works!
codelens search "myFunc" --mode symbol # Auto-detect → works!
codelens audit --check smell # Auto-detect → works!Resolution order: current directory (project markers: package.json, pyproject.toml, Cargo.toml, ...) → parent directories (up to 10 levels) → last used workspace cache → current working directory.
1. search "name" --mode symbol → not found = SAFE, active = EXTEND, dead = ASK
2. Write code
3. scan --incremental
security --check secrets → security --check taint → security --check vuln-scan
audit --check smell → audit --check complexity → audit --check dead-code → security --check secrets
scan --incremental → deps --check circular → audit --check dead-code → security --check secrets
search "pattern" . --mode regex → context . --check trace --name X --direction up
search "name" --mode symbol → context (if exists) → audit --check side-effect → write → scan --incremental
| Failure | Recovery |
|---|---|
scan file read error |
Skip unreadable files, scan the rest |
scan grammar import error |
Fallback to regex parser automatically |
search --mode symbol not found |
Returns found:false-equivalent (not an error) — run scan first if registry is missing |
| Registry corrupt | Delete .codelens/ → scan → retry |
context --check trace symbol not found |
Try search --mode symbol first to locate the exact name |
impact no edges |
Run scan first to build edges, then retry |
security --check vuln-scan no lockfile |
Returns empty results — not an error |
history --check ownership no git repo |
Fallback to mtime-based analysis |
| Any command timeout | Use --max-files to reduce scope |
Any status:"error" |
Follow the error/suggestion field in the response |
| Status | Meaning | AI Action |
|---|---|---|
active |
Used, ref_count > 0 | Normal, proceed |
dead |
Nothing references it in the graph | Cross-check with trace --direction up before flagging to user |
duplicate_ref |
Referenced from many places | List all callers |
collision |
Same id/name defined ambiguously | Stop, fix first |
duplicate_define |
Defined more than once | Warning |
Priority order: collision → duplicate_define → dead → duplicate_ref → active → not found
| Metric | What it actually means | How to interpret |
|---|---|---|
reference_count / caller count |
Popularity — how often a symbol is referenced | Not a criticality signal. A payment-flow function called once is more critical than a utility called 50×. |
status: dead |
Nothing references it in the graph | Flag for removal — but verify it's not an entry point (HTTP handler, CLI subcommand, exported API) first. |
status: duplicate_ref |
Referenced from many places | List all callers with context --check trace --direction up before changing. |
high_complexity |
Cyclomatic complexity ≥ threshold | Hotspot for bugs, not necessarily important. Cross-reference with trace --direction up. |
To judge importance: context --check trace --name X --direction up to see who calls it, then weigh by context (payment, auth, entry point) — not by raw count.
To reduce noise: --format compact for token-efficient output, --lite for decision-making mode, --detail minimal (where supported) for critical-severity findings only.
First scan is slow by design — it builds the SQLite graph. Subsequent scans are incremental (--incremental).
import subprocess, json
def cl_search(name, workspace, mode="symbol"):
r = subprocess.run(
["codelens", "search", name, workspace, "--mode", mode, "--lite"],
capture_output=True, text=True, timeout=30,
)
return json.loads(r.stdout)- Search before write — always check for an existing symbol before creating a new class/id/function
- Scan after write — run
scan --incrementalafter modifying code - Report dead code, don't silently ignore it
- Handle errors — gracefully handle subprocess timeouts and JSON parse errors
--top N— sorts by relevance first (severity, complexity, ...), then truncates--lite— command-specific minimal payload (see table above)--max-tokens N— hard cap, truncates the largest lists to fit--format ai— normalizes output to{stats, items[], truncated, recommendations}--format compact— single-char keys, smallest payload- Set
CODELENS_AI_MODE=1to make--format aithe default output format - Auto-setup caps scanning at 3000 files — run
scanmanually (no cap) for full analysis on large repos
export CODELENS_AI_MODE=1
codelens audit --check smell # now outputs in --format ai by defaultWithout this env var, the default format is json.
- docs/agent-usage-guide.md — verified per-language coverage,
--litereducer coverage, known gaps, with real before/after fix evidence references/agent-integration.md— CLI/Python API integration guidereferences/parser-rules.md— parsing rules per languagereferences/query-examples.md— query examples and output interpretationreferences/status-codes.md— details for all statuses and flags
- AST Taint Engine (
security --check taint) — tree-sitter AST traversal, path-sensitive, scope-aware, inter-procedural taint tracking with confidence scoring. Python/JS/TS/TSX only — no Rust source/sink rules yet. - Live CVE/OSV Scanning (
security --check vuln-scan) — real-time data from OSV.dev across 9 ecosystems (PyPI, npm, crates.io, Go, Maven, NuGet, RubyGems, Pub, Hex), SQLite cache + offline fallback. - Plugin System (
plugincommand) — 4 plugin types (rule_pack/engine/formatter/command), 3-tier discovery. Ships with OWASP Top 10 (36 rules) + Compliance (53 rules: PCI-DSS v4.0 + HIPAA). - Cross-File Dataflow Engine (
impact --check dataflow) — workspace-wide call graph with import resolution and bidirectional taint propagation. - CI/CD Quality Gate (
checkcommand) — exits non-zero on failure, SARIF output for GitHub Advanced Security / VS Code. - Gitleaks-Backed Secrets Scanner (
security --check secrets) — uses gitleaks as the primary backend when installed (600+ rules, entropy scoring), falls back to the built-in regex scanner otherwise.--no-gitleaksforces the regex backend. - Rust-aware dead-code detection —
#[cfg(test)] mod tests { #[test] fn ... }inline test functions are correctly exempted (fixed 2026-07-12; previously 56%+ of Rustregistry_deadfindings were test-function false positives).