Prev Next

AI / CodeGraph Interview questions

Last updated

1. What is CodeGraph? 2. What problem does CodeGraph solve for AI coding agents? 3. How do you install CodeGraph? 4. Which AI agents does the CodeGraph installer configure? 5. How do you initialize CodeGraph in a project? 6. Where does CodeGraph store its index? 7. What is the purpose of the CodeGraph MCP server? 8. List the MCP tools CodeGraph exposes? 9. What does the codegraph_context tool do? 10. What does the codegraph_trace tool do? 11. What does the codegraph_impact tool do? 12. What is the codegraph_explore tool? 13. Which programming languages does CodeGraph support? 14. What is the role of tree-sitter in CodeGraph? 15. What are the nodes and edges in a CodeGraph graph? 16. What does the codegraph affected command do? 17. What does codegraph status show? 18. List the main CodeGraph CLI commands? 19. How do you uninstall CodeGraph? 20. What does CodeGraph skip when indexing by default? 21. What is framework-aware route detection in CodeGraph? 22. How do you use CodeGraph as a TypeScript library? 23. What does the CodeGraph installer add to CLAUDE.md? 24. What does '100% local' mean for CodeGraph? 25. What flags does the codegraph install command accept? 26. How does CodeGraph keep the index fresh automatically? 27. What happens when an agent queries a file with a pending sync? 28. How does CodeGraph's connect-time catch-up work? 29. Explain the internal working of CodeGraph's indexing pipeline? 30. Why does CodeGraph use SQLite with FTS5? 31. Why does CodeGraph reduce tool calls compared to grep and Read? 32. How were CodeGraph's benchmark numbers measured? 33. Why do CodeGraph's savings vary between Tokio and OkHttp? 34. What is the difference between codegraph index and codegraph sync? 35. When should you run codegraph sync manually? 36. What is the difference between codegraph_trace and chaining callers and callees? 37. What is the difference between codegraph_context and codegraph_explore? 38. Why does CodeGraph tell agents not to delegate exploration to sub-agents? 39. How does CodeGraph bridge Swift and Objective-C calls? 40. How does CodeGraph link React Native JavaScript calls to native code? 41. What does provenance heuristic mean on CodeGraph edges? 42. How do you tune or disable CodeGraph's file watcher? 43. How do you use codegraph affected in a CI pipeline? 44. How do you troubleshoot 'database is locked' errors in CodeGraph? 45. How do you troubleshoot missing symbols in CodeGraph? 46. How do you troubleshoot CodeGraph's MCP server not connecting? 47. How can you optimize CodeGraph indexing on a large repository? 48. How do you pull a default-excluded directory like vendor into the graph? 49. Which is better for a small repo: CodeGraph or plain grep, and why? 50. What happens when an agent starts in a project without a.codegraph directory?

1. What is CodeGraph?

CodeGraph is an open-source tool that builds a pre-indexed, local knowledge graph of your codebase and hands it to AI coding agents through an MCP server. The graph stores symbols (functions, classes, methods) and the relationships between them: calls, imports, extends and implements.

Instead of letting an agent grep, glob and read files one by one, the agent asks CodeGraph a question and gets the relevant source and call paths back in a few calls. It targets agents such as Claude Code, Cursor, Codex CLI, opencode, Hermes Agent, Gemini CLI, Antigravity IDE and Kiro.

Everything runs on your machine. The index sits in a SQLite database, and no API keys or external services are needed.

Note: this pack covers the colbymchenry/codegraph project (npm package @colbymchenry/codegraph). Other unrelated projects share the CodeGraph name.

Take quiz
CodeGraph gives an AI agent access to a codebase mainly through:
a pre-indexed local knowledge graph exposed over MCP
a hosted vector service that needs an API key
a plugin that rewrites source files before every prompt
Which npm package installs CodeGraph?
@codegraph/core
@colbymchenry/codegraph
codegraph-mcp-server

2. What problem does CodeGraph solve for AI coding agents?

It removes the discovery tax. When an agent such as Claude Code explores a repository, it spawns Explore agents that scan with grep, glob and Read, and every one of those tool calls burns tokens before the agent even reaches the right code.

CodeGraph replaces that scan with graph queries over symbol relationships, call graphs and code structure that were indexed ahead of time. The agent can often answer "how does X work?" from the index with zero file reads.

In the project's own benchmark (v0.9.4, seven open-source repos), the average result was 35% cheaper, 57% fewer tokens, 46% faster and 71% fewer tool calls. Treat those as vendor-reported numbers: they depend on the repo and the question.

Take quiz
Where does most of the cost come from when an agent explores code without CodeGraph?
downloading the repository again for each query
recompiling the project for every question
repeated grep, glob and Read calls to discover structure
Across the benchmark repos, CodeGraph's average reduction in tool calls was about:
71%
35%
57%

3. How do you install CodeGraph?

There are three routes, and all of them end in an interactive installer that configures your agents.

  1. Shell installer (no Node.js needed, it bundles its own runtime): curl the install.sh script on macOS/Linux, or irm the install.ps1 script in PowerShell on Windows.
  2. npx: npx @colbymchenry/codegraph downloads and runs the installer in one go.
  3. npm global: npm i -g @colbymchenry/codegraph.
curl -fsSL https://raw.githubusercontent.com/colbymchenry/codegraph/main/install.sh | sh
# or
npx @colbymchenry/codegraph

After installing, restart your agent so it loads the MCP server, then run codegraph init -i inside each project you want indexed.

Take quiz
Do you need Node.js installed to use the shell or PowerShell installer?
Yes, Node 18 or newer is mandatory
No, the build bundles its own Node runtime
Yes, plus a C++ toolchain for native modules
After the installer wires up your agent, what makes the MCP server load?
rebooting the whole machine
running codegraph sync --force
restarting the agent

4. Which AI agents does the CodeGraph installer configure?

The installer auto-detects and configures eight agents: Claude Code, Cursor, Codex CLI, opencode, Hermes Agent, Gemini CLI, Antigravity IDE and Kiro. For each one it registers the MCP server and writes an instructions file that teaches the agent when to use CodeGraph.

Agent Instructions file written
Claude Code CLAUDE.md (plus auto-allow permissions)
Cursor .cursor/rules/codegraph.mdc
Codex CLI ~/.codex/AGENTS.md
Gemini CLI ~/.gemini/GEMINI.md

You can pick agents explicitly with --target=cursor,claude instead of auto-detection. The supported list may grow, so check the README for your version.

Take quiz
Which file does the installer write for Cursor?
.cursor/rules/codegraph.mdc
.cursorrules.json
~/.cursor/AGENTS.md
Which of these is on the installer's agent list?
JetBrains AI Assistant
Kiro
Sourcegraph Cody

5. How do you initialize CodeGraph in a project?

Run codegraph init -i from the project root. It creates the local .codegraph/ directory and, because of -i (--index), builds the full graph in the same step.

cd your-project
codegraph init -i

It also wires up any project-local agent surfaces, such as Cursor's rules file, so one global codegraph install keeps working in every project you open.

Once .codegraph/ exists, agents use the CodeGraph tools automatically. Without it, the project simply isn't indexed.

If you aren't standing in the project root, codegraph init [path] accepts a path. To start over later, codegraph uninit removes the index and you can initialise again.

Take quiz
What does the -i flag add to codegraph init?
it installs CodeGraph globally
it skips creating the .codegraph directory
it indexes the project immediately
Agents start using CodeGraph tools in a project when:
a .codegraph/ directory exists there
a codegraph.config.json is committed
the project contains a package.json

6. Where does CodeGraph store its index?

In a local SQLite database at .codegraph/codegraph.db inside each project. Symbols, edges and files live in tables, and FTS5 provides full-text search over names.

Current builds ship their own Node runtime and use Node's built-in node:sqlite in WAL mode, so concurrent readers don't block on a writer.

Removing the index is per project: codegraph uninit deletes it (use --force to skip the prompt). codegraph uninstall deliberately leaves .codegraph/ alone.

Because the index is a plain file inside the project, there's no server process to manage. If it ever drifts out of step, codegraph index --force rebuilds it. You'll usually want to keep .codegraph/ out of version control (that part is my suggestion, not a README rule).

Take quiz
Which storage engine backs the CodeGraph index?
an embedded Kuzu graph database
SQLite with FTS5
a hosted Neo4j instance
Which command deletes a project's index?
codegraph uninstall
codegraph sync --clean
codegraph uninit

7. What is the purpose of the CodeGraph MCP server?

It's the bridge between the index and your agent. Your agent launches codegraph serve --mcp over stdio, and the server answers tool calls such as search, context, callers and impact from the SQLite graph.

The same process also watches your project for file changes and keeps the index in sync, so answers don't go stale while the agent edits code.

{
  "mcpServers": {
    "codegraph": {
      "type": "stdio",
      "command": "codegraph",
      "args": ["serve", "--mcp"]
    }
  }
}

The installer writes this into ~/.claude.json for Claude Code, so you rarely edit it by hand.

The agent launches the server over stdio, so it starts and stops with the agent session. That is exactly why the connect-time catch-up exists: it reconciles anything that changed while no server was running.

Take quiz
Which command starts CodeGraph's MCP server?
codegraph serve --mcp
codegraph mcp start
codegraph daemon --port 3748
Besides answering tool calls, the MCP server also:
uploads query logs for model training
watches the project and re-indexes changed files
rebuilds the entire index every five minutes

8. List the MCP tools CodeGraph exposes?

CodeGraph exposes ten tools to the agent:

Tool Purpose
codegraph_search Find symbols by name
codegraph_context Build relevant context for a task
codegraph_trace Trace the call path between two symbols
codegraph_callers What calls a function
codegraph_callees What a function calls
codegraph_impact What is affected by changing a symbol
codegraph_node Details (and optionally source) of one symbol
codegraph_explore Source of several related symbols, grouped by file
codegraph_files Indexed file structure
codegraph_status Index health and statistics

In practice an agent rarely uses all ten. The common pattern is context, then explore, with trace for path questions, impact before an edit and status when something looks stale.

Take quiz
Which tool finds a symbol by name?
codegraph_node
codegraph_files
codegraph_search
Which tool reports index health and pending syncs?
codegraph_status
codegraph_files
codegraph_context

9. What does the codegraph_context tool do?

codegraph_context maps a task or feature area in a single call. It composes search, node lookup, callers and callees, then returns entry points, related symbols and code snippets.

The agent instructions tell it to call this first, before anything else, when it needs to understand an area. The same capability is available on the command line as codegraph context <task> with --format and --max-nodes, and in code as buildContext().

codegraph context "fix login bug" --max-nodes 20

Think of it as the cheap first move. Instead of guessing filenames and grepping, one call returns the likely entry points and the symbols around them, and the agent can then zoom in with explore or node.

Take quiz
When should an agent call codegraph_context?
last, to verify that edits compile
first, to map a task or feature area
only to read a single symbol's signature
Which CLI options does codegraph context accept?
--depth and --stdin
--kind and --force
--format and --max-nodes

10. What does the codegraph_trace tool do?

codegraph_trace answers "how does X reach Y?". Give it two symbols and it returns the call path between them in one call, with each hop's source body inline.

Its useful trick is following hops that text search can't: dynamic dispatch such as callbacks, React re-renders and interface-to-implementation jumps. With grep you'd find the name at each end and guess the middle.

Use it for questions like "how does a request reach the database?" where the interesting part is the chain, not either endpoint.

Take quiz
codegraph_trace is designed to answer:
how one symbol reaches another along the call path
which tests cover a symbol
which files changed since the last commit
Which kind of hop can trace follow that plain grep misses?
calls that appear only inside comments
dynamic dispatch such as callbacks and interface-to-implementation
calls inside files larger than 1 MB

11. What does the codegraph_impact tool do?

codegraph_impact shows what is affected if you change a symbol. It walks callers outward from that symbol to build its impact radius, so the agent can see the blast radius before it edits anything.

On the CLI, codegraph impact <symbol> takes --depth to control how many hops to follow and --json for machine-readable output. In the library, the equivalent is getImpactRadius(nodeId, depth).

codegraph impact parseConfig --depth 3

A typical use: before changing the signature of a widely used helper, the agent calls impact, sees which callers fan out, and plans the edit and tests accordingly. Pair it with codegraph affected to find the test files that cover the touched modules.

Take quiz
When is codegraph_impact most useful?
after deployment, to roll back changes
while installing, to pick a target agent
before editing a symbol, to see what could break
Which CLI option sets how far impact traverses?
--depth
--radius
--hops

12. What is the codegraph_explore tool?

codegraph_explore returns the source of several related symbols, grouped by file, plus a relationship map, all in one budget-capped call.

Agents typically call codegraph_context to find the right area, then one codegraph_explore to read the relevant code, and stop. The returned source is treated as already read, so the agent shouldn't re-open those files.

The budget cap keeps one call from flooding the context window with source.

Compared with calling codegraph_node for one symbol at a time, explore saves round trips when the answer spans several functions, say a handler, its service and the repository it calls. Use codegraph_node when you only need one signature.

Take quiz
codegraph_explore returns:
only a list of file paths
source for related symbols grouped by file, plus a relationship map
a diff of uncommitted changes
What does 'budget-capped' protect against?
indexing more than one project
running longer than the debounce window
one call dumping too much source into the context

13. Which programming languages does CodeGraph support?

About 22 languages. Full support covers TypeScript, JavaScript, Python, Go, Rust, Java, C#, PHP, Ruby, C, C++, Swift, Kotlin, Scala, Dart, Svelte, Vue, Liquid, Pascal/Delphi, Lua and Luau.

Objective-C is partial: classes, protocols, methods, @property, #import and message sends work, but .mm (Objective-C++) files may parse incompletely.

There's nothing to configure per language. The parser is chosen automatically from the file extension.

Svelte and Vue single-file components get script extraction (Svelte 5 runes, SvelteKit routes, Nuxt page, API and middleware routes), and Luau adds type aliases and Roblox instance-path require. Mixed-language repos are fine because one graph spans every supported language in the project.

Take quiz
How is Objective-C support described?
partial, with .mm files possibly parsing incompletely
full, identical to Swift
not supported at all
How does CodeGraph choose a language parser?
from a languages list in a config file
automatically from the file extension
from a --lang flag passed to every command

14. What is the role of tree-sitter in CodeGraph?

tree-sitter is the parser behind extraction. CodeGraph runs it on every supported source file to produce an abstract syntax tree, then applies language-specific queries to pull out nodes (functions, classes, methods) and edges (calls, imports, extends, implements).

Because tree-sitter is fast and error-tolerant, files that are mid-edit or slightly broken can still yield useful symbols. It only sees syntax, though, so linking a call to the right definition is a separate resolution step that runs afterwards.

Because the extraction queries are written per language, support is reported per language in the README, with Objective-C marked partial.

Take quiz
What does tree-sitter produce for CodeGraph?
vector embeddings of each function
compiled bytecode for each file
ASTs from which nodes and edges are extracted
Which pair are edge kinds named for the graph?
calls and imports
reads and writes
allocates and frees

15. What are the nodes and edges in a CodeGraph graph?

Nodes are code entities: functions, classes, methods and files, plus specialised ones like framework route nodes and React Native component and property nodes.

Edges are relationships between them: calls, imports, extends, implements and references. A route node, for example, is linked by a references edge to its handler.

Queries are just walks over this graph. A callers query follows incoming calls edges, and an impact query follows them outward for several hops.

Synthetic nodes exist too. For Expo Modules, the DSL literals produce synthetic method nodes that then resolve through ordinary name matching, so the graph includes entities created from framework conventions as well as what the parser sees directly.

Take quiz
A framework route node is connected to its handler by which edge?
implements
references
extends
What does a callers query return?
symbols the function calls
files that import the function's package
symbols that call the given function

16. What does the codegraph affected command do?

It finds the test files affected by a set of changed source files by tracing import dependencies transitively.

Option Meaning Default
--stdin Read the file list from stdin false
-d, --depth <n> Max dependency traversal depth 5
-f, --filter <glob> Glob that identifies test files auto-detect
-j, --json / -q, --quiet JSON output / paths only false

codegraph affected src/utils.ts src/api.ts
git diff --name-only | codegraph affected --stdin

Use it to shrink a test run. Given a change to a utility module, it walks importers outward up to the depth limit and returns only the test files that transitively depend on it. It works on import dependencies, so treat it as a fast filter rather than a guarantee for code reached through runtime lookups.

Take quiz
What is the default traversal depth for codegraph affected?
5
3
10
How do you feed it the files from a git diff?
codegraph affected --git HEAD
git diff --name-only | codegraph affected --stdin
codegraph affected --diff-files

17. What does codegraph status show?

codegraph status prints statistics and health for a project's index. The MCP equivalent is codegraph_status, which agents use to check whether the index is trustworthy.

If edits are still waiting to be synced, you'll see a Pending sync section naming the files and how long ago they were edited. It also reports a Journal: line; anything other than wal means WAL mode couldn't be enabled on that filesystem.

A good habit is to run it once after the first index to confirm the counts look sane, and again whenever an agent claims a symbol doesn't exist.

Take quiz
What does a Pending sync section in the status output list?
agents that failed to connect
languages that failed to parse
files awaiting re-index and the age of their edits
A Journal value other than wal suggests:
WAL mode couldn't be enabled on that filesystem
the index was built by an older agent
the file watcher crashed

18. List the main CodeGraph CLI commands?

These are the commands you'll use day to day, grouped by whether they set things up, build the index, or query it.

Command What it does
codegraph install / uninstall Configure or remove CodeGraph in your agents
codegraph init [path] Initialize a project (--index to also index)
codegraph index [path] Full index (--force, --quiet)
codegraph sync [path] Incremental update
codegraph status [path] Show statistics
codegraph query <search> Search symbols (--kind, --limit, --json)
codegraph callers / callees <symbol> Walk call flow one hop
codegraph impact <symbol> Show affected code
codegraph context <task> Build context for an AI
codegraph affected [files] Find affected test files
codegraph serve --mcp Start the MCP server

Take quiz
Which command performs an incremental update of the index?
codegraph index --force
codegraph sync
codegraph init
Which command builds context for an AI from a task description?
codegraph query
codegraph files
codegraph context

19. How do you uninstall CodeGraph?

Run codegraph uninstall. It reverses the installer by stripping CodeGraph's MCP server config, instruction blocks and permissions from every agent it configured.

Use --target to limit removal to specific agents and --yes to run without prompts. Your project indexes in .codegraph/ are not touched, so remove those per project with codegraph uninit.

A clean removal is therefore two steps: codegraph uninstall for the agent configs, then codegraph uninit in each project whose index you want gone. --target is handy if you only want to detach one agent, say Cursor, while keeping Claude Code wired up.

Take quiz
What does codegraph uninstall leave behind?
each project's .codegraph/ index
the MCP server entries in agent configs
the permissions added for Claude Code
Which flag runs the uninstall non-interactively?
--force-all
--yes
--silent-remove

20. What does CodeGraph skip when indexing by default?

It's zero-config, so the defaults do the filtering. CodeGraph skips three groups of files:

  • Dependency, build and cache directories such as node_modules, vendor, dist, build, target, .venv, Pods and .next, even with no .gitignore.
  • Anything in your .gitignore, via git in repos and by reading the file directly in non-git projects (root and nested).
  • Files larger than 1 MB, which catches generated bundles, minified JS and vendored blobs.

The goal is a graph of your code rather than third-party noise.

Take quiz
Files above which size are skipped?
100 KB
10 MB
1 MB
Where do you add an extra path to keep it out of the graph?
.gitignore
a codegraph.config.json file
an environment variable

21. What is framework-aware route detection in CodeGraph?

CodeGraph recognises web-framework routing files and emits route nodes linked by references edges to the handler class or function. As a result, asking for the callers of a view or controller also surfaces the URL pattern that binds to it.

Framework Shapes recognised
Django path(), re_path(), include() in urls.py
Flask / FastAPI @app.route(...), @app.get(...)
Express app.get(...) with middleware chains
Spring @GetMapping, @RequestMapping
Rails get '/x', to: 'users#index'

The README lists 14 frameworks in total, including NestJS, Laravel, Drupal, ASP.NET, Vapor and React Router.

Take quiz
What does route detection add to a callers query on a controller?
the database table it reads
the URL pattern that binds to it
its latest git blame author
How is a route node attached to its handler?
by a calls edge to main()
by an extends edge to the router
by a references edge

22. How do you use CodeGraph as a TypeScript library?

Import the default export, initialise or open a project, index it, then query. The library mirrors what the CLI and MCP tools do.

import CodeGraph from '@colbymchenry/codegraph';

const cg = await CodeGraph.init('/path/to/project'); // or CodeGraph.open(...)
await cg.indexAll({ onProgress: p => console.log(p.phase, p.current, p.total) });

const results = cg.searchNodes('UserService');
const callers = cg.getCallers(results[0].node.id);
const ctx = await cg.buildContext('fix login bug', { maxNodes: 20, includeCode: true, format: 'markdown' });
const impact = cg.getImpactRadius(results[0].node.id, 2);

cg.watch();   // auto-sync on file changes
cg.unwatch(); // stop watching
cg.close();

Remember to call close() when you finish.

CodeGraph.init sets up a new project index, while CodeGraph.open attaches to an existing one. indexAll takes an onProgress callback reporting phase, current and total, which is handy for a progress bar in your own tooling.

searchNodes finds symbols by name, getCallers walks incoming call edges, buildContext assembles task context (maxNodes, includeCode, format), and getImpactRadius takes a node id plus a depth. watch() turns on the same auto-sync the MCP server uses.

Reach for the library when you're building your own tooling on top of the graph rather than going through MCP.

Take quiz
Which method opens an already-initialised project?
CodeGraph.open
CodeGraph.attach
CodeGraph.load
Which call returns the impact radius of a node?
getBlastZone(nodeId)
getImpactRadius(nodeId, depth)
buildImpact(nodeId)

23. What does the CodeGraph installer add to CLAUDE.md?

It adds a short CodeGraph section that tells Claude how to behave. If .codegraph/ exists, Claude should answer directly with CodeGraph tools instead of delegating exploration to a file-reading sub-agent or a grep/read loop, and usually finish with zero file reads.

It also includes a tool-by-intent table: context to map an area, trace for "how does X reach Y", explore for several symbols at once, search for names, callers/callees for one hop, impact before editing and node for one symbol.

If .codegraph/ doesn't exist, Claude is told to ask at the start of a session whether to run codegraph init -i.

Take quiz
If .codegraph/ is missing, what does the injected guidance tell Claude to do?
silently run a full index
disable all MCP tools
ask the user whether to initialize CodeGraph
What does the guidance say to avoid when .codegraph/ exists?
delegating exploration to a file-reading sub-agent
calling codegraph_context first
using codegraph_impact before edits

24. What does '100% local' mean for CodeGraph?

No data leaves your machine. The graph is a SQLite file in the project, extraction runs through tree-sitter locally, and there are no API keys or external services involved.

The installer also ships a bundled runtime, so nothing needs compiling or downloading at query time. The agent still talks to its own model provider as usual; CodeGraph just means your index and the structural queries stay on disk.

That makes adoption easy in restricted environments: no accounts and nothing to audit beyond a local file you can delete any time with codegraph uninit. Whether the agent's own model calls leave the machine depends on the agent, not on CodeGraph.

Take quiz
Which statement matches 'local' for CodeGraph?
the graph is synced to a cloud workspace
indexing and queries run on your machine with no API keys
queries are sent to an embedding API
Where does the graph data live?
on Anthropic's servers
in a shared team database
in a SQLite file inside the project

25. What flags does the codegraph install command accept?

The installer runs interactively by default, and flags let you script it for CI or dotfiles.

Flag Values Default
--target auto, all, none or a CSV like claude,cursor prompt
--location global, local prompt
--yes boolean prompt every step
--no-permissions skip the Claude auto-allow list permissions on
--print-config <id> dump one agent's snippet and exit none

codegraph install --yes
codegraph install --target=cursor,claude --yes
codegraph install --print-config codex

A common setup is --location=global once on a workstation so every project gets the MCP server, then codegraph init -i per repo. For a dotfiles repo or CI image, combine --yes with an explicit --target so the result doesn't depend on which agents happen to be installed. Use --print-config when you only want the snippet to paste into a managed config.

Take quiz
Which flag prints an agent's config snippet without writing files?
--print-config
--dry-run-all
--show-mcp
What does --no-permissions skip?
the MCP server registration
the Claude auto-allow permissions list
the instructions file

26. How does CodeGraph keep the index fresh automatically?

Through three layers that work together while the MCP server is running, so an agent never gets a silent wrong answer between an edit and the next sync.

  1. File watcher with debounced sync. A native OS watcher (FSEvents, inotify or ReadDirectoryChangesW) captures source-file creates, modifies and deletes, then re-indexes after a quiet window. The default is 2000 ms.
  2. Per-file staleness banner. If a tool response touches a file that's still pending, it carries a warning telling the agent to read that file directly.
  3. Connect-time catch-up. When the server (re)connects, it reconciles the index with the working tree before answering the first query.
flowchart LR
  A["Agent edits Widget.ts"] --> B["Native watcher fires"]
  B --> C["2s debounce window"]
  C --> D["Incremental sync"]
  D --> E["Next query sees Widget.ts"]
Take quiz
What is the default debounce window before CodeGraph re-indexes after a change?
200 ms
30 seconds
2000 ms
Which layer catches edits made while no MCP server was running?
connect-time catch-up
the per-file staleness banner
the debounce timer

27. What happens when an agent queries a file with a pending sync?

CodeGraph prepends a warning banner to the tool response that names the still-pending file and tells the agent to Read it directly for live content. This covers the short debounce window between an edit and the re-index.

Pending files that the response doesn't reference show up as a small footer instead of a banner.

The README says it has been validated with Claude Code, where the agent literally announces that it is reading the file directly before opening it. The trade-off is one extra read for that file, in exchange for never trusting stale graph data.

Practically, a freshly edited file may cost the agent one extra read, but the graph never silently serves stale structure for it. Once the debounce window passes and the sync completes, the banner disappears and queries return the new symbols.

Take quiz
How does CodeGraph flag a pending file the response relies on?
it silently omits the file from the answer
a banner telling the agent to Read the file directly
it blocks the call until the sync finishes
How are pending files that the response does not reference reported?
as an error status code
they are never reported
as a small footer

28. How does CodeGraph's connect-time catch-up work?

When the MCP server (re)connects, CodeGraph runs a fast reconciliation of the index against the working tree before answering the first query. It compares (size, mtime) and a content hash to spot files that changed.

This absorbs edits the watcher never saw: a git pull from the terminal, changes from another editor, or a previous agent session that exited. The first tool call of the next session therefore starts from a correct graph.

Because it runs before the first query is answered, that first call may take slightly longer on a big tree; later calls aren't affected. It complements the watcher rather than replacing it: the watcher handles live edits, and catch-up handles everything that happened while nothing was watching.

Take quiz
What does catch-up compare to detect changed files?
size, mtime and a content hash
only file names
git commit timestamps
Which scenario does catch-up exist for?
a syntax error inside a single file
a git pull made while no MCP server was running
a stale npm cache

29. Explain the internal working of CodeGraph's indexing pipeline?

Indexing is a four-stage pipeline, and each stage hands a cleaner artifact to the next.

  1. Extraction. tree-sitter parses each file into an AST. Language-specific queries emit nodes (functions, classes, methods) and edges (calls, imports, extends, implements).
  2. Storage. Everything goes into .codegraph/codegraph.db, a SQLite database with FTS5 full-text search.
  3. Resolution. References are resolved: function calls to definitions, imports to source files, class inheritance, plus framework-specific patterns such as routes.
  4. Auto-sync. The MCP server watches the project, debounces for two seconds, filters to source files and syncs incrementally.
flowchart LR
  S["Source files"] --> T["tree-sitter AST"]
  T --> X["Nodes and edges"]
  X --> D[(SQLite + FTS5)]
  D --> R["Resolve calls, imports, inheritance"]
  W["File watcher"] --> D

Extraction only knows syntax, which is why resolution is a separate pass: a bare save() call has to be matched to the right definition.

Take quiz
Which stage matches a function call to its definition?
extraction
storage
resolution
Which component supplies full-text name search in the pipeline?
FTS5 inside the SQLite database
the tree-sitter query engine
the MCP transport layer

30. Why does CodeGraph use SQLite with FTS5?

SQLite gives CodeGraph a single-file, zero-service store: one .codegraph/codegraph.db per project, no server to run and nothing leaving the machine. That fits the "100% local, no config" promise.

FTS5 supplies the name search behind codegraph_search, so finding a symbol across a large repo doesn't mean scanning files.

WAL mode matters too. On the bundled runtime's node:sqlite, concurrent reads never block on a writer, which is what lets an agent query the graph while the watcher is mid-sync. On network shares or WSL2 /mnt, WAL may be unavailable and you can hit lock contention.

The trade-off is that SQLite is an embedded engine rather than a dedicated graph database, so callers and impact are queries over symbol and edge tables. For a local, read-mostly index, that simplicity is the point.

Take quiz
What does FTS5 power in CodeGraph?
tree-sitter parsing
fast symbol name search
git history analysis
Why does WAL mode help during agent sessions?
it compresses the database file
it encrypts source snippets
reads don't block while a sync is writing

31. Why does CodeGraph reduce tool calls compared to grep and Read?

Because the structure is already computed. Without it, an agent spends most of its budget on discovery: find, ls and grep to locate the right files, then Read to open them, often through sub-agents that repeat the same work.

With the index, the agent calls codegraph_context to map the area, then one codegraph_explore for the relevant source, and stops, usually with zero file reads.

Repo Tool calls with CodeGraph Without
Excalidraw 3 79
Tokio 4 53
VS Code 8 55

These are medians from the project's benchmark, so treat them as indicative rather than guaranteed.

There's a second effect: fewer calls mean fewer tokens re-sent as context, which is why the README reports a 57% average token drop next to the 71% drop in tool calls. The effect also grows with repo size: on VS Code (~10k files) tool calls fell by 85%.

Take quiz
What typical flow lets the agent answer with zero file reads?
codegraph_context to map, then one codegraph_explore
codegraph_status then codegraph_files
codegraph_search then a full Read of each hit
What does the no-CodeGraph agent spend most of its budget on?
compiling the project
discovery with find, ls and grep
waiting for the file watcher

32. How were CodeGraph's benchmark numbers measured?

The README describes a controlled A/B run against seven open-source repositories (re-validated on v0.9.4 on 2026-05-24).

  1. Each arm runs claude -p headlessly with Claude Opus 4.7 and --strict-mcp-config.
  2. WITH enables CodeGraph's MCP server; WITHOUT uses an empty MCP config. Built-in Read, Grep and Bash stay available to both.
  3. Each repo gets one architecture question, run 4 times per arm, and the median is reported.
  4. Cost is the run's total_cost_usd; tokens include cached input plus output; tool calls include those inside spawned sub-agents.
  5. Repos are cloned with --depth 1 and indexed by the same CodeGraph build that serves them.

The headline average was 35% cheaper, 57% fewer tokens, 46% faster and 71% fewer tool calls. It's a vendor benchmark with one question per repo, so your mileage will vary.

Take quiz
How many runs per arm does the benchmark take, and what is reported?
10 runs, the mean
1 run, the best result
4 runs, the median
What does the WITHOUT arm change?
it uses an empty MCP config but keeps Read, Grep and Bash
it disables all built-in tools
it uses a different model

33. Why do CodeGraph's savings vary between Tokio and OkHttp?

The gap comes from how hard the agent without CodeGraph has to work on each repo. On Tokio it fanned out to 53 tool calls and a $2.41 median run, versus $0.42 with CodeGraph: 82% cheaper. On OkHttp it needed only 11 calls and the cost was essentially identical ($0.47 vs $0.47), so only 2% cheaper.

Repo Cost saving Tool-call saving
Tokio (Rust, ~790 files) 82% 92%
Excalidraw (TS, ~640) 52% 96%
Gin (Go, ~110) 21% 40%
OkHttp (Java, ~645) 2% 45%

The README's explanation is that gains scale with codebase size and that on small repos native search is already cheap. Note OkHttp isn't small, which shows per-repo numbers also move run to run with how much the without-arm thrashes.

Take quiz
Which repo showed the biggest cost saving in the benchmark?
OkHttp at 82%
Tokio at 82%
Gin at 82%
What mainly drives the savings gap between repos?
the licence of each repository
the number of contributors
how much the no-CodeGraph agent has to search

34. What is the difference between codegraph index and codegraph sync?

codegraph index does a full index of the project; codegraph sync does an incremental update of only what changed.

codegraph index codegraph sync
Scope Whole project Changed files only
Options --force to re-index, --quiet path argument
Typical use First build, or a clean rebuild Catch up after edits when the watcher is off

codegraph init -i performs the first index for you. In normal agent use you rarely run either by hand because the MCP server syncs automatically.

A sensible rule is to let the watcher or sync do the routine work and use index --force only when you suspect the database is out of step with the tree and a plain sync didn't fix it.

Take quiz
Which command forces a complete re-index?
codegraph index --force
codegraph sync --full
codegraph init --reset
What does sync process?
every file in the project
only files that changed
only test files

35. When should you run codegraph sync manually?

Only in a few cases, because auto-sync normally keeps the index current.

  • The watcher is disabled, for example in a sandboxed environment or when CODEGRAPH_NO_DAEMON=1 is set.
  • You're scripting against the index outside an agent session and want a pre-flight sync at the start of the script.
  • You suspect a symbol is missing and want to rule out a stale index before digging further.
codegraph sync
codegraph status   # confirm nothing is pending

If the MCP server is running with the watcher on, a manual sync is redundant.

Manual runs are cheap because sync is incremental, so there's no penalty for running one defensively before a scripted query. Finish with codegraph status to confirm the Pending sync section is empty.

Take quiz
Which setting makes manual sync necessary?
CODEGRAPH_FAST_MODE=1
CODEGRAPH_COLOR=0
CODEGRAPH_NO_DAEMON=1
Which tool lets you verify nothing is pending after a sync?
codegraph status
codegraph files
codegraph affected

36. What is the difference between codegraph_trace and chaining callers and callees?

codegraph_trace returns the whole path between two symbols in one call. Chaining codegraph_callers or codegraph_callees walks the flow one hop per call, so the agent has to decide which branch to follow each time.

codegraph_trace callers / callees
Calls needed One for the whole path One per hop
Hop bodies Inline for every hop Symbol lists, source fetched separately
Dynamic dispatch Follows callbacks, React re-render, interface-to-implementation One edge per hop, interpreted by the agent
Best for "How does X reach Y?" Exploring around one symbol

Use trace when you know both ends. Use callers and callees when you're still exploring around a single function.

Take quiz
When is codegraph_trace the better fit?
you only want a symbol's signature
you know both endpoints and want the path between them
you want to list indexed files
How many calls does a callers/callees walk need for a three-hop path?
exactly one
none, it is precomputed
roughly one per hop

37. What is the difference between codegraph_context and codegraph_explore?

codegraph_context is the map; codegraph_explore is the reading. Context composes search, node, callers and callees to show where a task lives and which symbols matter. Explore then returns the actual source for several related symbols, grouped by file, with a relationship map.

codegraph_context codegraph_explore
Goal Find the area for a task Read several related symbols
Returns Entry points, related symbols, snippets Source grouped by file plus relationship map
Budget --max-nodes on the CLI Budget-capped per call
Typical order First After context

In practice you rarely need both for a small question. For "where is X defined and who calls it?", context alone may be enough. For "how does the request flow work?", follow context with one explore (or a trace) so the agent actually sees the code on the path.

Take quiz
Which tool is normally called first?
codegraph_context
codegraph_explore
codegraph_status
What does explore add that context does not emphasise?
index health statistics
full source of several symbols grouped by file
affected test files

38. Why does CodeGraph tell agents not to delegate exploration to sub-agents?

Because CodeGraph only pays off when it's queried directly. If the main agent hands exploration to a file-reading sub-agent, that sub-agent reads files regardless, and CodeGraph becomes overhead instead of a saving.

The injected instructions therefore say: answer "how does X work?", architecture and trace questions in a handful of CodeGraph calls, treat the returned source as already read, and reach for raw Read or Grep only to confirm a detail the graph didn't cover.

This is a prompting rule, not a technical block. It exists because the benchmarks showed that the savings come from skipping the grep-and-read loop entirely.

Take quiz
What happens if exploration is delegated to a file-reading sub-agent?
CodeGraph indexes the sub-agent's files twice
the MCP server refuses the connection
the sub-agent reads files anyway, so CodeGraph is wasted overhead
When should an agent still use raw Read or Grep?
to confirm a specific detail the graph didn't cover
before every CodeGraph call
for every file the graph returns

39. How does CodeGraph bridge Swift and Objective-C calls?

Tree-sitter stops at each language boundary, so CodeGraph adds synthetic edges using the @objc auto-bridging rules. That lets trace, callers, callees and impact run end to end across Swift and Objective-C.

  • Swift to ObjC: a Swift call obj.foo(bar:) is matched to the selector -fooWithBar:, including init, property and protocol forms and Cocoa preposition prefixes (With, For, By, In, On, At).
  • ObjC to Swift: [obj fooWithBar:] is matched to @objc func foo(bar:) using reverse-bridge name candidates, and CodeGraph verifies the @objc exposure in source.

Edges created this way carry provenance: 'heuristic' and synthesizedBy: 'swift-objc-bridge'.

Take quiz
A Swift call obj.foo(bar:) is matched to which Objective-C selector?
-foo_bar:
-fooWithBar:
-barFoo:
What does CodeGraph verify when going from ObjC to Swift?
that the Swift file compiles
that the selector has no arguments
that the Swift method is exposed with @objc

It parses the native-side declarations to build a map from JS names to native methods, then adds cross-language edges so queries connect end to end.

Bridge JS side Native side
Legacy bridge NativeModules.X.fn() ObjC RCT_EXPORT_METHOD / RCT_REMAP_METHOD, Java/Kotlin @ReactMethod
TurboModules import M from './NativeM' Native impl matching the Codegen spec (the Native<X>.ts interface is ground truth)
Native to JS events NativeEventEmitter.addListener('e') sendEventWithName:, sendEvent(withName:), .emit('e')
Expo Modules requireNativeModule('X') Swift/Kotlin Module { Name("X") ... }

Events are linked through a synthesised channel keyed by the literal event name. Fabric and Paper view components are handled by matching the JSX tag to a spec and a native class by naming convention.

41. What does provenance heuristic mean on CodeGraph edges?

It marks an edge as inferred by a bridge rule rather than read directly from syntax. Cross-language bridges (Swift/ObjC, React Native, Expo, Fabric) emit edges tagged provenance: 'heuristic'.

Each of these also carries metadata.synthesizedBy with a stable channel name, such as swift-objc-bridge, rn-event-channel, fabric-native-impl or expo-module-extract.

The point is transparency: an agent looking at a trace can tell at a glance how each hop got into the graph and weigh it accordingly, rather than trusting every edge equally.

Contrast this with edges read straight from the AST, such as an ordinary call resolved by name. Those are structural facts; heuristic edges are informed matches built from conventions like selector naming or literal event names, and the README says each bridge was validated on small, medium and large real codebases.

Take quiz
What does synthesizedBy record?
which user created the edge
which commit last changed it
which bridge rule produced the edge
Which tag value signals an edge inferred by a bridge?
provenance: 'heuristic'
provenance: 'verified-by-compiler'
provenance: 'cached'

42. How do you tune or disable CodeGraph's file watcher?

Two environment variables control it. CODEGRAPH_WATCH_DEBOUNCE_MS sets the quiet window before a sync; the default is 2000 ms and the value is clamped to 100 ms to 60 s. CODEGRAPH_NO_DAEMON=1 turns the watcher off.

# faster sync after edits
export CODEGRAPH_WATCH_DEBOUNCE_MS=500

# sandboxed environment, watcher disabled
export CODEGRAPH_NO_DAEMON=1
codegraph sync

A shorter debounce makes the graph catch up sooner but may trigger more frequent syncs during bursts of edits. With the watcher disabled you must run codegraph sync yourself.

Raise the debounce if your editor or formatter rewrites many files on save; lower it if you want the agent to see edits almost immediately. The staleness banner still protects the agent during the window, so a longer debounce costs freshness, not correctness.

Take quiz
Setting CODEGRAPH_WATCH_DEBOUNCE_MS to 5 would result in:
an immediate error at startup
a value clamped up to 100 ms
a 5 second window
Which variable disables the watcher?
CODEGRAPH_WATCH=off
CODEGRAPH_DEBOUNCE_MS=0
CODEGRAPH_NO_DAEMON=1

43. How do you use codegraph affected in a CI pipeline?

Pipe the changed files into codegraph affected --stdin --quiet to get just the test file paths, then run only those tests.

#!/usr/bin/env bash
AFFECTED=$(git diff --name-only HEAD | codegraph affected --stdin --quiet)
if [ -n "$AFFECTED" ]; then
  npx vitest run $AFFECTED
fi

--quiet outputs paths only, which is what a shell loop wants. Use --filter to point at a custom test pattern such as "e2e/*", and --depth to limit how far import chains are followed (default 5).

The check needs an initialised index in the CI workspace.

Build or restore the index as part of the job, since a cold checkout has no .codegraph/. When nothing is affected, the empty-string check skips the test run entirely, which is where the CI time is saved. Because the result is import-based, keep a full test run on your main branch to catch gaps.

Take quiz
Which flag makes affected print only file paths?
--quiet
--paths-only
--plain
Which flag points affected at a custom test glob?
--match-tests
--filter
--glob-tests

44. How do you troubleshoot 'database is locked' errors in CodeGraph?

Current builds shouldn't produce them, so start by finding out why yours does.

  1. Check your version. Pre-0.9 installs lack the bundled runtime. Reinstall with the install script or npm i -g @colbymchenry/codegraph@latest.
  2. Run codegraph status and read the Journal: line. If it isn't wal, WAL couldn't be enabled on that filesystem.
  3. Move the project to a local disk. Network shares and WSL2 /mnt are the usual culprits, because there reads can block on writes.

Current builds use Node's built-in node:sqlite in WAL mode, where concurrent reads never block on a writer.

If you're still stuck after those three steps, note whether the error appears only when several agents or terminals touch the same project at once, and include your codegraph status output when you report it.

Take quiz
Which journal mode is expected in a healthy install?
delete
memory
wal
Which location commonly prevents WAL from being enabled?
a network share or WSL2 /mnt
a project inside /tmp on Linux
a path containing spaces

45. How do you troubleshoot missing symbols in CodeGraph?

Work from the cheapest check to the most specific.

  1. Wait a couple of seconds. The MCP server auto-syncs on save after the debounce window.
  2. Run codegraph sync and then codegraph status to confirm nothing is pending.
  3. Check the language. Is the file extension supported (and Objective-C .mm only partially)?
  4. Check exclusions. Is the file under node_modules, dist or another default-excluded folder, matched by .gitignore, or larger than 1 MB?

If a file is excluded by default but you do need it, add a .gitignore negation such as !vendor/ to bring it back.

One last diagnostic: run codegraph query <name> from the terminal. If the CLI finds the symbol but your agent doesn't, the problem is on the agent or MCP side rather than in the index.

Take quiz
A symbol lives in a 3 MB generated file. Why might it be missing?
generated files are always encrypted
files over 1 MB are skipped
only the first 100 files are indexed
What is the first, cheapest step when a recent edit isn't visible?
delete .codegraph and reinstall
switch to a different agent
wait for the debounced auto-sync, then run sync

46. How do you troubleshoot CodeGraph's MCP server not connecting?

Check from the bottom up: the project, the config, then the process.

  1. Confirm the project is initialised and indexed. The error "CodeGraph not initialized" means you need codegraph init first.
  2. Verify the path in your MCP config points at a codegraph binary that is on the PATH.
  3. Run codegraph serve --mcp by hand in a terminal. If it fails there, the agent won't fare better.
  4. Compare configs. codegraph install --print-config <id> prints the expected snippet without writing files.
  5. Restart the agent so it reloads the MCP server list.

If the server runs fine by hand but the agent still can't see it, check whether you chose a global or project-local install (--location) and that you're editing the config your agent actually reads.

Take quiz
Which command prints the expected MCP snippet without writing files?
codegraph install --print-config <id>
codegraph serve --dump
codegraph status --config
What does 'CodeGraph not initialized' tell you?
upgrade Node.js
run codegraph init in the project
clear the npm cache

47. How can you optimize CodeGraph indexing on a large repository?

Most of the speed comes from indexing less noise and syncing incrementally.

  • Make sure big directories are excluded. node_modules, dist, build and similar are skipped by default, and your .gitignore adds to that.
  • Ignore generated code. Anything larger than 1 MB is skipped automatically; add other generated paths to .gitignore.
  • Use --quiet on codegraph index to reduce output overhead.
  • Prefer sync over a full re-index. Reserve codegraph index --force for a clean rebuild, since the watcher and sync only touch changed files.

The troubleshooting guide's first suggestion for slow indexing is exactly this: check that node_modules and other large directories are excluded.

Take quiz
Which approach avoids re-parsing the entire repo after small edits?
codegraph index --force every time
deleting .codegraph before each session
incremental sync via the watcher or codegraph sync
What does --quiet change on codegraph index?
it reduces output overhead
it skips test files
it indexes only one language

48. How do you pull a default-excluded directory like vendor into the graph?

Add a negation to your .gitignore: !vendor/. That's the explicit opt-in.

# .gitignore
!vendor/

The defaults apply uniformly, so simply committing a dependency or build directory doesn't force it into the graph. You have to say so. Then run codegraph sync (or wait for auto-sync) and the folder's symbols appear.

Be aware that vendored code can be large and noisy, so only do this when you genuinely need to trace into the dependency.

Afterwards, confirm with codegraph query on a symbol you know lives in that folder. Remember that the 1 MB per-file limit still applies to vendored files.

Take quiz
What is the explicit opt-in to index a default-excluded folder?
a --include flag on init
a .gitignore negation such as !vendor/
renaming the folder
Does committing a vendor directory force it into the graph?
yes, committed files are always indexed
yes, but only for Go projects
no, defaults apply uniformly

49. Which is better for a small repo: CodeGraph or plain grep, and why?

For a very small repo the margin narrows, but CodeGraph still comes out ahead on call count in the project's numbers. On Gin (~110 files) CodeGraph was 21% cheaper and used 40% fewer tool calls, versus 82% cheaper on Tokio.

The README's own explanation: on a small repo native search is already cheap, so there is less discovery cost to remove. You also pay a setup cost (install, codegraph init -i) and carry a .codegraph/ index.

Rule of thumb: skip it for a handful of files you already know, adopt it as repos grow, or when agents keep fanning out into dozens of grep and read calls. These figures come from the project's benchmark, so measure on your own code.

Take quiz
What did CodeGraph's benchmark show on the small Gin repo?
smaller savings, since native search is already cheap
no benefit whatsoever
larger savings than on Tokio
Which cost does CodeGraph add on a small repo?
a mandatory cloud subscription
setup and keeping a .codegraph index
rewriting the project's build files

50. What happens when an agent starts in a project without a.codegraph directory?

The CodeGraph tools have nothing to query, so the agent falls back on grep, glob and Read. The installed instructions anticipate this: at the start of a session, Claude is told to ask whether you'd like to initialize CodeGraph.

The suggested prompt is along the lines of "I notice this project doesn't have CodeGraph initialized. Would you like me to run codegraph init -i to build a code knowledge graph?"

If a tool is called anyway, you'll see "CodeGraph not initialized", and the fix is to run codegraph init in the project directory. The global install and MCP registration don't create any per-project index.

Take quiz
What does the agent guidance say to do when .codegraph/ is missing?
re-run codegraph install for all agents
refuse to answer code questions
ask whether to run codegraph init -i
Does a global install index every project automatically?
no, each project needs its own init
yes, on first agent launch
yes, only for TypeScript projects
«
»

Comments & Discussions