find_dead_code
Identify unused functions, methods, and classes in your codebase by cross-referencing definitions against references. Get confidence scores and reasons for each candidate.
Instructions
USE THIS TOOL to find functions, methods, and classes that look like dead code (defined but never called).
PREREQUISITE: This tool requires indexing. If results are empty or you haven't indexed this session, call index_codebase(directory) first.
HOW IT WORKS: Cross-references the indexed symbol table against the indexed reference table. Any symbol with no reference outside its own definition body is flagged as a candidate. Each candidate is scored with a confidence in [0.0, 0.99] and a list of human-readable reasons explaining the verdict.
TRIGGER - Call this tool when the user asks:
"Find dead code / unused functions / unused classes"
"What's not used in this codebase?"
"Are there functions I can safely delete?"
"Show me dead code in "
"Find unreachable / orphaned code"
HEURISTICS APPLIED:
Excludes Python dunder methods (init, call, etc) — protocol methods
Excludes 'main' — common entry point
Excludes test files by default (override via include_tests=True)
Excludes anonymous and file-level fallback symbols
Lower confidence for methods in JS/TS/Go/Rust/C++/Kotlin (member-access calls aren't captured by the reference index)
Lower confidence for symbols defined in init.py / index.{js,ts} / mod.rs (likely re-exports)
Lower confidence for decorated symbols (likely framework-registered)
Lower confidence when the name is shared across multiple symbols
LIMITATIONS: Cannot detect symbols invoked via reflection, dynamic dispatch, string-based imports, or framework registration. Treat results as candidates to investigate, NOT as a definitive deletion list. Always verify before removing code.
Do NOT use this tool for:
Finding code definitions (use search_code with "definition")
Finding where code is used (use search_code with "references")
General code search (use search_code with "topic_discovery")
Args: directory: Path to the project directory to scan. min_confidence: Minimum confidence (0.0-1.0) to include a candidate. Default 0.5. Raise to filter aggressively. kinds: Symbol kinds to scan. Default ['function', 'method', 'class']. Allowed values: 'function', 'method', 'class'. include_tests: If True, also scan symbols in test files. Default False. top_k: Maximum candidates to return, sorted by confidence desc (default 50, max 500).
Returns: Dict with: - candidates: list, each containing name, kind, file_path, line_start, line_end, confidence, reasons, source_excerpt. - count: number of candidates returned. - scanned_symbols: count of symbols inspected after exclusions. - total_symbols: total symbols of the requested kinds in the index. - limitations: list of caveats for interpreting the results.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| kinds | No | ||
| top_k | No | ||
| directory | Yes | ||
| include_tests | No | ||
| min_confidence | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |