CodeNavi: API Reference¶
All tools are accessed via the Model Context Protocol (MCP). Connect to http://localhost:8765/mcp using any MCP-compatible client.
Tools are called as MCP tools/call requests. Parameters are passed as JSON objects. All tools return plain text (formatted for LLM consumption, not raw JSON).
43 tools total: 35 core tools + 8 crawler tools (when CRAWLER_ENABLED=true). The machine-readable catalog, grouped by skill, with connection details and usage rules, is the agent card at GET /.well-known/agent-card.json.
Tool profiles:7 by default (CODENAVI_TOOL_PROFILE=focused, since 1.3.73) tools/list advertises semantic_search, find_callers, impact_analysis, diff_impact, codebase_overview, list_codebases, the index-ops tools (reindex_incremental, reindex_status, index_stats), the approval-gated tools and reveal_tools(); CodeNavi's grep/read/browse tools run on demand, since an agent's own grep and file reads do the same job (config.md). With CODENAVI_TOOL_PROFILE=protected (the older lean, the default from 1.3.23 to 1.3.72) tools/list advertises an 11-tool core, the search/browse/read loop (semantic_search, file_search, grep_search, symbol_search, list_directory, read_file, codebase_overview, list_codebases) plus the everyday index-ops tools (reindex_incremental, reindex_status, index_stats), and a reveal_tools() meta-tool, shrinking the per-conversation schema by about 55% (measured 2026-11-13: 44.2k → 20.4k compact chars, 35 → 18 tools; with the crawler 48.4k → 21.3k, 43 → 20 tools). Set CODENAVI_TOOL_PROFILE=full to advertise every tool below up front (the pre-1.3.23 default). Nothing is lost: call reveal_tools() for a grouped catalog of the hidden tools, reveal_tools(group="relations") or reveal_tools(names="find_callers,diff_impact") for their descriptions and arguments, and reveal_tools(call="find_callers", args='{"symbol": "handle_login"}') to run one and get its result in the same call (since 1.3.30).20 Hidden tools stay out of tools/list: since 1.3.71 a reveal no longer adds them, because the server is stateless and the tool list is shared, so one agent's reveal used to grow every connected agent's list until restart (CN-1061). A client that wants a hidden tool in its own list names it in X-CodeNavi-Tools (below). reveal_tools(call=…) refuses the destructive or outbound tools (reindex_full, cancel_reindex, reindex_docs, backup, restore, delete_note; crawl, cancel_crawl with the crawler), so the client's per-tool approval applies to each and an approval of reveal_tools never covers them (since 1.3.61, CN-913). reindex_full, cancel_reindex, crawl and cancel_crawl are always in tools/list: call them directly. Since 1.3.73 backup, restore, reindex_docs and delete_note are not listed (CN-1091): run backup and restore from the web UI, or name them in X-CodeNavi-Tools.
Read-only and per-connection narrowing: CODENAVI_MCP_READ_ONLY=true removes the state-changing tools (reindex, notes writes, feedback, backup/restore, crawl) from the MCP surface. A client can narrow its own connection with X-CodeNavi-Read-Only: true or X-CodeNavi-Tools: name,name. X-CodeNavi-Tools keeps only the tools it names and, since 1.3.71, also lists any of them the profile hides; neither header reaches a tool the server removed. A refused call returns an isError result naming the header. Details: Configuration.
Tool annotations: every tool in tools/list carries the MCP annotations hints. The state-changing tools listed above have readOnlyHint: false; every other tool has readOnlyHint: true. destructiveHint: true marks reindex_full, restore, delete_note and cancel_reindex. idempotentHint: false marks the writes a client must not repeat on its own: save_note, submit_feedback, backup, crawl, reindex_full, restore. openWorldHint: true marks crawl only. reveal_tools counts as a write, because call= can run a hidden write tool such as save_note; with CODENAVI_MCP_READ_ONLY=true it is read-only. Clients use the hints differently: Claude Code runs read-only calls in parallel, and Codex asks before every destructive one.
Search Tools¶
semantic_search¶
Search across code, documentation, and crawled web pages by meaning. Queries all three LanceDB tables in parallel, merges results, and reranks with a cross-encoder.
Works with natural language ("how does the login flow work?"), function names ("verifyCredentials"), or mixed queries ("PayPal payment error handling").
Zero-result responses carry a coverage note13 when the queried codebase has materially unindexed file types, e.g. note: some files in this codebase are not indexed — 301 .tmpl files … were skipped at index time: in the text envelope and as coverage_note in the structured payload, so an empty answer is distinguishable from an unindexed corpus.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
query |
string |
(required) | The search query, natural language or code identifiers |
limit |
integer |
10 |
Maximum results to return. Use 5 for focused queries, 8-10 for broad exploration. |
source_filter |
string |
"" |
Filter by file path prefix. Example: "public_html/site/" |
language_filter |
string |
"" |
Filter by programming language: php, js, ts, py, go, java, ruby, rust, csharp, fortran, sql, smarty, kotlin, etc. |
source_type_filter |
string |
"" |
Filter by source: "code" (code only), "doc" (docs only), "web" (web only), or "" (all three) |
max_chars |
integer |
0 |
Per-query response budget in characters. 0 = use server default (15,000). Lower values save context window. A tight budget shortens code first: the top hit's code is cut to fit, later hits return metadata only (file, lines, symbol, score) without code, and a hit that would not fit even as metadata is listed by path and lines in an <omitted> block and counted in <chunks_omitted>. No hit's path is dropped. The top hit always carries at least 200 characters of code, so a budget smaller than one entry is exceeded by that entry and the <omitted> list. |
codebase |
string |
"" |
Name of a specific codebase to search, or "" for the server's default_codebase (every codebase when that is unset). Use list_codebases to see available names. |
output |
string |
"full" |
"full": code included, as below. "locations": each hit's path, lines, symbol, score and first line (summary), no code and no chunk_id, about a tenth of the size; same hits in the same order. max_chars does not apply to it.25 |
Returns: XML-formatted results.
The response opens with a <budget> envelope giving the caller a read on
response shape:
<budget>
<chars_used>5521</chars_used>
<chars_budget>15000</chars_budget>
<chunks_truncated>0</chunks_truncated>
<chunks_omitted>0</chunks_omitted>
<chunks_returned>5</chunks_returned>
<diagnostic>concentrated</diagnostic> <!-- conditional, see below -->
</budget>
<chars_used>/<chars_budget>: actual vs allowed response size in characters. Agents can widenmax_charsif they need more.<chunks_truncated>: chunks returned as metadata-only (no<code>block) because the budget was exhausted.<chunks_omitted>: chunks that did not fit even as a metadata-only entry. Their path and lines follow the results in an<omitted>block (in structured output,budget.omitted). They still count in<chunks_returned>; raisemax_charsto see their code.<chunks_returned>: number of semantic chunks (excludes any keyword-fallback stubs appended afterwards).<diagnostic>: optional, may repeat.concentrated: all top-3 results come from the same file (the old score-spread co-condition was dropped10, its scale died with hybrid retrieval), the query was probably too narrow and broadening it may surface adjacent paths.low_signal9: the top hit's rerank logit is below the measured 5th percentile of queries with a ground-truth hit in their window (calibrated across five testbeds, 2026-07-29), likely nothing on-topic; reformulate in the codebase's own vocabulary instead of trusting the window or falling back to grep.<rerank>: optional.10 Emitsskippedwhen a configured reranker returned no scores for this query (load failure or per-query timeout). Result order is then raw vector order and<score>values are retrieval cosine similarities rather than cross-encoder output. Absent when the reranker ran, and whenRERANKER_MODEL=none(an opt-out is not degradation).
After the envelope, each result contains:
<source_file>: relative file path (or URL for web results)<lines>: line range (start-end)<chunk_id>: unique identifier (used for feedback)<source_type>:doc,web,noteorwiki; absent for code25<codebase>: codebase name (only present when the search covered more than one codebase)<code>: the matching snippet<score>: ranking score (0-1): sigmoid of the cross-encoder rerank logit. Relative within one response, not calibrated confidence, the reranker is trained on web prose, so correct code hits routinely score 0.01–0.20. Judge by order and gaps, not absolute level.9<stale>: present only when the chunk's source file has been modified or deleted since indexing; agents should re-verify the snippet viaread_file(or runreindex) before quoting it
Some queries also append keyword-fallback entries below the main results,
files that match alias-expanded keywords but didn't show up via vector
search. These have <match_type>keyword</match_type> and <matched_keywords>
instead of <code>. Doc-flavored files (.md / .rst / .txt) are
suppressed from this fallback unless source_type_filter="doc".
Structured output:11 alongside the XML text, the tool result carries
a structuredContent object validated against the tool's advertised
outputSchema (core MCP protocol, 2025-06-18 spec). The payload is a
self-sufficient mirror of the envelope, clients may feed the model either
channel (Claude Code feeds structuredContent instead of the text when it is
present), so each must stand alone. Hits carry file,
line_start/line_end, chunk_type/chunk_name, score, chunk_id, source_type
(only when not code), truncated (only when true), and the code snippet (absent on budget-truncated
entries, mirroring the text channel; JSON-raw, escape it before inserting
into a DOM), plus optional codebase/flagged/stale and code_truncated
(the snippet was cut at the per-hit cap: the top two hits show up to 4000
characters, the rest 800; read_file the line range for the rest, CN-1101); the top level adds
diagnostics, rerank_skipped, the budget block, index_freshness
(mirroring the <index_freshness> line), and any keyword_fallback entries.
On error/edge paths the payload is
{"ok": false, "error": "<the same message the text carries>", "results": []}.
Six tools emit structured output: semantic_search, find_callers,
impact_analysis, graph_neighborhood, wiki_pages, wiki_page. All other tools deliberately
advertise no outputSchema (registered with structured_output=False):
without it, the SDK auto-derives a {result: string} wrapper and structured-
preferring clients would feed the model an escaped JSON blob instead of the
formatted text. A tool gains a schema only when it gains a real payload.
file_search¶
Find files by name, path, or description.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
query |
string |
(required) | File search query |
limit |
integer |
15 |
Maximum files to return |
source_filter |
string |
"" |
Filter by path prefix |
language_filter |
string |
"" |
Filter by language |
source_type_filter |
string |
"" |
"code", "doc", or "" |
codebase |
string |
"" |
Name of a specific codebase to search, or "" for the server's default_codebase (every codebase when that is unset) |
Returns: File paths with content previews.
read_file¶
Read a file from the codebase by its relative path. Returns the file content with line numbers. Use after semantic_search or file_search to read the full file or a specific section.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
path |
string |
"" |
Relative file path (required, or use file_path) |
file_path |
string |
"" |
Alias for path (matches Claude Code's built-in Read tool) |
start_line |
integer |
0 |
Start reading from this line (1-based) |
end_line |
integer |
0 |
Stop at this line. 0 reads to end of file, capped at DEFAULT_READ_LINES (2000) with a "call again with start_line=…" continuation note |
codebase |
string |
"" |
Which codebase to read from, or "" for the server's default_codebase (the only codebase on a single-codebase install; a multi-codebase server with no default refuses the unscoped call and names the codebases) |
Returns: File content with line numbers, secrets redacted.
When to use: After a search hit, to read the full file or a specific range.
list_directory¶
List files and subdirectories at a path in the codebase. Use to explore project structure before reading specific files.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
path |
string |
"" |
Directory to list ("" = codebase root) |
depth |
integer |
2 |
How many levels deep to show (max 5) |
codebase |
string |
"" |
Which codebase to list, or "" for the server's default_codebase (the only codebase on a single-codebase install; a multi-codebase server with no default refuses the unscoped call and names the codebases) |
Returns: Tree-style directory listing.
codebase_overview¶
Get a structural overview of the indexed codebase. Auto-detects languages, directory structure, file distribution, and symbol counts from the index, works for any codebase without configuration.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
section |
string |
"structure" |
structure (default, every top-level dir with subtree chunk totals + detected entry points, ~1k tokens), all (full overview, ~10k tokens on a large codebase), languages, files, symbols, entrypoints (front controllers, main.* files, script dirs, vhost→docroot pairs mined from indexed nginx/apache configs) |
codebase |
string |
"" |
Name of a specific codebase, or "" for all |
Returns: With the default structure section, top directories by chunk count. Pass section="all" for the full overview (language breakdown, top directories, largest files, function/class counts).
Default changed in v1.2.4 (was
"all"). The full overview burns ~10k tokens on a large codebase; most "what is this codebase?" questions are answered bystructurealone. Passsection="all"explicitly when you want everything.
reindex_incremental¶
Re-encode only files modified since the last index, safe and fast (a few seconds on a small index, longer on a large one). Returns immediately; the work runs in the background. Auto-allowed by the recommended plugin allowlist (no permission prompt).
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
codebase |
string |
"" |
A specific codebase name, all (or *) for every codebase, or "" to use the server's default_codebase setting, which falls back to all when unset6. MCP tools only; the ./codenavi reindex CLI / reindex.sh path keeps ""=all. |
Returns: Confirmation message, or rate-limit notice (minimum 5 minutes between calls).
When to use: When a search response's <index_freshness> envelope flags a stale index (a <recommendation>reindex_incremental</recommendation> appears once it's >1h old), or after editing files you're about to search. Runs in the background: confirm completion with reindex_status. Default for the /codenavi:reindex slash command. On a multi-codebase server, set default_codebase in data/settings.json so a no-arg call reindexes just that codebase rather than rebuilding every codebase's vector index; pass codebase=all to force the full sweep.6
reindex_full¶
Re-encode the entire codebase from scratch (~6-40 min depending on codebase size). Drops and rebuilds all chunks. Returns immediately; the work runs in the background. Always prompts for permission: intentional given the runtime cost and search downtime while vectors rewrite.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
codebase |
string |
"" |
A specific codebase name, all (or *) for every codebase, or "" to use the server's default_codebase setting, which falls back to all when unset6. MCP tools only; the ./codenavi reindex CLI / reindex.sh path keeps ""=all. |
Returns: Confirmation message, or rate-limit notice (minimum 5 minutes between calls).
When to use: Suspected index corruption, embedding model changed, or directories renamed such that incremental tracking is confused. Use reindex_incremental for everyday staleness.
reindex (deprecated)¶
Deprecated alias for reindex_incremental (full=False) and reindex_full (full=True). Prefer the explicit tools: they are clearer in tool-call logs and let plugin allowlists auto-approve the safe incremental path while keeping a permission prompt on the destructive full path.
Kept for backward compatibility with reindex.sh and existing agents; will not be removed without notice.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
full |
boolean |
false |
false = incremental (delegates to reindex_incremental). true = full rebuild (delegates to reindex_full). |
codebase |
string |
"" |
A specific codebase name, all (or *) for every codebase, or "" to use the server's default_codebase setting, which falls back to all when unset6. MCP tools only; the ./codenavi reindex CLI / reindex.sh path keeps ""=all. |
Returns: Confirmation message, or rate-limit notice (minimum 5 minutes between calls).
reindex_status¶
Check the progress of the most recent background reindex.
Parameters:
- codebase (string, optional): report the last finished run of this codebase, and say whether a reindex is running now. Without it, the reply describes the most recent run, whatever its codebase. On a multi-codebase server, pass the codebase you reindexed: a later run of another codebase replaces the no-argument reply.
Returns: Running status, progress, duration, and any errors. The first line names the codebase(s) the run covered. A completed run's summary includes a Skipped: line13 counting every file the scan dropped, by reason. If the previous reindex died without recording an outcome (server restart, OOM-kill), the response says so explicitly, ⚠ … was INTERRUPTED15, instead of implying nothing ran; the notice self-clears when a run completes.
cancel_reindex¶
Cancel a running background reindex. The reindex stops after the current encoding batch completes. The existing index remains unchanged (no partial data). A cancel that arrives during the scan or the structural (call-graph) phase takes effect at the first encoding checkpoint, so on a large first index the stop can take a minute or two, the call-graph sidecar is built before the encode since 1.3.38 (CN-706).
Parameters: None.
Returns: Confirmation with elapsed time, or "No reindex is currently running."
doc_sources¶
List all indexed documentation files with chunk counts.
Parameters: None.
Returns:
Indexed documentation (3 files, 12 chunks):
docs/architecture.pdf: 5 chunks
docs/api-guide.docx: 4 chunks
README.md: 3 chunks
reindex_docs¶
Ingest PDF and DOCX files from DOCS_DIR. Scans for security threats before ingestion. Existing records from DOCS_DIR are replaced (deduplication). .md and .txt files within the codebase are indexed automatically during reindex, this tool is only needed for external PDF/DOCX files. On a multi-codebase server, when DOCS_DIR/<codebase>/ exists it is scanned instead of the flat DOCS_DIR root, so each codebase ingests only its own external docs; the flat layout is a legacy fallback (logged warning).
Parameters: None.
Returns: Summary: chunks ingested, files skipped, errors.
Security checks: Encrypted PDFs, embedded JS (/JS, /JavaScript), auto-execute actions (/OpenAction, /AA), launch commands, embedded files, metadata scanning.
submit_feedback¶
Rate a search result chunk. Down-voted chunks (net rating < -2) are demoted in future searches. Rate-limited to 5 submissions per chunk per 5-minute window to prevent abuse.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
query |
string |
(required) | Original search query |
chunk_id |
string |
(required) | From <chunk_id> in search result |
source_file |
string |
(required) | From <source_file> in search result |
rating |
integer |
(required) | +1 (helpful) or -1 (not helpful) |
comment |
string |
"" |
Optional explanation |
Returns: Confirmation, or rate-limit notice.
feedback_stats¶
On a scoped /mcp/{codebase} endpoint of a multi-codebase server this tool and search_analytics return a 400, because their data covers every codebase. Use /mcp. search_analytics(report=true) holds counts and no names, so it works on any endpoint.
View aggregated feedback: total votes, top/bottom-rated chunks, demotion list, recent comments.
Parameters: None.
index_stats¶
View index statistics: file count, chunk count, breakdown by chunk type, files with the most chunks, plus the skip ledger13: a skipped-by-reason table from the last reindex (per-extension counts, ignore-file attribution, oversize examples, scanner rejects), answering "is a language missing from the breakdown because the repo has none, or because the scan dropped them?" It also shows the source revision of the last index pass and, for a git checkout, warns when the checkout's HEAD has moved past it ("the index is N commit(s) behind"; local only, never fetches).
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
codebase |
string |
"" |
Name of a specific codebase, or "" for all |
search_analytics¶
View query statistics from the search log: most common queries, zero-result queries, alias expansion stats, and retry patterns (same query within 5 minutes).
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
since |
string |
"" |
Only include queries after this date (YYYY-MM-DD). Empty = all time. |
top |
integer |
20 |
Number of entries to show in each category (top queries, zero-result, etc.) |
report |
boolean |
false |
Return the fixed usage report instead: key: value lines with the time, server version, engine, compute, licence, index shape (counts and languages) and the usage numbers of the last 7 days. Counts and fixed labels only: no query text, paths, codebase names, licence holder, IPs or user agents. Ignores since and top. Fields: Usage report. |
Returns: Text report with sections: Top Queries, Zero-Result Queries, Alias Expansions, Retries.
Clearing or scoping the data. Analytics is read from the append-only query log (
~/codenavi/logs/queries.log*), there is no separate reset command. To exclude benchmark/eval traffic, setsince(CLI:--since) to just after your last benchmark run; it filters without deleting. To hard-reset, delete the query log (rm ~/codenavi/logs/queries.log*), see PRIVACY.md → How to delete all data. Ratings work the same way: there is no clear command, remove rows or deletedeploy/data/feedback.db.
symbol_search¶
Search for symbols (functions, classes, methods) by name. Uses FTS lookup: no GPU encoding needed. Fast alternative to semantic_search when you know the symbol name.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
name |
string |
(required) | Symbol name to search for (e.g. "createUser", "UserAuth") |
kind |
string |
"" |
Filter by symbol kind: function, class, method, template, or "" (all) |
language_filter |
string |
"" |
Filter by language: php, js, py, etc. |
source_filter |
string |
"" |
Filter by file path prefix |
limit |
integer |
20 |
Maximum results |
include_source |
boolean |
false |
If true, includes the full source code of each symbol |
codebase |
string |
"" |
Name of a specific codebase to search, or "" for the server's default_codebase (every codebase when that is unset) |
Returns: XML-formatted results:
<symbol>
<name>Auth::verifyCredentials</name>
<kind>function</kind>
<file>public_html/lib/Authorize.php</file>
<lines>16-82</lines>
<language>php</language>
<code>...</code> <!-- only if include_source=true -->
</symbol>
When to use: You know the function or class name and want its definition. Faster than semantic_search for exact name lookups.
find_references¶
Find all references to a symbol name across the indexed codebase. Like grep but uses the search index, returns results grouped by file.
A chunk with a detected secret or PII value is matched on its redacted text, so the answer does not confirm a guess of the value: the names around it are still found, and a line that holds a value is listed as [line not shown: …]. Chunks without a detected value come first. A value the scanner does not detect is not hidden.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
name |
string |
(required) | Symbol name to find references for |
language_filter |
string |
"" |
Filter by language |
source_filter |
string |
"" |
Filter by file path prefix |
limit |
integer |
30 |
Maximum results |
codebase |
string |
"" |
Name of a specific codebase to search, or "" for the server's default_codebase (every codebase when that is unset) |
Returns: References grouped by file:
Found 10 reference(s) to 'authenticate' across 8 file(s) [64ms]
**public_html/lib/Authorize.php**
L16-82 (function: Auth::verifyCredentials)
L90-120 (function: Auth::checkSession)
**public_html/site/members/act_login.php**
L5-45 (file_part: act_login.php:1-45)
When to use: You found a function with symbol_search and want to know where it's called from. Also useful for impact analysis before refactoring.
grep_search¶
Regex-search the indexed source. Faster and cheaper than semantic_search for exact matches, variable names, function calls, config values, error messages, imports, SQL fragments. No GPU cost.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
pattern |
string |
(required) | Regex pattern to match. Accepts query as an alias, matching semantic_search's naming. |
path_filter |
string |
"" |
Only search files whose path starts with this literal prefix, anchored at the codebase root (e.g. public_html/admin/, or a file path like core/graph.py). Not a substring and not a glob, blacklist will not match public_html/site/blacklist/, and *blacklist* is rejected outright. When the prefix excludes every file the response says so and suggests matching directories, rather than reporting a no-match. |
path_exclude |
string \| string[] |
"" |
Skip files under this path prefix, or any of a list of prefixes (e.g. ["tests/", "vendor/"]). Same literal-prefix rules as path_filter. Combine with path_filter to scope tightly. |
language_filter |
string |
"" |
php, js, py, etc. |
case_sensitive |
boolean |
false |
If true, match exact case |
max_results |
integer |
50 |
Max matches to return (hard cap 200) |
context_lines |
integer |
0 |
Include N lines before and after each match (capped at 5). Useful when you'd otherwise follow up with read_file. |
codebase |
string |
"" |
Name of a specific codebase to search, or "" for the server's default_codebase (every codebase when that is unset) |
output |
string |
"matches" |
matches: the matching lines. files: every file with a hit and its match count, sorted by path, listing up to 500 files. count: matches and files per folder, one level under path_filter. files and count search the whole scope with no match cap, and the header gives the complete totals. For audits ("every file that still touches table X"). Since 1.3.78.24 |
Returns: Match list with file paths, line numbers, and matched text. Header reports total matches found (even when capped) so callers know whether to widen or narrow the search.
Detected secrets and PII are replaced with [REDACTED:rule_id] before the pattern is matched, so a value can be neither read nor searched for; an assignment keeps its name (password = "[REDACTED:…]"). A no-match does not prove that a secret value is absent. The operator can turn this off with CODENAVI_GREP_REDACT=false.
Why prefer this over the built-in Grep tool / shell grep:
- CRLF immunity. The CodeNavi index normalizes line endings during ingest. Files with mixed CRLF/LF (common in Windows-origin or long-lived legacy codebases) silently break shell
grep, patterns spanning line ends miss matches because\n≠\r\nin the regex engine.grep_searchoperates on normalized chunks, so mixed-line-ending codebases match identically to clean-LF ones. - No shell overhead. Runs against in-memory chunk text, no
findtraversal, no per-file process spawn. - Same exclusions as the index.
vendor/,node_modules/,__pycache__/, etc. are already excluded; you don't need to remember the per-codebase ignore list.
When to use built-in Grep instead: trivial known-string match in a small directory the user just told you about, or when the file isn't indexed (e.g. recent untracked file).
rule_evidence¶
The complete evidence bundle for ONE compliance rule (CN-936): every line in the codebase matching ANY of the rule's grep patterns — one live walk, no per-match cap — plus the top-10 semantic chunks for its query, grouped by file and tagged with which pattern hit. Built for the bundled compliance-check skill: fetch the bundle, read every file it lists, grade. Two runs see the same evidence, so a verdict no longer depends on which hits an agent chose to open. Hidden under the lean tool profile — call it as reveal_tools(call="rule_evidence", args='{...}').
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
patterns |
string[] \| string |
(required unless query) |
Regex patterns, OR'd; typically a pack rule's search.grep list (unescape the pack's JSON escaping first). |
query |
string |
"" |
The rule's semantic sentence. With a query the call takes the search lock like semantic_search; without one it is a lock-free disk scan. |
path_exclude |
string \| string[] |
"" |
Prefix(es) to skip, same literal-prefix rules as grep_search. |
case_sensitive |
boolean |
false |
Match exact case. |
max_files |
integer |
150 |
Files shown (the header says TRUNCATED when exceeded). |
lines_per_file |
integer |
20 |
Matching lines shown per file; the rest is counted. |
population |
string[] \| string |
"" |
(1.3.67+, CN-938) Membership regexes for absence-type rules — matched per line, or against the relative path when prefixed path:. The bundle then lists every member file with no grep evidence first, naming evidence in the same or a parent directory (per-directory middleware), and tags members that do have evidence with member. |
codebase |
string |
"" |
Codebase to scan, or the server default. |
Returns: A header with the match total, files hit, per-pattern counts, the semantic chunk count, and an explicit coverage line (ALL matching files are listed or TRUNCATED), then one section per file (most evidence first) with line | text rows and a ~semantic tag where the index also pointed there. Scans the live tree, so matched lines are raw — never copy a credential-looking line into a report. Match total is complete up to a 5000-line ceiling.
list_codebases¶
List all configured codebases with their paths and index status (chunk counts). A codebase whose folder sits inside another configured codebase is marked "inside …": the outer codebase already covers it. On a multi-codebase server the last line says where a call without codebase= goes. Each line also names the revision the index was built from (VCS, branch, revision, an uncommitted-changes flag and the remote URL without credentials), stamped at every index pass; the same stamp is the provenance object per codebase in the authenticated /health body.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
codebase |
string |
"" |
Show only this codebase. A scoped /mcp/{codebase} endpoint always sets it, so the reply names no other codebase. |
Returns:
- **api**: /var/www/myapp/api (3102 code chunks, inside **myapp**)
- **myapp**: /var/www/myapp (8234 code chunks; indexed from git main @ 1a2b3c4d5e6f from https://git.example.com/myapp.git)
- calls without codebase= go to: **myapp** (server default_codebase)
When to use: Before using the codebase filter on other tools, shows you what names are available.
generate_claude_md¶
Auto-generate a CLAUDE.md project summary from the indexed codebase. Analyzes directory structure, language breakdown, key classes and functions, entry points, and configuration files.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
codebase |
string |
"" |
Name of a specific codebase, or "" for default |
Returns: Markdown-formatted project summary:
# CLAUDE.md — Project Summary
*Auto-generated from 3723 indexed files, 14415 code chunks.*
## Languages
- **php**: 8748 chunks (61%)
- **js**: 532 chunks (4%)
...
## Directory Structure
- `public_html/admin/` — 846 files
...
## Entry Points
- `public_html/index.php`
...
## Key Classes
- **UserAuth** — `public_html/lib/Login.php` (120 lines)
...
## Key Functions
- `verifyCredentials` — `public_html/lib/Authorize.php` (66 lines)
...
When to use: Onboarding to a new codebase, generating context for AI agents, or sharing project structure with team members.
Wiki Tools¶
Two read-only tools that mirror the web UI's Wiki screen, LLM-compiled knowledge pages over a codebase's own indexed documents (never code). Neither tool triggers a compile.
wiki_pages¶
List compiled wiki pages for a codebase.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
codebase |
string |
"" (server default) |
Which codebase's wiki to list |
Returns: structuredContent with each page's slug, title, and kind (concept/entity). Multi-source pages only by default (≥2 contributing documents), with a note on how many single-source pages were hidden.
wiki_page¶
Fetch one compiled wiki page.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
slug |
string |
(required) | The page's slug, from wiki_pages |
codebase |
string |
"" (server default) |
Which codebase's wiki to read from |
Returns: The page's rendered markdown, including its Sources section (one entry per contributing document with a locator back to the source).
Investigation Notes Tools¶
Agent-written investigation notes (CN-550), stored per codebase and shared across every agent surface. Writes are security-scanned; every note is anchored to ≥1 indexed file and automatically goes stale when an anchor file changes (re-hashed after every reindex) or archived when it leaves the index. Fresh notes also blend into semantic_search results as clearly-labeled advisory hits. Disable the whole surface with CODENAVI_NOTES_ENABLED: false in data/settings.json. On lean-profile installs run them with reveal_tools(call="search_notes", args=…); reveal_tools(group="notes") shows their arguments.
save_note¶
Save (or update) an investigation note. Notes are pointers, not copies, summarize what you learned and reference code as file:line; bodies that are mostly pasted code, oversized bodies (>4096 bytes), secrets, and injection patterns are rejected with a reason. Embeds at save time, so it takes the search lock, never call in parallel with other search tools.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
title |
string |
(required) | Short note title |
body |
string |
(required) | Markdown body, max 4096 bytes; pointers not copies |
anchors |
array |
(required) | [{"file": "rel/path.py", "start_line": N, "end_line": M}], ≥1 required, lines optional |
category |
string |
"" |
flow, pattern, gotcha, or domain |
tags |
array |
[] |
Free-form string tags |
slug |
string |
"" |
Pass an existing slug to update that note in place (the refresh path for stale notes) |
codebase |
string |
"" |
Target codebase ("" = the default codebase) |
Returns: Saved note '<slug>' (status: fresh). or REJECTED: <reason>: fix the reason and re-save. Per-codebase cap: 500 notes.
search_notes¶
Vector search over saved notes only. Stale hits carry a [stale: <file> changed since written] marker, re-verify against the current code, then save_note with the same slug. Archived notes never appear here.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
query |
string |
(required) | Natural-language query |
limit |
integer |
5 |
Maximum results |
include_stale |
boolean |
true |
Include [stale]-marked notes |
codebase |
string |
"" |
Target codebase |
list_notes¶
Browse view of all notes, the operator surface. Includes archived notes.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
status |
string |
"" |
Filter: fresh, stale, archived, or "" (all) |
limit |
integer |
50 |
Maximum rows |
codebase |
string |
"" |
Target codebase |
Returns: one line per note: slug, status, title, author agent, updated time.
delete_note¶
Permanently delete one note by slug, the purge path for wrong or poisoned notes. No undo.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
slug |
string |
(required) | Slug returned by save_note / shown by list_notes |
codebase |
string |
"" |
Target codebase |
Structural / Relations Tools¶
Structural call-graph queries over the per-codebase relations sidecar (relations_{codebase}.db, built from the same tree-sitter pass as the index). Edges are name-based, not type-resolved, an edge records "this function contains a call spelled foo(...)"; when several definitions share a name the output says so rather than guessing. Callers must be in the same language family as the callee's definition (JS/TS count as one), a Python x.init() never reaches a JavaScript init(); set CODENAVI_GRAPH_CROSS_LANGUAGE=true to walk across languages anyway.16 Treat results as a lower bound: dynamic dispatch, reflection, route tables, and templates are invisible to static edges. In the lean tool profile these are hidden: run them with reveal_tools(call="find_callers", args=…), or list them for one client with X-CodeNavi-Tools.
find_callers¶
Who calls a symbol? Reverse-walks the precomputed call graph up to depth hops. Applies same-file shadowing (a call site in a file that locally defines the name resolves to that local definition) and notes when a name has multiple definitions.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
symbol |
string |
(required) | Bare name (sendMail) or qualified (Class::method) |
codebase |
string |
"" |
Which codebase, or "" for the server's default_codebase (the only codebase on a single-codebase install; a multi-codebase server with no default refuses the unscoped call and names the codebases) |
depth |
integer |
1 |
Hops to walk (max 4) |
limit |
integer |
50 |
Max call sites (max 200) |
Returns: the symbol's definition location(s), an ambiguity note if the name is overloaded, and per-hop call sites (path:line in <caller>). structuredContent11 mirrors this as definitions (name/qualified/kind/file/lines), call_sites (depth/file/line/caller), and ambiguous/capped flags. The output ends with the same Graph coverage: line impact_analysis appends (below) whenever the graph has blind spots, carried as coverage_note in the structured payload18, a caller list is evidence, and a caller the graph cannot see would otherwise read as not called.
When to use: trace who depends on a function before you change it.
impact_analysis¶
Blast radius: what is affected if a symbol or a file changes? Reverse-walks the call graph depth hops, groups affected files, and flags test files separately. It also reads per-symbol centrality8 (degree + PageRank): the report leads with a ⚠ Hub warning when the target is one of the most-connected symbols in the codebase, and adds a "Hubs in the blast radius" section calling out high-importance symbols the change reaches, so a load-bearing change is obvious at a glance. (Hub annotations appear only once the codebase has been reindexed on a build with centrality support; otherwise the output is unchanged.)
Importers of a file: for a file target the report also lists "Files that import or name this file", one hop, from the path and module tokens each file contains (import … from './b', require, include, PHP use App\Models\User, Perl Foo::Bar), resolved with the same rules as find_orphans: relative path first, extensionless TS/JS specifiers tried as .ts/.tsx/.js/… and index.*, then the longest path-suffix match. A file that defines no functions (a module of types or constants, a template) is now a valid target. Package-name imports (@scope/pkg, lodash) are not resolved, so a file reached only through a barrel index.ts shows the barrel. The structured payload carries the list as referenced_by. Since 1.3.71; the first reindex after the update rebuilds the call-graph sidecar once (seconds to a minute per codebase, CN-1060).
Method calls on an unknown type:22 for a method target, a call made on its class (Str::limit(), \Support\Str::limit()) or on self/static/$this inside it counts as a caller. A call on any other object ($query->limit(10), q.limit()) may be a different method with the same name, since the graph does not know the object's type. Those files are not dropped: they are listed after the others, under "Matched by method name only", and carry name_only: true in structuredContent (also on find_callers call sites). Functions, and languages that record no receiver yet (C#, Rust, Kotlin, Swift, Scala, Dart, Perl), are unchanged. A call that names its class explicitly is no longer hidden by a same-named method in the calling file, so Stringable::limit calling Str::limit now counts. Since 1.3.71; the first reindex after the update rebuilds the call-graph sidecar once.
Java: calls through an injected interface.23 A Java call's receiver is resolved to the declared type of the variable it is made on (a field, a constructor or method parameter, or a local, including var x = new Foo()), and each class's extends/implements are recorded. So in a Spring controller, clinicService.findOwnerById() on an @Autowired or constructor-injected ClinicService field counts as a caller of ClinicServiceImpl::findOwnerById, while vet.findOwnerById() on an unrelated class stays name-only. Calls on an expression (a.b().f()) and on Kotlin/C# objects are unchanged. The first reindex after the update rebuilds the call-graph sidecar once.
Coverage-aware:14 every verdict appends a Graph coverage: line quantifying what the call graph cannot see (never-indexed extensions from the skip ledger, scanner rejects, indexed-but-no-extractor languages, and any language where 60% or more of its call sites have no named caller17, top-level script code has none to name, and a definition shape the extractor does not recognise loses the calls in its body), and a file-path target whose extension was skipped at index time is refused, Cannot assess impact … treat this as UNKNOWN, not low impact, instead of returning a confident empty result. The structured payload carries the caveat as coverage_note.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
target |
string |
(required) | A symbol name (Mailer::send) or a relative file path (src/auth/login.php) |
codebase |
string |
"" |
Which codebase, or "" for the server's default_codebase (the only codebase on a single-codebase install; a multi-codebase server with no default refuses the unscoped call and names the codebases) |
depth |
integer |
2 |
Hops to walk (max 4) |
limit |
integer |
100 |
Max affected files listed (max 500) |
Returns:
Impact of changing symbol 'Facade::shouldReceive' — codebase: laravel
⚠ Hub: 'Facade::shouldReceive' is one of the most-connected symbols in the call graph (degree 1575: callers + callees). Changes here tend to have wide reach — review the blast radius carefully.
Affected files within 2 hop(s): 5 (4 test file(s))
Code:
- src/Illuminate/Support/Facades/Facade.php (via Facade::shouldReceive)
Tests:
- ...
Hubs in the blast radius (high-importance symbols affected — verify these first):
- Facade::shouldReceive (src/Illuminate/Support/Facades/Facade.php)
Caveat: edges are static name-based call sites … treat this as a lower bound, not a proof of safety.
structuredContent11 mirrors the report as target/target_kind/hub_target plus an affected list (file, is_test, via caller symbols, and hubs when god-nodes are reached).
When to use: before a refactor or rename, to gauge how far the change reaches and whether it touches load-bearing code.
graph_neighborhood¶
Bounded caller/callee sub-graph around a symbol, as structured nodes/edges, the same engine behind the web UI's Graph screen23 (core/graph.py), including class↔method contains edges and centrality8 (degree/pagerank) per node.
MCP App (SEP-1865):12 the tool declares _meta.ui.resourceUri = ui://codenavi/graph. On hosts that render MCP Apps (Claude web/desktop, VS Code, Goose), the result appears as an interactive explorer, click a node for an inspector, Expand pulls its 1-hop neighborhood via tools/call, and Tell the model shares the focused node into the conversation via ui/update-model-context; exploration clicks otherwise cost no context. The bundle is fully self-contained (vendored Cytoscape inlined; the spec's default CSP allows no external fetches) and renders indexed content via textContent/canvas only, never parsed as HTML. On text-only clients the tool is still useful as data: the text envelope carries a bounded summary (top 30 nodes by degree, 40-edge sample), structuredContent the full sub-graph.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
seed |
string |
(required) | A symbol name (sendMail) or qualified Class::method |
codebase |
string |
"" |
Which codebase, or "" for the server's default_codebase (the only codebase on a single-codebase install; a multi-codebase server with no default refuses the unscoped call and names the codebases) |
depth |
integer |
2 |
Hops to walk (max 4) |
direction |
string |
"both" |
"in" (callers), "out" (callees), or "both" |
node_cap |
integer |
300 |
Max nodes (max 1000); truncated: true flags a partial sub-graph |
Returns: structuredContent with nodes (id, label, kind, file, line, ambiguous, degree, pagerank), edges (source, target, relation: calls|contains, line), plus truncated/node_cap/notes. Name-based edges: treat as a lower bound.
When to use: visual/structural exploration around a symbol; the data twin of the web UI Graph screen for agents and MCP Apps hosts.
diff_impact¶
Blast radius of a unified diff. Maps each changed hunk's line range to the symbols it overlaps (via the sidecar's line ranges), then reverse-walks the call graph, separating ripples inside the changed files from the external blast radius. Also surfaces hubs.8 Changed files the graph cannot assess are attributed precisely14, NOT indexed (<ext> skipped at index time) vs no call-graph extractor (<language>), under a heading stating their impact is unknown, not zero.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
diff |
string |
(required) | Unified diff text (e.g. the output of git diff) |
codebase |
string |
"" |
Which codebase, or "" for the server's default_codebase (the only codebase on a single-codebase install; a multi-codebase server with no default refuses the unscoped call and names the codebases) |
depth |
integer |
2 |
Hops to walk (max 4) |
limit |
integer |
100 |
Max affected files listed (max 500) |
Since 1.3.7122 a hunk inside a method seeds only that method, not the class around it, and callers on an object of unknown type are listed apart (see impact_analysis). The report ends with a count of the files that import or name a changed file (impact_analysis on that file lists them). When no changed line falls inside a function or class (a types module, a template), those files are its only reach, so the report lists them instead (the first 20).
When to use: pre-commit or PR review, paste a git diff to see what the change ripples into before you push.
find_orphans¶
Files nothing reaches, and copies that drifted apart. Built for legacy PHP / Perl-CGI codebases, where files are reached by URL, include string and AJAX path and symbol-based dead-code tools (IDE references, knip, vulture) see nothing. One live walk of the codebase: every path, include or module token in a non-doc file (modules/x.php, ../act_config.php, Bugzilla::Util, App\Foo, a TypeScript/JavaScript import written without its extension such as './cart' or './utils' for utils/index.ts) is resolved to the file it names, longest path-suffix match with the referrer's own tree winning a tie, plus call-graph edges from the relations sidecar and mentions of the classes and functions a file defines (an autoloaded class names no path). A TypeScript/JavaScript module (a file with import/export) is reached only through an import path, including a path alias such as '@/lib/money' and the './create.js' form that names create.ts: a name it defines that appears in another file is not a reference. A file no reference reaches lands in a tier:
| Tier | Meaning |
|---|---|
orphan |
no reference and no inbound call from another file |
ambiguous |
its name is referenced, but several same-named files fit and nothing picks one — a copy may be borrowing its twin's reference, so neither is credited |
maybe-dynamic |
its folder is concatenated or interpolated into a path at runtime ("lang/_" . $lang) |
entry-point |
named in config/deploy files (.htaccess, crontab, ansible/, docker/, …) or matching an entry pattern (cron/, bin/, tests/, index.*, site-verification files) — not dead |
Then the copy groups: files sharing their last two path segments, drifted (same name, different content — the class where a fix lands in one copy only) listed before identical.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
codebase |
string |
"" |
Which codebase, or "" for the server's default_codebase |
path_prefix |
string |
"" |
Report only files under this folder; references still come from the whole codebase |
include_twins |
boolean |
true |
List the drifted and identical copy groups |
limit |
integer |
200 |
Max rows per section |
Returns: a header with the counts per tier and whether the call graph was available, then one section per tier and per copy class. Runs in a few seconds on a few thousand files (nothing is cached; it reads the live tree).
When to use: cleanup before a migration, or an attack-surface pass (CRA Annex I asks products to limit it): a forgotten endpoint is reachable code nobody patches. Read a file before deleting it — a URL reached only from outside the repo, or a file loaded by framework convention (fbx_Switch.php, a Template Toolkit hook), looks orphaned here. Hidden under the lean profile: reveal_tools(call="find_orphans", args='{"codebase": "…"}').
Chat & Backup Tools¶
chat: retired as an MCP tool (CN-558)¶
The chat MCP tool was removed in v1.3.22. An MCP caller is itself an LLM with
the retrieval tools in hand, a second LLM synthesizing on its behalf answered
worse than the caller would (and was the one agent-triggerable tool that sent
retrieved source code off-host when a remote provider was configured).
Grounded Q&A itself is unchanged and stays on the human-facing surfaces, all
backed by the same pipeline (core/chat.py):
- SPA Chat screen (
/ui), pick the LLM in the chat rail POST /chat: see HTTP Endpoints; this is what thecodenavi chatCLI uses- Chat output is still scanned (
chat_outputscope), and every[code] file:linecitation is validated against the chunks retrieved for that turn, citations the context does not support are flagged in the answer instead of presented as grounded
Agents wanting an answer about the codebase should run semantic_search /
read_file themselves and synthesize, that is the supported pattern.
backup¶
Snapshot all LanceDB tables, SQLite databases, chat history files, and settings to a timestamped backup directory.
Parameters: None.
Returns: Backup created: backup_20260326_143012
Notes:
- Keeps the last 3 backups (older ones are rotated out), calling backup purely
to discover existing IDs therefore destroys the oldest snapshot. Use
restore with an empty backup_id to list them instead.
- Backups are stored in index/lancedb-backup-*
- A full reindex also saves one there first. An incremental reindex does not: it builds the
new index next to the old one and keeps the old one until the next reindex.
restore¶
Restore from a previous backup. Fails if a crawl is currently active.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
backup_id |
string |
(required) | Backup directory name (e.g. backup_20260326_143012). Pass "" to list the available snapshots instead of restoring, listing is read-only and works even while a crawl is active. |
Returns: Confirmation; the available backup IDs when backup_id is empty; or
an error naming the available IDs if the requested one does not exist.
Crawler Tools¶
These tools are only registered when CRAWLER_ENABLED=true. They query the crawler's LanceDB tables and run history database.
Required environment configuration (per env):
| Variable | Required for | Default |
|---|---|---|
CRAWL_LOCAL_BASE_URL |
env=local |
http://localhost (container's localhost, usually not what you want; set to http://host.docker.internal:<port> to reach the host) |
CRAWL_DEV_BASE_URL |
env=dev |
unset → crawler exits with a clear error |
CRAWL_PROD_BASE_URL |
env=prod |
unset → crawler exits with a clear error |
CRAWL_DEV_API_BASE / CRAWL_PROD_API_BASE |
optional | empty (only set if you have a separate API host) |
Set these in ~/codenavi/.env. The crawler validates that base_url has an http:// or https:// scheme at startup and refuses to run with a relative or empty value (avoids the silent "0 URLs crawled" failure mode).
Site route mappers (extension point)¶
Two crawler capabilities need to know which URL renders a given source file:
source-code URL discovery (seeding from route references in source) and
crawl changed (re-fetching only the pages whose code moved since the last run).
That mapping is framework-specific, there is no general filesystem→URL
correspondence, so no mapper ships by default. Without one the crawler seeds
from base_url and discovers by links and sitemap, which is the normal mode of
operation and needs no configuration.
What degrades, and how:
| Capability | With a mapper | Without |
|---|---|---|
crawl |
Seeds from switch/route discovery + base_url, URLs tagged by circuit |
Seeds from base_url, link/sitemap discovery, all URLs tagged public |
crawl changed |
Re-crawls only URLs whose source changed | Exits 2, a diff-driven crawl is the mapping |
| Post-reindex auto-crawl | Fires crawl changed |
Skipped (no child process spawned) |
sync-api-routes, scan-safety |
Run | Report unavailable, exit 2 |
POST /ui/api/safety/scan |
Runs the scan | 501 with an explanatory message |
| Destructive-action block floor | In force | In force, it does not depend on a mapper |
The block floor is deliberately independent: it lives in crawler/safety_scanner.py
and is imported by crawler/url_guard.py, which every fetch passes through. A
missing mapper never weakens the crawl guard.
Installing one. Provide a Python package named site_routes on the
container's import path (a read-only directory bind-mount to /app/site_routes
is the simplest route) exposing three submodules:
| Submodule | Must expose | Contract |
|---|---|---|
discoverer |
APP_CONFIG, discover_from_switches(root, base_url, api_base, api_routes_path, timeout=…), discover_from_source_refs(root, base_url), sync_api_routes(root, out_path), load_api_routes(path, api_base) |
Returns lists of absolute URLs; APP_CONFIG maps app name → (dir, entry_script, circuit) |
diff_mapper |
map_files(paths, …) |
Changed repo-relative paths → URLs to re-crawl. Returning [] is valid and means "nothing to do" |
classifier |
classify_url(url) -> str |
One of public, member, affiliate, admin, drives which session the fetcher uses |
safety_scan |
scan_safety(public_html, app_config=…, config_path=…), write_report(report, path=None) |
Walks the app's action files and grades each one, then applies the layer-3 config. May import crawler.safety_scanner's load_safety_config / is_action_blocked, that layer-3 API is the stable surface a mapper is allowed to depend on |
crawler/routes.py performs the optional import and exposes AVAILABLE. All of
the above are pure functions with no DB or HTTP access; a mapper that raises on an
unfamiliar tree is a bug, return an empty list instead.
Extending CodeNavi generally: this is an in-process seam and deliberately narrow. For custom behaviour on indexing/crawl/chat events, notifications, downstream builds, syncing to another system, use the event hooks instead (
HOOK_URL/HOOK_SCRIPT_DIR, see Webhooks & hooks). Hooks run out of process, carry no dependency on CodeNavi internals, and cannot break on an upgrade. Reach for a route mapper only when you specifically need file→URL mapping.
crawl¶
Trigger a crawl run as a subprocess. Returns immediately with a run ID.
Full crawl runs automatically:
1. Source code URL discovery (requires an installed site route mapper; skipped otherwise), scans source files for route references and adds them as seeds, catching URLs that appear only in email templates, redirects and link builders. Without a mapper the crawl seeds from base_url and discovers by links and sitemap.
2. Destructive-action filtering: refuses any fuseaction matching the built-in block floor (*.delete, *.remove, *.destroy, *.purge, *.wipe, *.suspend, *.ban, *.disable, *.deactivate, *.revoke, *.terminate, *.void), while keeping past-tense and view pages crawlable (*.deleted, *.archived, *.view_*, *.list_*). The floor lives in code (crawler/safety_scanner.py), so it is always in force, no config file required. data/crawl_safety.json is optional and only extends or relaxes it; see Crawler safety config.
3. Safety report loading: if data/crawl_safety_report.json exists (written by scan-safety, which combines action-name heuristics with PHP GET-safe static analysis), it blocks additional critical/high-risk URLs. Those two analyses run only during scan-safety, not during a crawl. scan-safety enumerates action files through the site route mapper, so it requires one installed; the block floor in item 2 does not and is always in force.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
env |
string |
"local" |
Target environment: local, dev, or prod. Any other value is refused, nothing is spawned. |
mode |
string |
"full" |
full (all pages), changed (SVN diff only), or url (single page). Any other value is refused. |
url |
string |
"" |
Required when mode="url". Omitting it is refused: it must never be allowed to widen a spot-check into a full crawl. |
All three arguments are validated before the subprocess is spawned, so a rejected call never starts a crawl and never reports a false "started".
Returns: Crawl started for env=dev (mode=full), run_id=abc12345. Progress:
get_run_summary / list_runs. Stop it: cancel_crawl.
For mode="url" the response reports the pid instead: a spot-check is a single
request that registers no run, so there is no run_id and nothing to cancel.
cancel_crawl¶
Send SIGTERM to a running crawl subprocess.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
run_id |
string |
(required) | Run ID from crawl or list_runs |
Returns: Confirmation or "process not found" if already finished.
search_errors¶
Search crawl errors by semantic query. Returns errors similar in meaning to the query.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
query |
string |
(required) | Description of the error to find |
env |
string |
"" |
Filter by environment (local, dev, prod) |
run_id |
string |
"" |
Filter by specific run ID |
limit |
integer |
5 |
Maximum results |
Returns: JSON array of error records with url, error_type, error_message, context_for_llm, http_status, run_id, crawled_at.
search_urls¶
Find crawled pages by URL pattern or description.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
query |
string |
(required) | Page description or URL fragment |
env |
string |
"" |
Filter by environment |
run_id |
string |
"" |
Filter by run ID |
limit |
integer |
10 |
Maximum results |
Returns: JSON array with url, http_status, response_time_ms, content_hash, crawled_at, auth_level.
compare_runs¶
Diff two crawl runs: which errors are new, which were resolved.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
run_id_a |
string |
(required) | Baseline run (older) |
run_id_b |
string |
(required) | Comparison run (newer) |
Returns: JSON with run summaries, new_errors (appeared in B but not A), resolved_errors (in A but not B), and counts.
get_run_summary¶
Get statistics for a specific crawl run, or the latest run if no ID is provided.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
run_id |
string |
"" |
Run ID (omit for latest) |
Returns: JSON with run_id, env, status, total_urls, total_errors, error_breakdown, started_at, completed_at.
list_runs¶
List crawl history.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
env |
string |
"" |
Filter by environment |
limit |
integer |
10 |
Maximum runs to return |
Returns: JSON array of run summaries.
get_referrers¶
Find pages that link to a given URL. Answers "where is X linked from?"
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
url |
string |
(required) | The target URL to find referrers for |
env |
string |
"" |
Filter by environment |
run_id |
string |
"" |
Filter by run ID |
limit |
integer |
20 |
Maximum results |
Returns: JSON array with source_url, http_status, env, run_id. Empty result means the URL is a seed URL or predates referrer tracking (introduced 2026-03-21).
Crawler safety config¶
The crawler ships with two guards, both on by default and needing no configuration.
Destructive-action guard. The block floor lives in crawler/safety_scanner.py::_DEFAULT_SAFETY_CONFIG, in code, so a missing, empty, or corrupt config cannot disarm it. data/crawl_safety.json is optional; copy data/crawl_safety.json.example to create it.
| Key | Effect |
|---|---|
block |
Exact fuseactions to always block. Beats everything, including allow. |
block_patterns |
fnmatch globs to block. Unioned with the built-in floor, entries here add to it. Deleting an entry, or setting this to [], does not lower the floor. |
allow |
Exact fuseactions exempt from block_patterns. Replaces the default (empty) list when present. |
allow_patterns |
fnmatch globs exempt from block_patterns. Omit this key to keep the built-in exemptions (*.deleted, *.archived, *.view_*, *.list_*, …); defining it replaces them wholesale. |
Precedence: block > allow > block_patterns > allow_patterns. To permit an action the floor blocks, add it to allow, do not try to remove it from block_patterns.
SSRF guard. Each hostname is resolved and rejected if it lands on a private, loopback, or cloud-metadata address. In env=local loopback and RFC1918 are permitted, that is what local crawling means, but cloud-metadata ranges (169.254.0.0/16, fe80::/10, fd00:ec2::/32) are refused in every env. The /ui/api/crawler/crawl HTTP route does not inherit the local relaxation: it accepts a caller-supplied URL and so applies the strict blocklist unconditionally.
HTTP Endpoints¶
Every endpoint below, and the MCP transport itself, can answer 429 Too Many Requests with a Retry-After header when the per-client throttle refuses the request (a client over its request budget, or an address locked out for rejected tokens). /health and /.well-known/* are exempt. Limits and the reasoning: Configuration → Throttling.
GET /health¶
Health check. Always unauthenticated.
Response:
{
"status": "ok",
"version": "1.3.79",
"build": "r1044",
"mcp_endpoint": "http://localhost:8765/mcp",
"gpu": {
"available": true,
"name": "NVIDIA GeForce RTX 4090",
"device_count": 1,
"memory_used_mb": 8214.3,
"memory_total_mb": 24564.0,
"memory_torch_allocated_mb": 7488.1,
"memory_torch_reserved_mb": 7812.0
},
"compute_device": "cuda",
"compute_backend": "cuda",
"gpu_present_but_unused": false,
"embedding_models": {
"code": {"model": "/models/Buric-E0.6B", "version": "1.0", "status": "loaded"},
"content": {"model": "/models/Buric-E0.6B", "status": "idle"}
},
"llm": {"provider": "ollama", "model": "llama3.1", "status": "ok"},
"tables": {
"code_chunks": {"chunks": 12379},
"doc_chunks": {"chunks": 45},
"web_chunks": {"chunks": 8821}
},
"crawler": {"enabled": true},
"tier": "Unlimited",
"uptime_sec": 3600,
"index_integrity": {
"status": "ok",
"last_check": 1789575398.1,
"codebases": {"default": {"status": "ok", "checked_at": 1789575398.1, "mismatches": [], "written_at": 1789575100.4}}
}
}
index_integrity21 is the last verdict of the stored-index check: every reindex records a fingerprint of the active code table, the doc table and the call-graph sidecar (index/integrity_<codebase>.json); the server compares it with what is on disk after start-up and every INDEX_INTEGRITY_CHECK_INTERVAL seconds. ok, everything matches; mismatch, the mismatches list names what differs (rows, Lance version, missing or extra fragment files, sidecar bytes, PRAGMA quick_check) and the server log carries the same line as a WARNING, search keeps serving the index as stored, and a full reindex rebuilds and re-records it; a server upgrade that adds tables to the call-graph sidecar re-records its fingerprint, but only when the file still matched the manifest beforehand; any other change is still reported; unverified, no manifest yet (the next reindex writes one) or the check has not run. The overall status is mismatch if any codebase is, ok only when every codebase is. Cached: /health never hashes anything itself. Same verdict as the codenavi_index_integrity gauge.
The version field is read from the VERSION file at the project root. gpu.available/name/device_count come from nvidia-smi/MPS detection; the two memory_* pairs are deliberately different measurements, used/total is the whole card (every CUDA client), torch_allocated/torch_reserved is this server process only (the only per-process VRAM attribution that works under WSL2). All four read 0 when there's no CUDA device. compute_device is the embedder's actual device (cuda/mps/cpu) and is the field to key logic off; compute_backend (cuda/rocm/mps/cpu) is its display companion and is the one to show a human, torch-on-ROCm reports the CUDA device type, so an AMD card reads cuda in compute_device and rocm here. gpu_present_but_unused fires when a GPU is reachable but the embedder is running on CPU anyway, reachable by torch, known to the host (CODENAVI_HOST_HAS_GPU from the installer), or listed by the container runtime itself (nvidia-smi -L or /dev/kfd inside the container, probed only on a CPU embedder and cached 60 s). The last source catches a CUDA_VISIBLE_DEVICES pin on a card that is no longer on the bus: torch then sees no device and the server would otherwise come up healthy on CPU with no signal1. When it fires, gpu.unused_hint says why in one sentence (the runtime's device list and the CUDA_VISIBLE_DEVICES / NVIDIA_VISIBLE_DEVICES values in effect), gpu.runtime_visible lists what the runtime exposed, and the server log carries the same line as a WARNING at model load. See observability.md for the same fields as Prometheus metrics.
When multiple codebases are configured (CODEBASE_CONFIG), the response includes a codebases field with per-codebase stats:
{
"codebases": {
"myapp": {"path": "/var/www/myapp", "tables": {"code_chunks": {"chunks": 8234}, ...}},
"api": {"path": "/var/www/api", "tables": {"code_chunks": {"chunks": 3102}, ...}}
},
"default_codebase": "myapp"
}
The top-level tables field shows aggregated totals across all codebases. default_codebase is where a tool call without codebase= goes (null when unset: per-codebase tools then refuse and searches cover every codebase); the agent plugins' SessionStart hook names it so an agent never reads a "no matches" from the wrong codebase as real.
plugins (CN-1076) maps each agent plugin this server serves at /plugins/<agent>.git to its version, e.g. {"claude": "0.5.48", "codex": "0.3.24", "antigravity": "0.4.22", "cursor": "0.2.16"}. The SessionStart hooks compare it to their own version and name the update step when the server's is newer. An agent the build left out is missing from the map.
Since 1.3.38 (CN-706) each codebases.<name> entry also carries:
| key | meaning |
|---|---|
structural_ready |
the call-graph sidecar exists, find_callers, impact_analysis, diff_impact and symbol_search can answer |
vectors_ready |
an active vector table exists, semantic_search answers with results |
structural_coverage |
{"covered": [languages with a call-graph extractor], "uncovered": {language: files}}: docs, SQL, templates and config have no extractor, so a docs-only tree can be structural-ready with no symbols |
encode_progress |
{"done", "total"} chunks, present only while this codebase is in the encoding phase |
Status codes: 200 healthy, 503 degraded (model loading or index empty).
GET /metrics¶
Prometheus exposition of the live server metrics registry.5 Serves the process-wide prometheus_client registry (metrics.py) via generate_latest(), metrics incremented in the hot path (search.py, indexing.py). Bearer-gated when CODENAVI_AUTH_TOKEN is set, scrape with the token in the Prometheus job's authorization. Counts/histograms/gauges only (no query text or code), so it is safe to expose to an on-prem Prometheus.
Two scrape endpoints, same registry. CodeNavi also exposes the same metrics on a dedicated
prometheus_clientport 9091 (CODENAVI_METRICS_PORT, bound toCODENAVI_HOST, default127.0.0.1, unauthenticated), the standard path for a co-located Prometheus. Use this bearer-gated/metricson the API port for authenticated / remote scraping instead. Full setup + Grafana dashboard:observability.md.
Because the registry is per-process and the benchmark harness (tools/benchmark.py) runs in a separate process, these metrics reflect real server traffic only, benchmark runs do not pollute them.
Metrics:
| Metric | Type | Labels | Description |
|---|---|---|---|
codenavi_queries_total |
counter | tool, status, codebase |
Queries by tool (semantic/file/symbol/refs/overview/chat), status (ok/error), and codebase (queried codebase, or all for cross-codebase/unscoped) |
codenavi_query_duration_seconds |
histogram | tool, phase, codebase |
Query duration (seconds) by phase (search/rerank/total) and codebase |
codenavi_zero_results_total |
counter | tool, codebase |
Queries returning zero results, by tool and codebase |
codenavi_throttled_requests_total |
counter | reason |
Requests refused with 429 by the per-client throttle: auth (address locked out for rejected tokens) or load (request budget exceeded) |
codenavi_safety_gate_filtered_chunks_total |
counter | n/a | Chunks removed by the retrieval safety gate |
codenavi_alias_expanded_total |
counter | n/a | Queries expanded by an alias |
codenavi_feedback_votes |
gauge | rating |
Current feedback vote totals (up/down), refreshed on scrape |
codenavi_gpu_lock_wait_seconds, codenavi_search_lock_wait_seconds |
histogram | n/a | Lock-wait time (GPU file lock / search lock) |
codenavi_gpu_memory_bytes |
gauge | kind |
VRAM on device 0, read at scrape time. used/total are the device-wide CUDA view; torch_allocated/torch_reserved are this process only, use those to answer "how much is CodeNavi holding", since per-process attribution is otherwise unavailable (nvidia-smi --query-compute-apps returns [N/A] under WSL2, and its device total there also counts Windows-host clients). All four read 0 with no CUDA device, so total == 0 means "no GPU" |
codenavi_index_chunks, codenavi_index_files |
gauge | codebase |
Current index size per codebase (one series per indexed codebase; sum() for the total) |
codenavi_last_reindex_timestamp |
gauge | n/a | Unix time of last completed reindex |
codenavi_index_integrity |
gauge | codebase |
Stored-index integrity verdict: 1 ok, 0 mismatch (rebuild with a full reindex), -1 unverified |
codenavi_reindex_duration_seconds |
histogram | n/a | Reindex durations |
codenavi_codebase_last_reindex_timestamp |
gauge | codebase |
Unix time of each codebase's last completed reindex |
codenavi_llm_calls_total |
counter | caller, provider, model, status, codebase |
LLM calls by outcome (ok, error, no_response) |
codenavi_llm_tokens_total |
counter | caller, provider, model, kind, codebase |
Provider-reported tokens (prompt, completion, reasoning; reasoning is inside completion) |
codenavi_llm_duration_seconds |
histogram | caller, provider, model |
Time for one LLM call that returned |
codenavi_client_requests_total |
counter | client |
Requests by agent family |
codenavi_build_info |
gauge | version, embedder |
Always 1; the labels carry the running build |
Prometheus scrape config:
scrape_configs:
- job_name: codenavi
metrics_path: /metrics
static_configs:
- targets: ["localhost:8765"]
authorization:
credentials: "<CODENAVI_AUTH_TOKEN>" # omit if auth is disabled
Status codes: 200 success, 401 bad/missing bearer token, 500 internal error (returned as {"error": "..."}).
POST /chat¶
Run a chat turn in-process and get the answer as JSON. Use this when you want chat from a script without going through the MCP protocol, e.g., the CLI wrapper, a shell one-liner, or an internal tool. Because the work runs inside the server process, the already-loaded embedding models are reused; the caller never loads models or touches the GPU.
Authenticated when CODENAVI_AUTH_TOKEN is set (same bearer-token scheme as MCP).
Request body:
| Field | Type | Default | Description |
|---|---|---|---|
message |
string |
(required) | The user's question |
codebase |
string |
"" |
Scope to a single codebase, or "" for all |
session_id |
string |
"cli" |
Per-session chat history file |
source_type_filter |
string |
"" |
"code", "doc", "web", or "" |
history_turns |
integer |
10 |
Prior turns to include as context |
verbose |
boolean |
false |
Include retrieval metadata in the response |
trace |
boolean |
false |
Include per-stage timings. Implies verbose. Developer use. |
Response:
{
"response": "...answer text with citations...",
"meta": {
"chunk_count": 8,
"by_source": {"code": 6, "doc": 2},
"by_codebase": {"laravel": 8},
"chunks": [
{"source": "code", "codebase": "laravel", "ref": "src/Illuminate/Auth/SessionGuard.php:142"},
...
],
"timings": {"embed_ms": 42, "search_ms": 87, "rerank_ms": 310, "generate_ms": 71200, "total_ms": 71639},
"generation": {"provider": "ollama", "model": "llama3.1", "prompt_tokens": 3421, "completion_tokens": 364, "tok_per_sec": 5.1}
}
}
meta is present only when verbose or trace is true. timings and generation are present only when trace is true.
Example:
curl -s -X POST http://localhost:8765/chat \
-H 'Content-Type: application/json' \
-d '{"message":"how does auth expire?","codebase":"laravel","verbose":true}' \
| jq .
Status codes: 200 success, 400 missing message, 401 bad bearer token, 500 internal error (returned as {"error": "..."}).
GET /sessions¶
List the chat session ids the server knows about. Lets a UI populate a session picker without filesystem access to the server's data dir.
Returns: {"sessions": ["default", "paypal-debug", ...]}: derived from the chat_history_*.json files in core.chat._HISTORY_DIR.
curl -s http://localhost:8765/sessions
GET /history?session_id=<id>¶
Return the saved messages for a chat session as a list of {role, content} dicts. The /chat endpoint writes this file on every turn, GET /history is its read-back counterpart.
Query params:
| Name | Required | Description |
|---|---|---|
session_id |
yes | Same id used with POST /chat (filename-sanitized server-side) |
Returns: [{role: "user"|"assistant", content: str}, ...]: empty list if the session has no history.
curl -s 'http://localhost:8765/history?session_id=default'
DELETE /history?session_id=<id>¶
Remove the on-disk chat_history_<id>.json for a session. Idempotent.
Returns: {"deleted": true} if a file was removed; {"deleted": false} if it didn't exist.
curl -s -X DELETE 'http://localhost:8765/history?session_id=paypal-debug'
Status codes: 200 always (idempotent), 400 missing session_id, 401 bad bearer token.
POST /reindex¶
Trigger an in-process background reindex (the same endpoint the codenavi reindex CLI and reindex.sh use). Bypasses the 5-minute MCP cooldown, treated as admin. Requires the bearer token when CODENAVI_AUTH_TOKEN is set.
Body (JSON, all optional):
| Field | Default | Description |
|---|---|---|
full |
false |
true re-encodes everything (~20 min); default is incremental (changed files only, typically seconds). |
codebase |
"" |
Restrict to one codebase. Empty = all configured (ignores default_codebase6). |
wait_for_completion |
false |
Block until done (incremental only; ignored when full=true4). |
max_wait_seconds |
120 |
Timeout for the wait, clamped 1–300. |
Returns: {"started": bool, "message": str} (+ completed/result when waiting). A reindex (or Docs Wiki compile) already in progress returns HTTP 409 with started: false, the request is dropped, not queued; the next call catches up. Safe to fire redundantly, and the 409 status means even a caller that discards the body can log the drop.
curl -s -X POST http://localhost:8765/reindex \
-H "Authorization: Bearer $CODENAVI_AUTH_TOKEN" \
-H "Content-Type: application/json" \
-d '{"codebase": "myrepo"}'
⚠️ Fire-and-forget hooks fail silently, test the exact command once before trusting it. The idiomatic git-hook integration ends in
|| true(a reindex must never fail a push), which makes every error invisible: a missingContent-Type: application/jsonheader is a 415 on every push (the header is required as a CSRF guard and cannot be waived), and a wrong token-file path reads as an empty token, a 401 on every push. Both look identical to success from the hook's side, so the index silently never refreshes. Run your hook'scurlonce by hand without>/dev/nulland confirm you get{"started": true, ...}(or a409) before wiring it in.
Triggering from CI / your forge: unknown JSON keys are ignored, so a Git forge's push webhook (Forgejo, Gitea, GitLab, GitHub) can POST its native payload straight at this endpoint, no runner, no glue script. It falls through to the defaults: an incremental reindex of all codebases, which no-ops in seconds when nothing changed. Configure a webhook on push events with the target URL http://<codenavi-host>:8765/reindex and, if auth is enabled, an Authorization: Bearer <token> header (Forgejo/Gitea have a dedicated Authorization-header field in the webhook form). Poll GET /reindex-status if you need completion, or subscribe to the outbound reindex.completed event (Webhooks & hooks).
A webhook reindexes what is on disk, it does not update the clone. CODENAVI_GIT_PULL_BEFORE_REINDEX=true (env or data/settings.json, read live, default off) adds an opt-in git pull --ff-only in each git-checkout codebase root before scanning; a failed pull logs a warning and indexing proceeds on the tree as-is.19 It requires a read-write codebase mount and in-container git credentials, trade-offs and the recommended host-side alternative are covered in Running CodeNavi as a team server.
GET /reindex-status¶
Poll the progress of the most recent background reindex triggered via POST /reindex (or any other path, MCP tool, CLI, reindex.sh). Same bearer-token rule as /reindex.
curl -s http://localhost:8765/reindex-status -H "Authorization: Bearer $CODENAVI_AUTH_TOKEN"
Returns: Running status, progress, duration, and any errors, the same payload the reindex_status MCP tool and ./codenavi reindex-status CLI command return.
Since 1.3.38 (CN-706) the payload also carries phase (structural | encoding | finalizing | "") and encode_progress ({"done","total"}): the sidecar is built before the encode, so a reindex reports structural for seconds, then encoding with progress.
POST /cancel-reindex¶
Cancel a running background reindex. The reindex stops after the current encoding batch completes; the existing index is left unchanged (no partial data). Same bearer-token rule as /reindex. A cancel that arrives during the scan or the structural (call-graph) phase takes effect at the first encoding checkpoint, so on a large first index the stop can take a minute or two, the call-graph sidecar is built before the encode since 1.3.38 (CN-706).
curl -s -X POST http://localhost:8765/cancel-reindex -H "Authorization: Bearer $CODENAVI_AUTH_TOKEN"
GET /.well-known/oauth-protected-resource¶
RFC 9728 OAuth Protected Resource metadata for MCP auth discovery.
GET /.well-known/agent-card.json¶
The agent card: a JSON self-description AI agents use to onboard themselves:
identity, capabilities (every tool, grouped by skill), connection details, an
onboarding sequence with a paste-ready .mcp.json example, and the usage rules
(sequential search calls, read_file exemption, limits, filters). The version
field is injected from the running server at serve time.
Two disclosure tiers, same split as /health:
- Unauthenticated: the generic card only: product information identical for every install, nothing deployment-specific.
- With the bearer token, adds a
deploymentblock: codebase names, scoped/mcp/{codebase}endpoints, the default codebase, per-codebaseindex_last_writetimestamps (UTC ISO-8601; a stale one means reindex before trusting results), and whether the crawler is enabled.
curl -s -H "Authorization: Bearer $CODENAVI_AUTH_TOKEN" \
http://localhost:8765/.well-known/agent-card.json | python3 -m json.tool
GET /metrics (port 9091)¶
Prometheus metrics: the same full registry as the main GET /metrics section above (index gauges, query counts and durations, GPU, locks, feedback), served on the dedicated metrics port.
Error Handling¶
Auth failure (401):
{"error": "invalid_token", "error_description": "Authentication required"}
MCP protocol errors follow JSON-RPC 2.0:
{"jsonrpc": "2.0", "id": 1, "error": {"code": -32600, "message": "..."}}
Rate Limits¶
- Reindex: one MCP call every 60 seconds per codebase;
./codenavi reindexhas no limit, and only one reindex runs at a time - Feedback: Maximum 5 ratings per chunk per 5-minute window
- Search/chat: No rate limit; the GPU phases serialize internally, keep one or two in flight for best latency
CLI Commands¶
The CLI (tools/cli.py) provides direct access without MCP. Run inside Docker or via the ./codenavi wrapper script (./codenavi-cli is a back-compat symlink).
init¶
Scan a codebase directory, detect languages, and generate a starter settings.json.
./codenavi init /path/to/your/project
./codenavi init /path/to/project --output /custom/data/dir
./codenavi init /path/to/project --force # overwrite existing settings.json
What it does:
1. Walks the directory tree, counts files by extension
2. Detects programming languages from file extensions
3. Auto-excludes known junk directories (node_modules, vendor, .git, etc.)
4. Auto-detects large asset directories (>200 files) to exclude
5. Generates data/settings.json with sensible defaults
Other CLI commands:
The CLI covers most MCP tools, search, read, indexing, docs, feedback, and crawler observation. The structural/relations tools (find_callers, impact_analysis, diff_impact, graph_neighborhood) the Wiki tools (wiki_pages, wiki_page) and the investigation-note tools (save_note, search_notes, list_notes, delete_note) are MCP/web-UI only today. Commands are grouped by category below.
Search & code intelligence:
| Command | Maps to MCP tool |
|---|---|
./codenavi search "query" |
semantic_search |
./codenavi file "query" |
file_search |
./codenavi symbol NAME [--kind ...] [--language ...] [--source] |
symbol_search |
./codenavi refs NAME [--language ...] [--path PREFIX] |
find_references |
./codenavi grep PATTERN [--path ...] [--exclude ...] [--language ...] [--context N] |
grep_search |
./codenavi chat ["message"] [--codebase NAME] |
POST /chat (no MCP tool since CN-558; REPL if no message) |
Files & structure:
| Command | Maps to MCP tool |
|---|---|
./codenavi read PATH [--start N] [--end N] |
read_file |
./codenavi ls [PATH] [--depth N] |
list_directory |
./codenavi overview [--section all\|languages\|structure\|files\|symbols] |
codebase_overview |
./codenavi codebases |
list_codebases |
./codenavi index-stats [--codebase NAME] |
index_stats |
./codenavi claude-md [--codebase NAME] |
generate_claude_md |
Indexing, docs, admin:
| Command | Maps to MCP tool |
|---|---|
./codenavi reindex [--full] [--codebase NAME \| --all] [--wait] |
reindex |
./codenavi reindex-status |
reindex_status |
./codenavi reindex-cancel |
cancel_reindex (POSTs to new /cancel-reindex REST endpoint) |
./codenavi reindex-compare [--backup NAME] [--codebase NAME] [--list] |
(CLI-only: diffs current index vs a saved lancedb-backup-*) |
./codenavi docs-list [--codebase NAME] |
doc_sources |
./codenavi docs-reindex [--codebase NAME] |
reindex_docs |
./codenavi backup |
backup |
./codenavi restore BACKUP_ID |
restore |
Feedback & analytics:
| Command | Maps to MCP tool |
|---|---|
./codenavi feedback-submit QUERY CHUNK_ID FILE --rating {1,-1} [--comment ...] |
submit_feedback |
./codenavi feedback-stats |
feedback_stats |
./codenavi analytics [--since YYYY-MM-DD] [--top N] |
search_analytics |
Crawler: orchestration (passthrough to crawler.py):
| Command | Description |
|---|---|
./codenavi crawl <subcommand> |
Subcommands: run [local\|dev\|prod] [--max-depth N] [--no-embed], re-embed <run_id>, changed [local\|dev], status, sync-api-routes, scan-safety [--review]. Requires CRAWL_<ENV>_BASE_URL set in ~/codenavi/.env (see Crawler Tools for details). |
Crawler: observation (queries against crawl_runs.db):
| Command | Maps to MCP tool |
|---|---|
./codenavi runs [--env ENV] [--limit N] |
list_runs |
./codenavi run-summary [--run-id ID] |
get_run_summary |
./codenavi runs-compare RUN_A RUN_B |
compare_runs |
./codenavi errors QUERY [--env ...] [--run-id ...] |
search_errors |
./codenavi urls QUERY [--env ...] [--run-id ...] |
search_urls |
./codenavi referrers URL |
get_referrers |
./codenavi crawl-cancel RUN_ID |
cancel_crawl (SIGTERM via PID registry) |
Server status:
| Command | Description |
|---|---|
./codenavi status |
Server health check |
./codenavi version |
Server version (live via /health, falls back to the VERSION file) |
chat¶
chat posts to the server's /chat endpoint so the already-loaded embedding models are reused, the CLI itself never loads models or touches the GPU.
./codenavi chat "how does auth expire?"
./codenavi chat --codebase laravel "how does auth expire?"
./codenavi -v chat --codebase laravel "how does auth expire?"
Flags:
| Flag | Description |
|---|---|
--codebase NAME |
Scope chat to a single codebase (default: all configured codebases). |
-v, --verbose |
(top-level flag) Print total time, per-source/per-codebase chunk counts, and each retrieved chunk's ref to stderr. The answer on stdout stays pipeable. |
--trace |
Developer-only: per-stage timings (embed, search, rerank, generate) and LLM token stats. Implies --verbose. Not shown in --help. |
Environment:
| Variable | Default | Description |
|---|---|---|
CODENAVI_PORT |
8765 |
Port where the CodeNavi server listens. |
CODENAVI_AUTH_TOKEN |
(empty) | Bearer token sent in the Authorization header when set. |
reindex¶
reindex posts to the server's /reindex endpoint. The work runs inside the server process (not the CLI), so the already-loaded embedding models are reused and there's no second GPU consumer. By default it prints the server's start message and returns; --wait polls /reindex-status every 5 s until the reindex finishes, prints the result, and exits non-zero if it failed. The wait runs in the CLI, so it is safe for a --full rebuild too. For post-reindex snapshots with checksums, use reindex.sh.
./codenavi reindex # incremental, all codebases
./codenavi reindex --full # full rebuild, all codebases
./codenavi reindex --codebase laravel # incremental, laravel only
./codenavi reindex --full --codebase laravel # full rebuild, laravel only
./codenavi reindex --full --wait # full rebuild, return when it finishes
Flags:
| Flag | Description |
|---|---|
--full |
Re-encode every file from scratch (~20 min). Default is incremental (only changed files). |
--codebase NAME |
Reindex only the named codebase. Default: all configured. |
--all |
All configured codebases. Same as the default; cannot be combined with --codebase. |
--wait |
Poll until the reindex finishes, then print the result. Exit code 1 if it failed. |
Same CODENAVI_PORT / CODENAVI_AUTH_TOKEN env vars as chat. The server enforces a 5-minute cooldown for the MCP reindex tool but not for this endpoint (CLI is treated as admin).
Unlike the MCP
reindex_incrementaltool and the/codenavi:reindexslash command, this CLI/HTTP path ignoresdefault_codebase, omitting--codebasealways reindexes all codebases6, soreindex.sh's documented full-sweep is unchanged.
Verbose output (example):
[v] POST /chat codebase=laravel len=20
<answer on stdout>
[v] total 71.34s chunks=8 by_source={'code': 6, 'doc': 2} by_codebase={'laravel': 8}
[v] [code] laravel: src/Illuminate/Auth/SessionGuard.php:142
[v] [code] laravel: src/Illuminate/Auth/Passwords/PasswordBroker.php:23
...
Trace output (adds, with --trace):
[t] embed=42ms search=87ms rerank=310ms generate=71200ms server_total=71639ms
[t] llm=ollama/llama3.1 prompt=3421tok completion=364tok 5.1tok/s
Use trace to separate retrieval cost from LLM cost when a chat turn is slow.
-
CN-862: found on a dual-GPU dev box after a BIOS update dropped the pinned card: the container reported
gpu.available: false, device_count: 0andstatus: ok, and every search took 2–8 s instead of 0.2 s. ↩ -
Vendor change reference CN-217. ↩
-
Vendor change reference CN-218. ↩
-
Vendor change reference CN-232. ↩
-
Vendor change reference CN-236. ↩
-
Vendor change reference CN-261. ↩
-
Vendor change reference CN-402. ↩
-
Vendor change reference CN-425. ↩
-
Vendor change reference CN-561. ↩
-
Vendor change reference CN-679. ↩
-
Vendor change reference CN-686. ↩
-
Vendor change reference CN-564. ↩
-
Vendor change reference CN-638. ↩
-
Vendor change reference CN-748. ↩
-
CN-1062, found in a headless CI review of a
Str::limitchange: 58 files matched the bare namelimit, almost all query-builder calls. On that diff the report now lists 2 confirmed files (Stringable.php,SupportStrTest.php) and 57 name-only. ↩↩ -
CN-1119. On Spring Petclinic (103 Java files), confirmed callers of the service and repository methods went from 14 to 223 of about 700 call sites in main code. Every one still name-only is a call on a different resolved type. ↩
-
CN-1167. An audit that has to list every file touching a table no longer stops at 200 matching lines. ↩
-
CN-1194. Measured on ten Laravel queries at limit 5: the structured answer went from a median of 5.6k to 5.1k chars, and to 1.8k with
output="locations". ↩↩