Semantic Search Skill
When to Use
- •Finding all usages of a function or method
- •Searching for code patterns (error handling, loops, etc.)
- •Locating implementations by purpose rather than exact text
- •Finding files by content patterns
- •Codebase exploration and architecture discovery
- •Identifying refactoring targets
Search Strategies
1. Semantic Search (Function/Purpose)
Use semantic-search for natural language queries about code:
code
Find all functions that handle authentication Where is the database connection configured? How is the API error handling implemented?
2. Pattern Search (grep)
Use grep for exact text patterns and regex:
bash
# Find function definitions
grep -n "func.*authenticate" .
# Find error handling patterns
grep -rn "try.*catch\|except\|throw" .
# Find specific imports
grep -rn "from.*import\|require(" .
3. File Pattern Search (glob)
Use glob to find files by name patterns:
bash
# Find all test files
glob("**/*test*.{js,ts,py}")
# Find configuration files
glob("**/*config*.{json,yaml,yml}")
# Find all TypeScript files
glob("**/*.ts")
4. Code Structure Search (semantic-search_dfg/semantic-search_cfg)
Use for data flow and control flow analysis:
code
Trace how user input flows through authentication What functions call the main API handler?
Step-by-Step Guidance
Quick Search (Most Common)
- •
Start with semantic search - Ask what you're looking for:
codesemantic-search("user authentication flow") - •
Refine with grep if you know the pattern:
codegrep("login|authenticate|credential", {include: ["*.ts", "*.js"]}) - •
Locate the files and read them:
codeglob("**/auth*.ts") read("/path/to/auth.ts")
Deep Search (Architecture Discovery)
- •
Search for main entry points:
codesemantic-search("main function entry point app startup") - •
Trace dependencies:
codesemantic-search_impact("main") - •
Explore related modules:
codegrep("import.*from.*auth", {type: "ts"})
Pattern-Based Search
- •
Identify the pattern type:
- •API endpoints:
router|route|get\(|post\(|api\. - •Database queries:
query|select|insert|update - •Error handling:
catch|except|throw|error
- •API endpoints:
- •
Search with grep:
codegrep("router\\.(get|post|put|delete)", {type: "ts"}) - •
Filter results:
codegrep("SELECT.*FROM", {include: ["*.py", "*.sql"]})
Search Combinations
Find Files Then Search Content
bash
# 1. Find relevant files
glob("**/*controller*.ts")
# 2. Search within those files
grep("authenticate", {paths: ["/found/files"]})
Multi-Pattern Search
bash
# Find files containing multiple patterns
grep("(auth|login|credential)", {include: ["*.ts", "*.js"]})
Exclude Patterns
bash
# Search excluding node_modules and tests
grep("password|secret|api_key", {exclude: ["node_modules", "**/*test*"]})
Output Interpretation
semantic-search Results
Returns structured information:
- •Function/class definitions
- •File paths and line numbers
- •Brief descriptions of what code does
grep Results
Returns matching lines with:
- •File path
- •Line number
- •Matching content
glob Results
Returns array of file paths matching the pattern
Best Practices
- •Start broad, narrow down - Begin with semantic search, refine with patterns
- •Use file type filters - Limit searches to relevant file types
- •Exclude non-source - Skip node_modules, build artifacts, tests when exploring
- •Combine strategies - Use glob + grep for targeted searching
- •Check imports - Understanding imports reveals dependencies
Common Search Patterns
Finding API Endpoints
code
grep("router\\.(get|post|put|delete|patch)", {type: "ts"})
Finding Database Operations
code
grep("(SELECT|INSERT|UPDATE|DELETE).*FROM", {type: "ts"})
Finding Error Handling
code
grep("catch|throw|Error\\(|new Error", {include: ["*.ts", "*.js"]})
Finding Configuration
code
glob("**/{config,settings}.{json,yaml,yml,js,ts}")
Finding Tests for a File
code
glob("**/*" + baseName + "*.test.{js,ts}")
Resources
Related Skills
- •
git-master- Git operations and history exploration - •
code-analyzer- Deep code analysis and refactoring - •
test-generator- Generate tests for found code