Code Intelligence
Navigate and understand codebases with xgrep — overview, search, go-to-definition, references, change-impact, and the code graph.
Code Intelligence
Beyond scanning, xgrep is a fast, AST-powered way to navigate and understand a
codebase — for humans and AI agents alike. It indexes symbols and call
relationships into a code graph and a search index (cached in .xgrep/, rebuilt
incrementally), so answers are precise (real symbols with locations) and navigable,
not just text hits.
Search is lexical and structural, not semantic — you find code by a name or a string it contains, then traverse call relationships. When you only know what code does, not its name, start with an overview to learn the vocabulary, then search those names and follow the references.
Two entry points, both with --json on every command:
xgrep inspect— overview, symbol/text search, go-to-definition, hover, references, implementations, file outline, change-impact, and dependencies.xgrep graph— build and query the call graph: callers, callees, call paths, reachability, and N-hop neighborhoods with inlined source.
The examples on this page and in the command reference run against expressjs/express — clone it and follow along:
git clone https://github.com/expressjs/express && cd expressWhat you can do
Understand a new codebase
Start with a one-shot map — languages, packages, entry points, key types — then drill into a file or a name:
xgrep inspect overview . # high-level map of the whole tree
xgrep inspect outline lib/router/route.js # every symbol in one file, in order
xgrep inspect symbol "Router" # find a symbol by name (exact → prefix → substring)Find code fast
Sub-millisecond trigram search after the first index, with regex, language, and glob filters:
xgrep inspect search "res.send" --file-pattern "*.js"
xgrep inspect search "req\.(query|body|params)" --regex --lang javascriptNavigate like an IDE
Resolve, explain, and cross-reference a symbol at a position or by name:
xgrep inspect definition --file lib/router/route.js --line 43 # what is this?
xgrep inspect hover --file lib/router/route.js --line 43 # docs, type, signature
xgrep inspect references "matchLayer" # callers + callees
xgrep inspect implementations "Router" # who implements this interfaceAssess change impact
Before you touch a function, see its blast radius — direct and transitive callers, affected files, and a risk score:
xgrep inspect impact "matchLayer" # blast radius + risk score
xgrep inspect deps "matchLayer" --depth 3 # up/downstream call dependencies
xgrep graph reachable "acceptParams" # everything this function can reachTriage a finding
Pull a finding's call neighborhood with the source inlined — topology and code in one shot, ideal for deciding whether a finding is reachable:
xgrep graph context "matchLayer" --depth 2Power an AI agent
Every command emits --json, and the same capabilities are exposed as MCP tools via
xgrep mcp, so an agent can map, navigate, and triage a codebase without bespoke
tooling. See AI agents for end-to-end workflows that
combine code intelligence with scanning.
Reference
- Inspect — every
inspectcommand, its flags, caching behavior, the MCP tool mapping, and supported languages. - Code graph — building and querying the call graph.