Best use case
search-hierarchy is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Search Tool Hierarchy
Teams using search-hierarchy should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/search-hierarchy/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How search-hierarchy Compares
| Feature / Agent | search-hierarchy | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Search Tool Hierarchy
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Search Tool Hierarchy
Use the most token-efficient search tool for each query type.
## Decision Tree
```
Query Type?
├── STRUCTURAL (code patterns)
│ → AST-grep (~50 tokens output)
│ Examples: "def foo", "class Bar", "import X", "@decorator"
│
├── SEMANTIC (conceptual questions)
│ → LEANN (~100 tokens if path-only)
│ Examples: "how does auth work", "find error handling patterns"
│
├── LITERAL (exact identifiers)
│ → Grep (variable output)
│ Examples: "TemporalMemory", "check_evocation", regex patterns
│
└── FULL CONTEXT (need complete understanding)
→ Read (1500+ tokens)
Last resort after finding the right file
```
## Token Efficiency Comparison
| Tool | Output Size | Best For |
|------|-------------|----------|
| AST-grep | ~50 tokens | Function/class definitions, imports, decorators |
| LEANN | ~100 tokens | Conceptual questions, architecture, patterns |
| Grep | ~200-2000 | Exact identifiers, regex, file paths |
| Read | ~1500+ | Full understanding after finding the file |
## Hook Enforcement
The `grep-to-leann.sh` hook automatically:
1. Detects query type (structural/semantic/literal)
2. Blocks and suggests AST-grep for structural queries
3. Blocks and suggests LEANN for semantic queries
4. Allows literal patterns through to Grep
## DO
- Start with AST-grep for code structure questions
- Use LEANN for "how does X work" questions
- Use Grep only for exact identifier matches
- Read files only after finding them via search
## DON'T
- Use Grep for conceptual questions (returns nothing)
- Read files before knowing which ones are relevant
- Use Read when AST-grep would give file:line
- Ignore hook suggestions
## Examples
```bash
# STRUCTURAL → AST-grep
ast-grep --pattern "async def $FUNC($$$):" --lang python
# SEMANTIC → LEANN
leann search opc-dev "how does authentication work" --top-k 3
# LITERAL → Grep
Grep pattern="check_evocation" path=opc/scripts
# FULL CONTEXT → Read (after finding file)
Read file_path=opc/scripts/z3_erotetic.py
```
## Optimal Flow
```
1. AST-grep: "Find async functions" → 3 file:line matches
2. Read: Top match only → Full understanding
3. Skip: 4 irrelevant files → 6000 tokens saved
```Related Skills
search-tools
Search Tool Hierarchy
search-router
Choose the right search tool for each query type
research
Document codebase as-is with thoughts directory for historical context
research-external
External research workflow for docs, web, APIs - NOT codebase exploration
research-agent
Research agent for external documentation, best practices, and library APIs via MCP tools
repo-research-analyst
Analyze repository structure, patterns, conventions, and documentation for understanding a new codebase
perplexity-search
AI-powered web search, research, and reasoning via Perplexity
morph-search
Fast codebase search via WarpGrep (20x faster than grep)
loogle-search
Search Mathlib for lemmas by type signature pattern using Loogle.
github-search
Search GitHub code, repositories, issues, and PRs via MCP
elasticsearch-patterns
Mapping design, query optimization, aggregation patterns, index lifecycle management, and search relevance tuning.
workflow-router
Goal-based workflow orchestration - routes tasks to specialist agents based on user goals