cartotree is a local code indexing tool designed to help coding agents locate relevant files faster and reduce the overhead of repeated grep and reading entire files. It offers two usage modes: a command-line interface (CLI) and an MCP server, and it does not depend on an LLM or make network requests.
Purpose
When a user asks the agent a question (for example, "Why does this bug happen?"), the agent usually needs to run grep multiple times and read many files before finding the relevant location. cartotree maintains a local repository index and directly answers the question "Which files should I open first?", returning a list of files ranked by relevance, along with matching lines as evidence.
Main capabilities
File location and ranking
cartotree uses the BM25F algorithm to score four fields of each source file: words in the path, export names, code identifiers (scored per function to avoid long files diluting the influence of a single matching function), and commit messages that previously modified the file. It also includes lightweight stemming, import-neighbor weighting, 1–2 lines of evidence per result, a warning when top results are close, and "usually changed together" hints based on git co-change history.
Three core commands
cartotree_locate: returns a ranked list of files with evidence lines.cartotree_peek: previews file contents.cartotree_links: views file relationships.
These commands can be exposed to MCP-capable agents through the MCP server (npx cartotree mcp). After the first call, the index is kept in memory, and each query takes about 10 milliseconds. The disk cache is located in the .cartotree/ directory, keyed by git HEAD and uncommitted changes.
Annotated directory tree
The original cartotree command can generate a compact, annotated map of the codebase that is easy to paste into any AI chat. It supports three output formats: the default annotated ASCII tree, the--ai token-optimized serialization format, and the--json JSON format.
Persistent defaults can be set via the .cartotreerc file in the project root; for example, after setting it, npx cartotree automatically uses --ai --no-exports.
Folder annotations and ignore rules
A .folder.md file can be added to any directory, and its first line serves as the annotation for that directory; if there is no .folder.md, it falls back to the first line of README.md . Ignore rules can be customized via the .cartotreeignore file, and by default node_modules、.git、dist、buildare excluded.
Sync integration
Running cartotree --sync injects the directory tree between marker tags, which is suitable for CLAUDE.md、AGENTS.md、.cursorrules or any file.
Export symbol display
cartotree reads source files and displays exported symbols directly in the directory tree, supporting .js、.ts、.jsx、.tsx、.mjs、.cjs.
Usage
It can be run directly via npx without installation. Use it as a Claude Code plugin, or via npx cartotree mcp Start the MCP server. Specific installation commands and configuration steps are not yet provided.
Use Cases
Suitable for developers using programming agents that support MCP, such as Claude Code, Cursor, and Codex, who want to reduce grep calls and token consumption when agents locate code while maintaining answer accuracy. Also suitable for scenarios where the codebase structure needs to be provided to AI chat in a compact format.
Limitations
cartotree does not include an LLM and does not make network requests. According to official documentation, its accuracy in testing is comparable to grep (within ±1.5 questions), with its main advantages being cost and speed. Testing was based on deepseek-harness (21,632 files) and the Claude Haiku agent; specific test details and complete data are not yet provided.