/code-quality:smart-explorefrom code-quality
Progressive code exploration that reads structure first (function signatures, types) then drills into specific functions. Reduces token usage by ~92% when understanding unfamiliar modules or finding where to add features.
Ships in code-quality. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description, though model invocation is off: only you can start it.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Skill: Read code structure before reading code. Show Claude function signatures and types first, then let it drill into specific functions only when needed.
Inspired by: Alex Newman (Claude-MEM) + Aider repo map pattern (validated at 40k+ stars)
When Claude reads files to understand a codebase, it reads everything:
# What actually happens
Read src/auth.rs → 400 lines → ~2,800 tokens
Read src/session.rs → 300 lines → ~2,100 tokens
Read src/user.rs → 500 lines → ~3,500 tokens
# Total: 8,400 tokens for 3 files
Most of that content is irrelevant. Claude needed to know that auth.rs has fn login() and fn logout() — not 400 lines of implementation.
Progressive exploration fixes this:
Step 1: What's in auth.rs? → ~200 tokens (signatures only)
Step 2: Show me fn login() body → ~350 tokens (one function)
Step 3: Who calls login()? → ~150 tokens (cross-reference)
# Total: 700 tokens instead of 8,400 — 92% reduction
| Signal | Use smart-explore | Use standard Read |
|---|---|---|
| "Understand this module/feature" | ✅ | ❌ |
| Exploring unfamiliar codebase | ✅ | ❌ |
| Finding where to add a feature | ✅ | ❌ |
| Need to read one specific function | ❌ | ✅ |
| Debugging a known line | ❌ | ✅ |
| File is < 100 lines | ❌ | ✅ (just read it) |
Don't use for:
Exploration task?
├─ Yes, understand a module
│ └─ Files > 200 lines each?
│ ├─ Yes → smart-explore (structure first)
│ └─ No → just Read (file is small)
├─ Search for something specific
│ └─ By name/pattern → Grep
│ └─ By meaning → grepai semantic search
└─ Need one specific function → Read with offset
No installation needed. Just change how you prompt Claude.
Add to your CLAUDE.md (or instruct Claude directly):
## Code Exploration Protocol
When asked to explore a codebase or understand a module:
1. **Structure first**: Use Grep to find function/class definitions
Rust:
`rg "^\s*(pub\s+)?(async\s+)?fn |^\s*(pub\s+)?(struct|enum|trait|impl)\s" src/ --no-heading -n`
Python/TypeScript/JS:
`rg "^\s*(async\s+)?(def |function |class |export (function|class|const))" src/ --no-heading -n`
Note: use `^\s*` not `^` — methods inside impl blocks and class bodies are indented.
The `^` pattern misses ~70% of Rust methods.
2. **Identify relevant symbols**: Based on names, pick 2-3 to read
3. **Targeted read**: Use Read with offset/limit to read specific functions
- Read lines 45-90 of auth.rs, not the whole file
4. **Cross-reference**: Use Grep to find callers only if needed
- `rg "fn_name" --type rust -n`
Never read a file start-to-finish when exploring. Always structure first.
Works with: Any Claude Code session, zero dependencies.
Use a lightweight Python script to extract signatures with regular expressions. It is not a parser: multi-line signatures may be truncated or missed.
Extract signatures script: save as ~/.claude/scripts/extract-signatures.py:
#!/usr/bin/env python3
"""Extract function/class signatures from source files with regular expressions."""
import sys
import re
from pathlib import Path
def extract_signatures(file_path: str) -> list[str]:
"""Extract function and type signatures without bodies."""
path = Path(file_path)
# Detect language from extension
lang_map = {
".rs": "rust", ".py": "python", ".ts": "typescript",
".tsx": "typescript", ".js": "javascript", ".jsx": "javascript",
".go": "go",
}
lang = lang_map.get(path.suffix)
if not lang:
return [f"# Unsupported: {path.suffix}"]
# Read actual source for signature extraction
source_lines = path.read_text().splitlines()
signatures = []
# Regex-based signature extraction
patterns = {
"rust": [
(r"^(\s*(?:pub\s+)?(?:async\s+)?fn\s+\w+[^{]*?)(?:\{|$)", "fn"),
(r"^(\s*(?:pub\s+)?struct\s+\w+[^{]*?)(?:\{|$)", "struct"),
(r"^(\s*(?:pub\s+)?enum\s+\w+[^{]*?)(?:\{|$)", "enum"),
(r"^(\s*(?:pub\s+)?trait\s+\w+[^{]*?)(?:\{|$)", "trait"),
(r"^(\s*impl\s+[^{]+?)(?:\{|$)", "impl"),
],
"python": [
(r"^(\s*(?:async\s+)?def\s+\w+[^:]*:)", "fn"),
(r"^(\s*class\s+\w+[^:]*:)", "class"),
],
"typescript": [
(r"^(\s*(?:export\s+)?(?:async\s+)?function\s+\w+[^{]*?)(?:\{|$)", "fn"),
(r"^(\s*(?:export\s+)?(?:default\s+)?class\s+\w+[^{]*?)(?:\{|$)", "class"),
(r"^(\s*(?:export\s+)?(?:const|let)\s+\w+\s*=\s*(?:async\s+)?\([^)]*\)\s*=>)", "arrow"),
(r"^(\s*(?:export\s+)?(?:interface|type)\s+\w+[^{=]*?)(?:\{|=|$)", "type"),
],
"go": [
(r"^(\s*func\s+[^{]+?)(?:\{|$)", "fn"),
(r"^(\s*type\s+\w+\s+(?:struct|interface)[^{]*?)(?:\{|$)", "type"),
],
"javascript": [
(r"^(\s*(?:export\s+)?(?:default\s+)?(?:async\s+)?function\s+\w+[^{]*?)(?:\{|$)", "fn"),
(r"^(\s*(?:export\s+)?(?:default\s+)?class\s+\w+[^{]*?)(?:\{|$)", "class"),
(r"^(\s*(?:export\s+)?(?:const|let)\s+\w+\s*=\s*(?:async\s+)?\([^)]*\)\s*=>)", "arrow"),
],
}
lang_patterns = patterns.get(lang, [])
for i, line in enumerate(source_lines, 1):
for pattern, sig_type in lang_patterns:
match = re.match(pattern, line)
if match:
sig = match.group(1).strip().rstrip("{").strip()
signatures.append(f" {sig_type} {sig} (line {i})")
break
return signatures
def explore_directory(directory: str, extensions: list[str] | None = None) -> None:
"""Print structure of all source files in directory."""
if extensions is None:
extensions = [".rs", ".py", ".ts", ".tsx", ".js", ".go"]
path = Path(directory)
files = sorted(
f for ext in extensions
for f in path.rglob(f"*{ext}")
if not any(part.startswith(".") or part in ("node_modules", "target", "__pycache__", "dist")
for part in f.parts)
)
for file in files:
rel_path = file.relative_to(path)
sigs = extract_signatures(str(file))
if sigs:
print(f"\n{rel_path}:")
for sig in sigs:
print(sig)
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: extract-signatures.py <file_or_dir> [ext1 ext2 ...]")
sys.exit(1)
target = sys.argv[1]
exts = sys.argv[2:] if len(sys.argv) > 2 else None
if Path(target).is_file():
sigs = extract_signatures(target)
for sig in sigs:
print(sig)
else:
explore_directory(target, exts)
Make executable:
chmod +x ~/.claude/scripts/extract-signatures.py
Usage:
# Single file
python3 ~/.claude/scripts/extract-signatures.py src/auth.rs
# Whole directory
python3 ~/.claude/scripts/extract-signatures.py src/
# Specific extensions
python3 ~/.claude/scripts/extract-signatures.py src/ .ts .tsx
Sample output (on a 500-line Rust file):
src/auth.rs:
fn pub fn new(config: AuthConfig) -> Self (line 12)
fn pub async fn login(username: &str, password: &str) -> Result<Session> (line 28)
fn pub async fn logout(session_id: Uuid) -> Result<()> (line 67)
fn pub fn validate_session(token: &str) -> bool (line 89)
struct pub struct AuthConfig (line 110)
struct pub struct Session (line 125)
impl impl AuthService (line 140)
Tokens: ~50-150 per file vs 2,000-5,000 for full reads.
Add to CLAUDE.md to make this automatic:
## Code Structure Tool
Before reading multiple files, run:
`python3 ~/.claude/scripts/extract-signatures.py <directory>`
This shows all function signatures without file bodies. Use this to identify
which specific functions to read, then use Read with line offset.
For codebases over 50 files, an indexed MCP server provides faster lookups and handles cross-file references.
Best options by use case:
| Use Case | Recommended | Install |
|---|---|---|
| General code exploration | mcp-server-tree-sitter | pip install mcp-server-tree-sitter |
| PR code reviews | code-review-graph | pip install code-review-graph |
| Symbol-heavy workflows | jCodeMunch (non-commercial) | claude mcp add jcodemunch uvx jcodemunch-mcp |
pip install mcp-server-tree-sitter
# Add to Claude Code
claude mcp add tree-sitter python -m mcp_server_tree_sitter
Available tools once installed:
get_file_structure — signatures and types for a filerun_ast_query — custom tree-sitter query (advanced)find_symbols — search by name across codebaseanalyze_dependencies — cross-file reference analysisOr configure it as JSON in a project .mcp.json (or ~/.claude.json), not in settings.json:
{
"mcpServers": {
"tree-sitter": {
"command": "python",
"args": ["-m", "mcp_server_tree_sitter"]
}
}
}
pip install code-review-graph
code-review-graph install
What it adds: When reviewing a PR, Claude gets the changed files AND their dependency graph automatically. Instead of reading 30 files to understand the impact of a change, Claude sees the 5 files that actually matter.
Usage:
/review-pr 123
# code-review-graph automatically provides:
# - Changed files
# - Files that import changed modules
# - Type definitions affected
# - Test coverage for changed code
claude mcp add jcodemunch uvx jcodemunch-mcp
Note: Free for personal/OSS projects. $79/developer for commercial use. Check licensing before team adoption.
Once added, Claude can call:
get_symbol("login") → function body
find_callers("login") → who calls it
get_class_hierarchy("User") → inheritance tree
get_dependencies("auth.rs") → what it imports
Old way (4 reads, ~12k tokens):
Read src/payments/processor.rs # 400 lines
Read src/payments/validator.rs # 300 lines
Read src/payments/gateway.rs # 500 lines
Read src/payments/types.rs # 200 lines
Smart explore way (1 structure scan + 2 targeted reads, ~1.5k tokens):
# Step 1: Get structure (~400 tokens for all 4 files)
python3 ~/.claude/scripts/extract-signatures.py src/payments/
# Step 2: Identify what matters from signatures
# "process_payment() calls validate_amount() — read those two"
# Step 3: Read only those functions (with line offsets)
Read src/payments/processor.rs (lines 45-90) # ~300 tokens
Read src/payments/validator.rs (lines 12-40) # ~200 tokens
Result: Same understanding, ~87% fewer tokens.
# Goal: Add rate limiting to the auth service
# Step 1: What's in the auth module?
python3 ~/.claude/scripts/extract-signatures.py src/auth/
# Output:
# src/auth/middleware.rs:
# fn pub fn authenticate(req: &Request) -> Result<Claims> (line 15)
# fn pub fn refresh_token(token: &str) -> Result<String> (line 45)
#
# src/auth/service.rs:
# fn pub fn validate(claims: &Claims) -> bool (line 8)
# fn pub async fn login(creds: &Credentials) -> Result<Token> (line 20)
# Step 2: Rate limiting goes in middleware.rs before authenticate()
# Read ONLY the authenticate function to understand injection point
Read src/auth/middleware.rs lines 15-44
# Step 3: Add feature — done
Add to your project's CLAUDE.md:
## Code Exploration Protocol
**For any exploration/refactoring task on this codebase:**
1. **Never read full files when exploring** — use structure scan first
2. Run `python3 ~/.claude/scripts/extract-signatures.py <module_dir>`
3. Identify 2-3 relevant functions from the output
4. Read only those functions (use Read with line offset from signature output)
5. For cross-file dependencies: Grep for the function name, don't read the caller file
**Rationale**: This codebase has ~80 files averaging 300 lines. Full reads = 15k+ tokens per task. Structure-first = 1-2k tokens.
Measured patterns, not marketing:
| Operation | Without smart-explore | With smart-explore | Savings |
|---|---|---|---|
| Understand 5-file module | ~18,000 tokens | ~2,500 tokens | ~86% |
| Find where to add a feature | ~8,000 tokens | ~800 tokens | ~90% |
| PR review (10 changed files) | ~25,000 tokens | ~3,500 tokens | ~86% |
| Single function lookup | ~3,000 tokens | ~350 tokens | ~88% |
Context: Numbers based on typical files (200-500 lines). Savings scale up for larger files and down for tiny ones. The Aider project (40k+ stars) independently validates this approach produces ~1,000 token summaries for entire large repos.
| Tool | What it saves | When |
|---|---|---|
| RTK | Command output tokens (git, cargo, npm) | After running CLI commands |
| smart-explore (this skill) | Code reading tokens | Before reading source files |
| grepai | Multiple Grep rounds → single semantic query | When searching by concept/intent |
| ast-grep | Complex structural refactors | Large-scale code transformations |
These are additive, not competing. A typical 30-minute Claude Code session uses all four.
Script extracts nothing:
patterns dict if neededMCP server not connecting:
# Verify install
python -m mcp_server_tree_sitter --help
# Restart Claude Code after adding MCP server
# Check the server entry in .mcp.json or ~/.claude.json (claude mcp list)
Results are too verbose (too many signatures):
extract-signatures.py src/payments/extract-signatures.py src/ .rs (Rust only)Last updated: March 2026 Compatible with: Claude Code 2.0+ Depends on: Python 3.10+ (Approach B script)
What SKILL.md sets; muted values are Claude Code's defaults
low18 skills in this plugin
/ast-grep-patternsStructural code search and refactoring with ast-grep: choose it over Grep, then write tested pattern and YAML rule recipes. Use when renaming calls or changing an API signature across a large codebase, migrating a framework, or finding code by shape (async functions without try/catch, empty catch blocks, long parameter lists). Not for plain text searches, which Grep handles faster./audit-codebaseCodebase health audit scoring 7 categories with progression plan/check-cache-bugsAudit Claude Code setup for cache bugs (CC#40524): sentinel, --resume/--continue, attribution header + ArkNill B3/B4/B5/design-patternsDetect, suggest, and evaluate GoF design patterns in TypeScript/JavaScript codebases. Use when refactoring code, applying singleton/factory/observer/strategy patterns, reviewing pattern quality, or finding stack-native alternatives for React, Angular, NestJS, and Vue./diagnoseInteractive troubleshooting assistant for Claude Code issues/eval-skillsAudit a project or library of skills for metadata, trigger boundaries, workflow completion criteria, local resource closure, instruction economy, tool scope, effort, and routing evidence. Use before shipping skills, after importing a skill collection, or when a skill triggers too often or not at all.npx claudepluginhub florianbruniaux/claude-code-plugins --plugin code-qualityOther plugins' skills for the same job