# CodeLens [Health: Active]

**Category:** 💻 Developer Tools  
**Repository:** https://github.com/ex-git/codeLens  
**GitHub Stars:** 4  
**npm Downloads (last month):** 577  
**Views:** 1  
**Installs:** 0  
**Upvotes:** 0  
**Directory Page:** https://allmcps.com/mcp/fodx-codelens

## Description
Local, branch-aware code search & relation graph. SQLite FTS5 + tree-sitter symbols + source-graph edges, exposed as an MCP server and CLI. No chat LLM required.

## Tools
Capabilities this server exposes over MCP:

- **cl_current** — Report current repo/branch/index status with freshness fields. Use first to check if an index is ready. If status is indexing, wait/retry shortly instead of refreshing immediately.

RETURNS: {repo, branch, headSha, indexId, status, dirtyFiles, lastIndexedAt, indexingStartedAt?, indexingAgeMs?, inGitRepo}

EXAMPLE: cl_current
- **cl_refresh** — Create or update the current branch/worktree index. Scans files, indexes FTS, extracts symbols, builds graph. If background auto-index is already running, returns status:indexing instead of duplicating work.

RETURNS: {indexId, branch, indexedFiles, totalChunks, skipped, status, indexingStartedAt?, indexingAgeMs?}

EXAMPLE: cl_refresh
- **cl_search** — Hybrid search over the current branch index: FTS5 BM25 + symbol-name match + graph proximity, fused via weighted ranking. Compact ranked handles, cursor pagination. Use BEFORE grep/find/read for code discovery. Pass related:true to also get graph neighbors of the top result in one call.

RETURNS: {indexId, query, count, results:[{handle,path,lines,score,why,preview,stale?}], nextCursor, freshness, pendingFiles}

WHEN NOT: editing exact files (use cl_expand or read instead).

EXAMPLE: cl_search(query: "session validation", limit: 5)
- **cl_explore** — One-call code exploration over the current branch index: hybrid search grouped by file, compact source previews, signature-collapse, and a relationship/blast map. Use for broad questions like 'how does X work?' before falling back to separate search/expand/related calls.

RETURNS: {indexId, query, count, files:[{path, stale?, results:[{handle,lines,score,why,preview,signature?,collapsed?,stale?}]}], related:[{sourcePath,path,edgeType,hops,confidence,stale?}], freshness, pendingFiles?, nextCursor?, truncated?}

EXAMPLE: cl_explore(query: "session validation flow", limit: 8)
- **cl_related** — Graph expansion within the current index. Returns compact handles plus evidence chains, source spans, extraction methods, and minimum whole-chain confidence (a heuristic, not a probability). Imported_by is the incoming imports view. Work limits set truncated:true; stale intermediates mark chains stale.

RETURNS: {indexId, results:[{handle,path,edgeType,hops,confidence}]}

EXAMPLE: cl_related(path: "src/auth/auth.ts", types: ["imports"], depth: 2)
- **cl_impact** — Static blast-radius analysis for a symbol or file in the current branch index. Returns resolved symbol callers/callees, affected files/tests, documents, and evidence chains. Broader file dependencies remain in fileFallback, not proven symbol callers. Unsupported static forms can be absent. Check truncation and freshness. Use before changing shared code.

RETURNS: {indexId, target?, candidates?, callers, callees, affectedFiles, affectedTests, depth, confidenceNote, freshness?, pendingFiles?}

EXAMPLE: cl_impact(symbol: "validateSession", path: "src/auth/session.ts", depth: 2)
- **cl_diff** — Analyze base-commit changes against the current working tree, including untracked files. Maps changed current lines to verified indexed symbols and returns callers, dependencies, tests, documents, fileFallback, and coverage gaps. Removed code has unknown historical impact. Not staged-only and not a safety verdict. Check freshness, gaps, and truncation.

EXAMPLE: cl_diff(base: "HEAD", maxTargets: 20)
- **cl_path** — Find a bounded shortest static relationship chain between two indexed file paths or two symbols (path#Scope.name, or an unambiguous name). Returns evidence, direction, minimum chain confidence, freshness, and truncation. Not a runtime trace. Default direction is out; both allows reverse traversal. Mixed file/symbol targets are rejected.

EXAMPLE: cl_path(from: "src/routes.ts", to: "src/store.ts")
- **cl_overview** — Summarize architecture from the current branch's static dependency graph: deterministic navigation communities, dependency hubs, cross-group connections, and strongly connected cycles. Heuristic, not authoritative architecture. Returns bounded members, omitted counts, inputTruncated, convergence, and freshness. No LLM required.

EXAMPLE: cl_overview(limit: 10)
- **cl_tour** — Build a bounded evidence-backed reading tour from the current branch index. Optional start is an indexed code file. Returns ordered stops with source locations, selection reasons, anchored static relationship chains, and linked tests/documents. Roots are separate reading sections, not inferred execution entrypoints. Check freshness and truncation. No LLM required.

EXAMPLE: cl_tour(start: "src/server.ts", limit: 8)
- **cl_expand** — Return exact current local file content by path/range. Reads from disk — never stale stored text. Use after cl_search/cl_related to read target snippets before editing.

RETURNS: {path, startLine, endLine, content, truncated, chars}

EXAMPLE: cl_expand(path: "src/auth/session.ts", startLine: 12, endLine: 58, budget: 1200)
- **cl_map** — Outline / repo-map: per-file symbol signatures for a file or directory, read from the index (no file re-read). Cheap orientation before diving in. Defaults to exported symbols; pass all:true for everything.

RETURNS: {indexId, files:[{path, symbols:[{name,kind,signature,startLine,endLine,exported}]}], fileCount, truncated}

EXAMPLE: cl_map(path: "src/auth")
- **cl_save** — Save a named working-context set (handles/paths + notes) in a separate DB that survives core-index rebuilds. Pin to prevent TTL deletion.

RETURNS: {id, name, pinned, itemCount}

EXAMPLE: cl_save(name: "auth-investigation", items: [{path: "src/auth/session.ts"}], notes: "wip", pinned: true)
- **cl_load** — Load a saved working-context by name. Returns items (path/symbol-based, stable across reindex).

RETURNS: {context, items}

EXAMPLE: cl_load(name: "auth-investigation")
- **cl_stats** — Index statistics: file/symbol/chunk/edge/index counts, total indexes, last indexed. Scoped to active index.

RETURNS: {active, indexId, branch, counts, lastIndexedAt, totalIndexes}

EXAMPLE: cl_stats
- **cl_doctor** — Health check: node version, better-sqlite3, git, schema version, integrity (PRAGMA quick_check), WAL mode. No PII.

RETURNS: diagnostic booleans + integrityOk

EXAMPLE: cl_doctor
- **cl_usage** — Global usage statistics across all repos: per-tool call counts, bytes served, estimated context bytes saved, and a per-repo breakdown. Use to see how much the index tools are being used.

RETURNS: {perTool:[...], perRepo:[...], totals:{calls,bytes_served,bytes_saved}}

EXAMPLE: cl_usage
- **cl_prune** — Run a manual TTL sweep: delete expired inactive indexes. Never deletes active/pinned/locked/grace-window indexes.

RETURNS: {deletedIndexes, skipped}

EXAMPLE: cl_prune
- **cl_drop** — Delete a specific branch/index explicitly. Refuses the active or pinned index.

RETURNS: {deleted, indexId, reason?}

EXAMPLE: cl_drop(branch: "old-feature")

## Claude Desktop Quick Installation
Install path detected from listing signals. Uses `npx` (confidence: high):

```json
"mcpServers": {
  "codelens": {
    "command": "npx",
    "args": ["-y","@fodx/codelens"]
  }
}
```

## Documentation

## What CodeLens does

CodeLens indexes a repository's current branch or worktree into SQLite and exposes the resulting code model through an MCP server and command-line interface. The index combines lexical search with tree-sitter symbol extraction and source relationships such as imports, tests, calls, inheritance, definitions, and file membership. Each branch or worktree has its own index, preventing results from crossing branch boundaries.

Results are returned as compact handles and ranked matches rather than large blocks of raw source. The server can connect code to repository-local Markdown references, preserve named working contexts across index rebuilds, and maintain separate indexes for multiple repositories. Retrieval is deterministic and does not require a chat model.

## How it works

Use `cl_current` first to inspect repository, branch, index, and freshness state. `cl_refresh` scans files and rebuilds or updates the active index. Search tools can automatically refresh changed files before answering, while responses identify pending or stale data when work is limited by freshness or execution bounds.

`cl_search` combines FTS5 BM25 ranking, symbol-name matches, and graph proximity. `cl_explore` packages search results by file with previews, collapsed signatures, and a relationship map for broader questions. After locating a target, `cl_expand` reads the current file directly from disk, so its content is not taken from potentially stale stored text.

Graph-oriented tools operate on static evidence. `cl_related` expands relationships, `cl_path` finds bounded chains between files or symbols, and `cl_impact` estimates callers, callees, affected files, tests, and documents. `cl_diff` maps working-tree changes to indexed symbols and related code. `cl_overview` groups dependency communities, hubs, cross-group links, and cycles, while `cl_tour` creates a bounded, evidence-backed reading sequence.

## Setup and configuration

The installer supports macOS, Linux, and Windows and requires Node.js 22.5 or newer. It installs the `codelens` launcher, builds the application, and can configure detected MCP hosts automatically. Use the shell installer on macOS or Linux and the PowerShell installer on Windows, then open a new terminal.

`codelens install` can target all detected hosts or selected hosts, and can write either global or project-local configuration. The installer supports Claude Code, Cursor, Gemini CLI, Kiro, opencode, and Codex CLI. `codelens --check-install` verifies SQLite FTS5 and parser grammars without changing indexes. Native dependencies include `better-sqlite3`, tree-sitter, and language grammar packages; restricted npm install scripts may require reviewed approval and a rebuild.

## Tools and capabilities

- Check index state with `cl_current`, statistics with `cl_stats`, and runtime health with `cl_doctor`.
- Refresh indexes with `cl_refresh`, search with `cl_search`, and explore repositories with `cl_explore` or `cl_map`.
- Inspect relationships with `cl_related`, `cl_path`, `cl_impact`, `cl_diff`, `cl_overview`, and `cl_tour`.
- Read exact source ranges using `cl_expand`.
- Save and reload named investigation sets through `cl_save` and `cl_load`.
- Review aggregate tool usage with `cl_usage`, remove expired indexes with `cl_prune`, and explicitly delete eligible indexes with `cl_drop`.

## Limitations and notes

The graph describes static relationships, not runtime execution. Symbol resolution may omit unsupported language constructs, and broad file dependencies can appear separately from proven symbol callers. Relationship confidence is a conservative chain heuristic rather than a probability. Results can be truncated or stale, so callers should inspect freshness, gaps, and truncation fields.

`cl_diff` analyzes base-commit changes against the working tree, including untracked files; it is not limited to staged changes and is not a safety verdict. Removed code has unknown historical impact. Parser failures leave text search available but can remove symbols and parser-derived graph edges for affected languages. Saved contexts use a separate database and survive core-index rebuilds, while inactive indexes are subject to automatic TTL cleanup.

_Full upstream README: https://allmcps.com/mcp/fodx-codelens/readme_

