home / skills / oimiragieo / agent-studio / code-semantic-search

code-semantic-search skill

/.claude/skills/code-semantic-search

This skill enables fast, meaning-based code search across semantic, structural, and hybrid modes to locate authentication logic, errors, and queries.

npx playbooks add skill oimiragieo/agent-studio --skill code-semantic-search

Review the files below or copy the command above to add this skill to your agents.

Files (11)
SKILL.md
3.4 KB
---
name: code-semantic-search
description: Semantic code search using Phase 1 vector embeddings and Phase 2 hybrid search.
version: 1.0.0
model: sonnet
invoked_by: user
user_invocable: true
tools: [Read, Write, Edit]
---

# Code Semantic Search

## Overview

Semantic code search using Phase 1 vector embeddings and Phase 2
hybrid search (semantic + structural). Find code by meaning, not
just keywords.

**Core principle:** Search code by what it does, not what it's called.

## Phase 2: Hybrid Search

This skill now supports three search modes:

1. **Hybrid (Default)**:
   - Combines semantic + structural search
   - Best accuracy (95%+)
   - Slightly slower but still <150ms
   - Recommended for all searches

2. **Semantic-Only**:
   - Uses only Phase 1 semantic vectors
   - Fastest (<50ms)
   - Good for conceptual searches
   - Use when structure doesn't matter

3. **Structural-Only**:
   - Uses only ast-grep patterns
   - Precise for exact matches
   - Best for finding function/class definitions
   - Use when you need exact structural patterns

### Performance Comparison

| Mode            | Speed  | Accuracy | Best For          |
| --------------- | ------ | -------- | ----------------- |
| Hybrid          | <150ms | 95%      | General search    |
| Semantic-only   | <50ms  | 85%      | Concepts          |
| Structural-only | <50ms  | 100%     | Exact patterns    |
| Phase 1 only    | <50ms  | 80%      | Legacy (fallback) |

## When to Use

**Always:**

- Finding authentication logic without knowing function names
- Searching for error handling patterns
- Locating database queries
- Finding similar code to a concept
- Discovering implementation patterns

**Don't Use:**

- Exact text matching (use Grep instead)
- File name searches (use Glob instead)
- Simple keyword searches (use ripgrep instead)

## Usage Examples

### Hybrid Search (Recommended)

```javascript
// Basic hybrid search
Skill({ skill: 'code-semantic-search', args: 'find authentication logic' });

// With options
Skill({
  skill: 'code-semantic-search',
  args: 'database queries',
  options: {
    mode: 'hybrid',
    language: 'javascript',
    limit: 10,
  },
});
```

### Semantic-Only Search

```javascript
// Fast conceptual search
Skill({
  skill: 'code-semantic-search',
  args: 'find authentication',
  options: { mode: 'semantic-only' },
});
```

### Structural-Only Search

```javascript
// Exact pattern matching
Skill({
  skill: 'code-semantic-search',
  args: 'find function authenticate',
  options: { mode: 'structural-only' },
});
```

## Implementation Reference

**Hybrid Search:** `.claude/lib/code-indexing/hybrid-search.cjs`

**Query Analysis:** `.claude/lib/code-indexing/query-analyzer.cjs`

**Result Ranking:** `.claude/lib/code-indexing/result-ranker.cjs`

## Integration Points

- **developer**: Code exploration, implementation discovery
- **architect**: System understanding, pattern analysis
- **code-reviewer**: Finding similar patterns, consistency checks
- **reverse-engineer**: Understanding unfamiliar codebases
- **researcher**: Research existing implementations

## Memory Protocol (MANDATORY)

**Before starting:**
Read `.claude/context/memory/learnings.md`

**After completing:**

- New pattern -> `.claude/context/memory/learnings.md`
- Issue found -> `.claude/context/memory/issues.md`
- Decision made -> `.claude/context/memory/decisions.md`

> ASSUME INTERRUPTION: If it's not in memory, it didn't happen.

Overview

This skill performs semantic code search that finds code by meaning rather than exact keywords. It uses a two-phase approach: Phase 1 generates vector embeddings and Phase 2 performs a hybrid search combining semantic relevance with structural constraints. The hybrid mode is the default and balances accuracy and speed for most queries.

How this skill works

Phase 1 encodes code and text queries into vector embeddings to capture conceptual similarity. Phase 2 supports three modes: hybrid (semantic + structural ranking), semantic-only (vector similarity), and structural-only (AST-pattern matching) to refine results. Results are ranked for relevance and returned with contextual snippets so you can inspect matches quickly.

When to use it

  • Locate authentication, error handling, or database logic when you don’t know exact names
  • Find code snippets that implement a concept or algorithm across a codebase
  • Discover similar implementations for refactoring or consistency checks
  • Search for patterns where structure matters (use structural-only) or where semantics matter (use semantic-only)
  • Avoid using this for exact text or file-name matches; use grep/glob tools instead

Best practices

  • Use hybrid mode as the default for best balance of accuracy and speed
  • Use semantic-only for fast, conceptual searches and exploratory queries
  • Use structural-only for exact AST-level patterns like function/class definitions
  • Limit results and set language filters to improve precision and performance
  • Record new patterns, issues, and decisions in the memory protocol after searches

Example use cases

  • Find all authentication flows across microservices when function names differ
  • Locate error handling patterns to standardize logging and retry behavior
  • Identify all database query implementations for a migration or audit
  • Search for similar utility functions to consolidate duplicate code
  • Quickly retrieve function or class definitions using structural-only mode

FAQ

Which mode should I use by default?

Use hybrid mode by default for the best accuracy and reliable results; switch to semantic-only for speed or structural-only for exact matches.

Is this a replacement for grep or glob?

No. Use semantic search to find meaning and patterns; use grep for exact text matching and glob for file-name searches.