$npx -y skills add parcadei/Continuous-Claude-v3 --skill search-hierarchySearch Tool Hierarchy
| 1 | # Search Tool Hierarchy |
| 2 | |
| 3 | Use the most token-efficient search tool for each query type. |
| 4 | |
| 5 | ## Decision Tree |
| 6 | |
| 7 | ``` |
| 8 | Query Type? |
| 9 | ├── STRUCTURAL (code patterns) |
| 10 | │ → AST-grep (~50 tokens output) |
| 11 | │ Examples: "def foo", "class Bar", "import X", "@decorator" |
| 12 | │ |
| 13 | ├── SEMANTIC (conceptual questions) |
| 14 | │ → LEANN (~100 tokens if path-only) |
| 15 | │ Examples: "how does auth work", "find error handling patterns" |
| 16 | │ |
| 17 | ├── LITERAL (exact identifiers) |
| 18 | │ → Grep (variable output) |
| 19 | │ Examples: "TemporalMemory", "check_evocation", regex patterns |
| 20 | │ |
| 21 | └── FULL CONTEXT (need complete understanding) |
| 22 | → Read (1500+ tokens) |
| 23 | Last resort after finding the right file |
| 24 | ``` |
| 25 | |
| 26 | ## Token Efficiency Comparison |
| 27 | |
| 28 | | Tool | Output Size | Best For | |
| 29 | |------|-------------|----------| |
| 30 | | AST-grep | ~50 tokens | Function/class definitions, imports, decorators | |
| 31 | | LEANN | ~100 tokens | Conceptual questions, architecture, patterns | |
| 32 | | Grep | ~200-2000 | Exact identifiers, regex, file paths | |
| 33 | | Read | ~1500+ | Full understanding after finding the file | |
| 34 | |
| 35 | ## Hook Enforcement |
| 36 | |
| 37 | The `grep-to-leann.sh` hook automatically: |
| 38 | 1. Detects query type (structural/semantic/literal) |
| 39 | 2. Blocks and suggests AST-grep for structural queries |
| 40 | 3. Blocks and suggests LEANN for semantic queries |
| 41 | 4. Allows literal patterns through to Grep |
| 42 | |
| 43 | ## DO |
| 44 | |
| 45 | - Start with AST-grep for code structure questions |
| 46 | - Use LEANN for "how does X work" questions |
| 47 | - Use Grep only for exact identifier matches |
| 48 | - Read files only after finding them via search |
| 49 | |
| 50 | ## DON'T |
| 51 | |
| 52 | - Use Grep for conceptual questions (returns nothing) |
| 53 | - Read files before knowing which ones are relevant |
| 54 | - Use Read when AST-grep would give file:line |
| 55 | - Ignore hook suggestions |
| 56 | |
| 57 | ## Examples |
| 58 | |
| 59 | ```bash |
| 60 | # STRUCTURAL → AST-grep |
| 61 | ast-grep --pattern "async def $FUNC($$$):" --lang python |
| 62 | |
| 63 | # SEMANTIC → LEANN |
| 64 | leann search opc-dev "how does authentication work" --top-k 3 |
| 65 | |
| 66 | # LITERAL → Grep |
| 67 | Grep pattern="check_evocation" path=opc/scripts |
| 68 | |
| 69 | # FULL CONTEXT → Read (after finding file) |
| 70 | Read file_path=opc/scripts/z3_erotetic.py |
| 71 | ``` |
| 72 | |
| 73 | ## Optimal Flow |
| 74 | |
| 75 | ``` |
| 76 | 1. AST-grep: "Find async functions" → 3 file:line matches |
| 77 | 2. Read: Top match only → Full understanding |
| 78 | 3. Skip: 4 irrelevant files → 6000 tokens saved |
| 79 | ``` |