index_codebase
Index a codebase for semantic search. This is typically the first tool you’ll use.Parameters
Behavior
First Run (Full Indexing):- Scans directory for supported files
- Splits code into semantic chunks (AST-based for supported languages)
- Generates embeddings
- Stores vectors in the search index
- Saves a sync snapshot for future incremental sync
- Auto-starts file watcher
~/projects containing multiple repos), SHARC blocks indexing and returns a guarded_block response with:
- The number of detected repos and sample paths
- A one-shot
guardOverrideTokento proceed if intentional - Guidance to index a specific child repo instead
- Loads previous sync snapshot
- Computes current file hashes
- Identifies changed files via diff
- Only re-indexes added/modified files
- Removes vectors for deleted files
Example
search_code
Search indexed code using natural language queries.Parameters
Search Modes
ThesearchMode parameter controls which types of code are returned:
This is useful when an agent needs to find specific categories of code. For example, use
implementation_only when looking for how a feature works, or tests_only when looking for test coverage of a function.
Behavior
- Generates embedding for query
- Performs hybrid search (dense vectors + BM25 sparse)
- Reranks results for better relevance
- Returns ranked code snippets with metadata
Result Format
Each result includes:- Location: File path and line numbers
- Score: Relevance score (0-1, higher is better)
- Code: The matching code snippet
- Context: Surrounding class/function information
Understanding Scores
SHARC uses hybrid retrieval (dense vectors + BM25 sparse matching) combined with a reranker, which produces well-calibrated relevance scores:
If a targeted query does not return results in the 0.9+ range, it typically means the implementation doesn’t exist in the codebase, the query was too vague, or the implementation itself is loosely structured. Try rephrasing with more specific terms.
Example
Query Tips
clear_index
Remove a codebase from the index.Parameters
Behavior
- Stops file watcher (if active)
- Deletes indexed data for that codebase
- Removes sync snapshot metadata
- Clears local caches
Example
get_indexing_status
Check the indexing status of a codebase.Parameters
Response States
Example
start_watch
Start watching a codebase for file changes.Parameters
Behavior
- Requires codebase to be already indexed
- Uses chokidar for file system events
- 2-second debounce for batched processing
- Automatically filters unsupported files
- Validates syntax before indexing (prevents broken code)
Example
File watching starts automatically after
index_codebase completes. You only need start_watch if you previously stopped watching.stop_watch
Stop watching a codebase for file changes.Parameters
Example
get_watch_status
Get the list of codebases currently being watched.Parameters
None.Example
Supported File Extensions
Tier 1: AST-Parsed (Best Quality)
Full semantic understanding with context injection:.ts, .tsx, .js, .jsx, .mjs, .cjs, .py, .pyw, .go, .rs, .java, .cs, .cpp, .cc, .cxx, .c, .h, .hpp, .scala
Tier 2: Documentation
Character-based chunking with overlap:.md, .mdx, .rst, .txt
Tier 3: Configuration
Grouped key-value chunking:.json, .yaml, .yml, .toml, .xml, .env.example, .ini, .cfg
Tier 4: Other Code
Fallback chunking for unsupported languages:.rb, .php, .swift, .kt, .kts, .vue, .svelte, .html, .css, .scss, .less, .sql