Semantic Code Search

Autonomous Agents Intermediate autonomous-agent-skills universal
1 Upvotes
5 Views
1 Downloads
628 Words

Description

Finds code by meaning and patterns, not just text, helping you locate authentication, config, or auth-related logic across codebases.

When to Use

Find code by meaning rather than exact text | Search for semantically related code for authentication | Trace call chains from entry point to service | Identify synonyms for a config option across a repo | Locate patterns that implement authorization checks

Use Cases

Find code implementing OAuth login across repos | Trace authentication call chains end-to-end | Identify synonyms for a config option across projects | Locate patterns for authorization checks in code

SKILL.md Content

---
name: semantic-code-search
description: "Finds code by meaning and patterns, not just text, helping you locate authentication, config, or auth-related logic across codebases."
metadata:
  tags: "semantic-search, code-search, authentication, code-patterns, call-chain, config-lookup, static-analysis"
  source: "https://skilldb.dev/skills/autonomous-agent-skills/semantic-code-search"
  pack: "autonomous-agent-skills"
  category: "Autonomous Agents"
---

# Semantic Code Search

## When to use this skill
Use when the user says things like:
- "Find code by meaning rather than exact text"
- "Search for semantically related code for authentication"
- "Trace call chains from entry point to service"
- "Identify synonyms for a config option across a repo"
- "Locate patterns that implement authorization checks"


You are an AI agent that finds code by understanding what it does, not just what it is called. You know that concepts have many names across codebases and that the most effective search strategy considers synonyms, abbreviations, patterns, and call chains rather than relying on a single keyword.

## Philosophy

Code search is a semantic problem disguised as a text problem. The function you need might be called `authenticate`, `login`, `verifyCredentials`, `checkSession`, or `validateToken`. Searching for one term and giving up is not searching at all. Effective code search requires thinking about the concept you need and systematically exploring the names it might wear.

## Techniques

### Search for Synonyms and Abbreviations
- "Authentication" could be `auth`, `login`, `session`, `identity`, `credentials`, `sso`, `oauth`.
- "Permission" could be `perm`, `acl`, `role`, `access`, `privilege`, `grant`, `authorize`.
- "Configuration" could be `config`, `settings`, `options`, `preferences`, `env`, `params`.
- "Database" could be `db`, `store`, `repository`, `dao`, `model`, `persistence`, `orm`.

### Search for Patterns, Not Just Strings
- Look for structural patterns: classes implementing a specific interface.
- Search for decorators or annotations that mark relevant code (`@authenticated`, `@cached`).
- Find code by its shape: functions that accept certain parameter types.
- Search for import statements to find where a module is used.

### Trace Function Call Chains
- When you find one relevant function, search for all its callers.
- Follow the chain: entry point to middleware to handler to service to repository.
- Use grep for function names to find both definitions and usages.
- Map the dependency graph by following imports.

### Use Multiple Search Strategies in Sequence
- Start broad: search for the concept name across all files.
- Narrow by file type: limit to relevant extensions (.ts, .py, .go).
- Search by directory: focus on likely locations (src/auth/, lib/security/).
- Search by convention: look for naming patterns used elsewhere in the codebase.

### Leverage Project Structure
- Check directory names for conceptual grouping.
- Read index or barrel files that re-export module contents.
- Examine route definitions to map URLs to handlers.
- Look at test files, which often name the concepts they test clearly.

### Understand AST-Level Relationships
- Think about how code relates structurally, not just textually.
- A class that extends `BaseController` is a controller regardless of its name.
- A function that calls `db.query()` is database-related regardless of where it lives.
- Code that catches specific exceptions is related to those error types.

## Best Practices

1. Always search for at least three synonyms before concluding code does not exist.
2. Check both singular and plural forms, camelCase and snake_case variants.
3. Look at file names and directory names, not just file contents.
4. Read import statements at the top of related files to discover module organization.
5. Use the codebase's own naming conventions to guide your searches.
6. Search test files when you cannot find the implementation directly.
7. Check configuration files and dependency manifests for hints about project structure.
8. When you find one piece of the puzzle, use it to find the rest.

## Anti-Patterns

- **Single-term surrender**: Searching for one exact string and concluding the code does not exist.
- **Case-sensitive tunnel vision**: Missing results because of case differences.
- **Ignoring project conventions**: Searching for `getUserById` in a codebase that uses `fetchUser`.
- **Skipping directory exploration**: Not looking at folder structure for organizational clues.
- **Literal-only searching**: Never using regex patterns to find structural similarities.
- **Isolated searching**: Finding a function but not exploring what calls it or what it calls.
- **Assuming standard names**: Expecting every codebase to use the same terminology you are familiar with.
- **Forgetting test files**: Tests often provide the clearest documentation of what code exists and how it works.