basemind-code-search — navigate code without reading it
basemind pre-indexes the repo into a tree-sitter code map across 300+ languages. The code map
(outline, symbols, refs) covers code only. code_grep also finds exact text in markdown,
config and data files (Markdown, JSON, YAML, TOML, XML, CSV, INI). docs_search is for searching
by meaning, and for PDFs, Office files, HTML and email (see basemind-documents). find_files
lists the indexed files and the other files git tracks, not an untracked file the index leaves out.
Structural questions (where a symbol lives, what calls it, what shape a file has) resolve from the index in milliseconds and return paths, 1-based line numbers, and signatures, not file bodies.
The tools are always loaded: call them directly. Drop to raw shell only when no tool covers the question.
The discipline
code_outlinebefore you open a file. A 1000-line file becomes a 30-line outline. Thencode_readthe one symbol or line span you need, not the file.code_symbolsinstead ofgrepfor a definition. It matches indexed symbol names and skips the comment, string and test-name noise.code_refsinstead of grepping call sites. Indexed call edges, not text matches.code_grepinstead of shelling out to ripgrep. It sweeps every indexed code, markdown, config and data file (a trigram filter skips code files that cannot match) and returns each hit's line and enclosing symbol. A file created since the last scan is not in it until the watcher or anindex_rescan {"paths":[…]}indexes it, so a miss there is not proof of absence.- Do not re-read a mapped file once the outline answered the question.
- The index follows your edits while a server, daemon or
basemind watchruns: no rescan and no server reconnect after each one. If a result saysstaleor a new file is missing, runindex_rescan {"paths":["src/store.rs"]}for that file; runindex_rescan {}only whenindex_statusreports an empty index,degradedorrescan_needed. Files underscan.extra_rootsare not watched andpathsskips them: refresh a changed one with a full pass (index_rescan {}, orbasemind scanwith no server). With only a standalonebasemind watchthere is noindex_rescanandbasemind rescanexits 3 on its lock: stop the watcher, rescan, restart it. - CLI only, with nothing watching: the index does not follow edits and shows no
staleflag. Runbasemind rescan <path>…for the files you edited before querying them.
Tool routing
| Question | MCP call | CLI |
|---|---|---|
| "What's the shape of file F?" | code_outline {"path":"src/store.rs"} |
basemind code outline src/store.rs |
| "Where is X defined?" | code_symbols {"name":"parse_config","kind":"function"} |
basemind code symbols parse_config --kind function |
| "Show one symbol's body" | code_read {"path":"src/store.rs","symbol":"open"} |
basemind code read src/store.rs --symbol open |
| "Show these lines" | code_read {"path":"src/store.rs","line":120,"end_line":160} |
basemind code read src/store.rs --line 120 --end-line 160 |
| "Where does this text appear?" | code_grep {"pattern":"cache_root(","path":"src/"} |
basemind code grep 'cache_root(' --path src/ |
| "Regex over code?" | code_grep {"pattern":"fn \\w+_call","regex":true} |
basemind code grep 'fn \w+_call' --regex |
| "Find code by meaning?" | code_search {"query":"retry a failed upload with backoff"} |
basemind code search "retry a failed upload with backoff" |
| "What calls X?" (any definition of the name) | code_refs {"name":"open_store"} |
basemind code refs open_store |
| "What calls anything named like X?" | code_refs {"name":"open_","match":"substring"} |
basemind code refs open_ --match substring |
| "What calls this specific definition?" | code_refs {"name":"open_store","path":"src/store.rs"} |
basemind code callers src/store.rs open_store |
| "What implements / extends / inherits X?" | code_refs {"name":"Drawable","relation":"implementations"} |
basemind code implementations Drawable |
| "What imports module M?" | code_refs {"name":"tokio::sync","relation":"importers"} |
basemind code dependents tokio::sync |
| "Which definition does this reference bind to?" | code_refs {"name":"open_store","relation":"definition","path":"src/main.rs","line":42} |
basemind code definition src/main.rs 42 open_store |
| "Which file is named like X?" | find_files {"query":"readme"} |
basemind code find readme |
| "What files are indexed under a directory?" | find_files {"path":"src/mcp/"} |
basemind code files --path src/mcp/ |
| "A result says stale, or a new file is missing?" | index_rescan {"paths":["src/store.rs"]} |
basemind rescan src/store.rs |
Notes
- An argument a tool does not take is rejected with a did-you-mean and the accepted list. A fixable
failure is a tool result with
isErrornaming the fix:docs_searchfor a document path,index_rescanfor a file that is not indexed,find_filesfor a missing one. pathis repo-relative;line,end_lineandcolumnare 1-based.code_readtakessymbol(addkindwhen several share the name) orlinewithend_line, not both. Acode_readbody over 128 KiB is cut at a line end and flaggedtruncated(omitted_bytesis what was left out): read on fromend_line + 1.stale: true(also oncode_outline) means the file changed since it was indexed and was read as it is now; a deleted file is an error namingindex_rescan.code_grep:patternis literal text unless"regex":true, and a regex anchors^/$at every line.pathis a substring of the repo-relative path, never a glob; apathorlanguagethat no indexed code or text file has is an error (it namesdocs_searchwhen only PDFs, Office files or other binary documents match).skipped_filescounts files that could not be searched;skipped_reasonssplits them intounavailable,too_largeandunreadable. The answer iskey: valuelines, then each file as# <path>and each innermost enclosing symbol as## <symbol>over its rows<line>: <text>(rows before any symbol header are outside every symbol); matches sharing a line are one row<line>:<col>,<col>: <text>, and a clipped line (over 400 bytes) writes its column<line>:<col>: ...."context":N(0-10) adds the N lines around each hit as rows<line>- <text>.stalelists files edited since they were indexed.totalappears only besidenext_cursor.find_fileslists each file by its path alone: the code map, the documents, and every other file git tracks (images, fonts, data). A query no path holds as typed may be a typo: a file it names up to one swapped, missing, extra or wrong character comes first.code_symbolsranks the exact name first, then prefix, then substring;"fuzzy":trueadds fuzzy subsequence matches last. A row is"<path>:<line>: <signature>", in rank order; a signature lacking the name, or none, is written"<path>:<line>: <kind> <name>[; <signature>]".stalelists files edited since the scan;totalappears only besidenext_cursor.code_refs {"name":"bar"}matches the identifier exactly:Foo::bar()andbar()are calls tobar,bar_baz()is not."match":"substring"widens it.hitslists each file once, as{"<path>": [hit, ...]}; a call site is itsline(andcolumnwhen another call of the same callee is on that line), pluscalleewhen that is notname, and an implementation is itslineandimpl_type. Each call site is graded byresolution(see Resolution below). Apaththat is not indexed, or defines no such symbol, is an error; so is a name several definitions in the file share, which lists each with its lines until you addline.relation:"importers"matches whole segments of recorded imports (osfindsimport os.path, notimport posixpath) and takes nomatch. Withpath,in_cyclecounts the listed importers that share an import cycle with the file, and onlyscan_captruncates (a walk stopped atdepthdoes not);deeper: truesays more importers lie pastdepth(default 1, at most 5).totalappears only besidenext_cursor.code_searchreturns pointers (path,line/end_line, symbol), not bodies; read a hit withcode_read.lanepickshybrid(default),semanticorkeyword. The response listslanes_ranandlanes_unavailable(lane,reason), so a hybrid search that ran without embeddings says so. It needs thecode-searchCargo feature.- Needs an index in the machine-global cache (Linux
~/.local/share/basemind/, macOS~/Library/Application Support/basemind/; overrideBASEMIND_DATA_HOME). Runbasemind scanfirst (see thebasemind-scanskill).
Resolution
code_refs finds call sites by name, then grades each one by what it is known to bind to. The
grade refines a result set; it never shrinks it. A call without resolution lists every call site
whose callee is the name, graded, so total stays a sound count of candidates.
Each call site carries resolution, one of:
| Value | Meaning |
|---|---|
same_file |
Binds to a definition in the same file. |
imported |
Binds through an import to a definition in another file. |
scope_resolved |
Binds to a local binding that is not an indexed definition: a variable, a parameter, or an import whose target is not indexed. |
elsewhere |
Checked against the definition pinned with path, and binds to another one. |
name_only |
No resolution facts for the site: matched by name alone. |
external |
No resolution facts, and the index defines no symbol of the name. |
path_match |
An HTTP call linked to a route by its method and normalized path. |
A page names its most common grade once as resolution_default, and a row leaves its own out when
it is that one; a page with no resolution_default is all name_only. resolution_counts gives
the rows per grade, before any filter.
- Callers of one definition. Add
path(andlinewhen several definitions in the file share the name): the answer carries thatdefinition, andresolved_totalcounts the hits proven to bind to it. When resolution could not run,resolved_totalis absent andresolution_notesays why:unsupported for <language>,no resolution facts for this file, orno resolution facts for this definition. - Precision on request.
resolutionfilters rows by grade, comma-separated:{"name":"open","resolution":"same_file,imported"}(CLI:--resolution same_file,imported). - Why the default keeps unresolved rows. Resolution cannot see through a module-object import
(
from pkg import mod, thenmod.f()) or an unresolvable path alias. Dropping those rows would lose real callers and report the rest as complete. Filter when you want precision; trusttotalwhen you need completeness. - Coverage. JavaScript and TypeScript (oxc), Python and Java (stack-graphs rules) resolve across files through imports; every other language gets tree-sitter scope binding.
- JS/TS workspaces. A bare import of a workspace package (
@acme/ui,@acme/ui/button) resolves to its source with nonode_modules. Packages come from the rootpnpm-workspace.yamlpackages:globs and the rootpackage.jsonworkspacesfield, each match with a namedpackage.json. A symlink into the repository resolves to its real path, and a literalrequire('./x')is a file edge. - From a reference to its definition.
relation: "definition"returns the definition the reference atpath/linebinds to, or aresolution_notewhen there is none. - HTTP routes. A route is a
routesymbol namedMETHOD /path, parameters written:param; a call with a literal URL is a call site of the same shape. The callers of a route (its name, orpathpinning it) are the calls it matches best, gradedpath_match: the methods agree (a route ofANYtakes every method) and the paths match segment for segment, else one is a suffix of the other (a client base URL, or a router mounted in another file). A match through a literal segment beats one through parameters and wildcards alone (a catch-all such asGET /*never takes a call from the route naming its path), an exact match a suffix, a longer suffix a shorter one, and a literal segment a parameter. A call that several routes match equally well carriesambiguous: two services may expose the path. The callers of a handler (pathpinning it) add the routes naming it and their calls,ambiguousfor a route in another file when more than one file defines the name.relation: "definition"on a call returns its route withresolution: "path_match", or the tied routes underambiguousand nodefinition. URLs built from variables are out of reach.
Paging and budgets
Every list takes limit and cursor and returns next_cursor while more remains. Pass
next_cursor back as cursor (CLI: --cursor) with the same arguments; only limit and
max_tokens may change between pages.
- Defaults.
code_symbols,code_grepandcode_refslist 100 rows,find_files200,code_outline500 symbols,code_searchanddocs_search10 hits,git_log20 commits (at most 100),git_blame100 hunks.limit: 0is refused. - Token budget. A list is trimmed to
max_tokens(default 6000), then setsbudgeted: raisemax_tokensor follownext_cursor. A first result overmax_tokensis still returned, andbudgetedstays unset when nothing was cut. - Three words for a cut. A page ended at
limitalone returns onlynext_cursor;budgetedmeans the token budget trimmed it;truncatedwithtruncated_reasonmarks a cut you did not ask for (omittedcounts what was left out; reasons below). They can co-occur: a firstcode_outlinepage that stops atlimiton a file with over 200 imports returnsnext_cursorandtruncated_reason: "imports", so check each one. - Limit cap.
git_logsilently capslimitat 100.code_outline,code_symbols,code_grep,code_refs(paginated relations;definitiontakes nolimit),find_filesand amemory_searchlisting cap at 1000 rows (find_files5000) and setlimit_clamped: true. Ask at or below the maximum and follownext_cursor. - Cursors are bound to their query. A cursor continues only the call that returned it: never
reuse one across queries (
code_symbolscannot detect it and skips results).code_symbols,code_grepandfind_filescursors are keyed to the index generation (a rescan or index change moves it, a HEAD move alone does not);git_logcursors to HEAD. On a mismatch the tool returns an error or an empty page withcursor_invalidated: true: repeat withoutcursor. - Notices. An empty or partial answer with a
notice(empty_index,warming_up,building_index,rescanning) means retry shortly, not "no matches". - Text answers (ADR-0053).
code_grepwrites other fields askey: valuelines, then each file as# <path>and each enclosing symbol as## <symbol>over its rows; rows before a symbol header or under a bare##are outside every symbol.code_outline,git_diffand afind_fileslist are TOON:key: valuelines, and a list of objects as one table,symbols[N]{name,kind,...}:plus a comma-separated row per object. Every other tool answers in compact JSON. MCPstructuredContentis always JSON. - CLI output. Human output prints bodies and diffs in full and cuts only table cells.
--jsonprints the MCPstructuredContentJSON.
Truncation reasons
truncated_reason says why an answer is incomplete.
scan_cap,code_symbols,code_refs,memory_search,impact:totalis a lower bound: follownext_cursor, else narrow withpathorlanguage.byte_budget,code_grep: Follownext_cursor, or narrow withpathorlanguage.time_budget,code_grep: Sweep stopped at 10 s (seenotice): follownext_cursor, or narrow.depth,code_search,docs_search,impact: Past 100 hits, or an import walk at its depth: refine the query.liveness_depth,docs_search: Narrow withpath,keywordsorformat.stale_chunks,code_search: Hits in files edited since indexing were dropped (omitted):index_rescanthem.imports,code_outline: Import list cut at 200:code_grepfor the import.size_cap,code_read: read a span withlineandend_line.too_large,git_blame: Blame a span or onesymbol.hunk_cap,byte_cap,git_diff: stopped at 200 hunks or 128 KiB, no cursor: narrowfrom/to.path_cap,git_diff: Status list cut (omitted): pass a directorypathending in/.span_limit,git_log: Follownext_cursor, an empty page included, until it is absent.unindexed_scan,git_log: No history index, newest commits only: wait for it (index_status), repeat.commit_cap,basemind git hotspots: The window holds more commits than the walk reads: narrowsince.shallow_clone,git_log,git_blame: An absent commit is inconclusive:git fetch --unshallow.
For git history, blame and diffs see basemind-git-history; for document search see
basemind-documents; for agent coordination see basemind-comms.
