mcpbeat Sign in

Code Search Assistant Agent Skill

Search code repositories for code related to a given code snippet, ranking results by call chain similarity, textual similarity, and functional similarity. Use when finding related code, locating similar implementations, discovering code dependencies, or identifying code that performs similar operations. Outputs ranked file lists with matching code snippets and relevance scores.

2k tokens
context cost
the whole folder, loaded on every use
1
files
instructions only
0
copies elsewhere
how many repositories repackaged it
141
stars on the repo
on the repository, not the skill itself

Install

one command, takes just this skill from the repository
npx skills add https://github.com/ArabelaTso/Skills-4-SE --skill code-search-assistant

The instruction itself

13 sections, as written by the author

Code Search Assistant

Overview

Search codebases to find code related to a given snippet using multi-dimensional similarity analysis: call chain patterns, textual structure, and functional behavior. Results are ranked and presented with matching code snippets.

Workflow

1. Analyze Input Snippet

Extract key characteristics from the provided code snippet:

Structural elements:

  • Function/method calls made
  • Classes/types used
  • Control flow patterns (loops, conditionals, try-catch)
  • Data structures (arrays, objects, maps)

Functional elements:

  • Purpose/intent of the code
  • Input/output behavior
  • Side effects (I/O, state changes, API calls)
  • Domain concepts (authentication, validation, transformation)

Textual elements:

  • Variable and function names
  • String literals and constants
  • Comments and documentation
  • Code tokens and keywords

2. Define Search Scope

Determine where to search:

  • Full repository: Search all code files
  • Specific directories: Focus on relevant modules
  • File type filter: Limit to specific languages

Use Glob to identify candidate files:

**/*.js, **/*.py, **/*.java, etc.

3. Search by Call Chain Similarity

Find code with similar function call patterns and dependencies.

Search strategy:

  • Extract function/method calls from input snippet
  • Use Grep to find files containing those function calls
  • Read matching files to analyze call sequences
  • Score based on:
  • Number of shared function calls (weight: 40%)
  • Order of function calls (weight: 30%)
  • Shared imported modules/libraries (weight: 30%)

Example:

// Input snippet calls: fetch(), JSON.parse(), setState()
// High match: Code that calls fetch() → JSON.parse() → setState()
// Medium match: Code that calls fetch() and setState() in different order
// Low match: Code that only calls fetch()

4. Search by Textual Similarity

Find code with similar structure and token patterns.

Search strategy:

  • Extract key identifiers from input snippet (function names, variable names)
  • Use Grep to find files with similar identifiers
  • Read matching files to compare code structure
  • Score based on:
  • Shared variable/function names (weight: 35%)
  • Similar control flow structure (weight: 35%)
  • Shared keywords and operators (weight: 30%)

Similarity indicators:

  • Same loop patterns (for, while, forEach, map)
  • Similar conditional logic (if-else chains, switch statements)
  • Matching data structure operations (array methods, object access)
  • Similar string/number operations

5. Search by Functional Similarity

Find code that performs similar operations or solves similar problems.

Search strategy:

  • Identify the functional purpose of input snippet
  • Search for code with similar purpose using semantic patterns
  • Look for:
  • Similar input/output transformations
  • Equivalent algorithms (different implementations, same result)
  • Parallel business logic
  • Alternative approaches to same problem

Functional categories:

  • Data transformation: Mapping, filtering, reducing, sorting
  • Validation: Input checking, format validation, constraint enforcement
  • I/O operations: File reading/writing, API calls, database queries
  • Authentication/Authorization: Login, permission checks, token handling
  • Error handling: Try-catch patterns, error recovery, logging

Search patterns:

// For validation code, search for:
- "validate", "check", "verify" in function names
- Conditional checks with error throwing
- Regular expression patterns

// For API calls, search for:
- HTTP client usage (fetch, axios, requests)
- Endpoint URLs or API patterns
- Response handling and error cases

6. Rank and Score Results

Combine similarity scores to rank results:

Scoring formula:

Total Score = (Call Chain Score × 0.35) +
              (Textual Score × 0.30) +
              (Functional Score × 0.35)

Score ranges:

  • 0.8-1.0: Very high similarity (likely duplicate or variant)
  • 0.6-0.8: High similarity (related implementation)
  • 0.4-0.6: Medium similarity (similar patterns or purpose)
  • 0.2-0.4: Low similarity (some shared elements)
  • 0.0-0.2: Minimal similarity (weak connection)

Ranking adjustments:

  • Boost files in same directory (+10%)
  • Boost files with similar names (+5%)
  • Penalize test files (-10%) unless input is a test
  • Penalize generated/vendor code (-20%)

7. Format Results

Present results in ranked order with context:

Result format:

## Search Results for: [Brief snippet description]

### 1. [file_path] (Score: 0.85)

**Similarity breakdown**:
- Call chain: 0.90 (shares fetch, JSON.parse, setState calls)
- Textual: 0.75 (similar variable names and structure)
- Functional: 0.90 (performs same data fetching and state update)

**Matching code** (lines 45-62):

[relevant code snippet from the file]


**Why it matches**: [Brief explanation of similarity]

---

### 2. [file_path] (Score: 0.72)
[... repeat format ...]

Output guidelines:

  • Show top 10 results by default
  • Include file path with line numbers
  • Show relevant code snippet (10-20 lines)
  • Explain why each result matches
  • Group results by score tier if many results

Search Optimization Tips

For better call chain matching:

  • Include import statements in input snippet
  • Provide complete function calls with arguments
  • Include chained method calls

For better textual matching:

  • Use descriptive variable names in input
  • Include comments describing intent
  • Provide complete code blocks, not fragments

For better functional matching:

  • Describe what the code does in comments
  • Include typical input/output examples
  • Show error handling patterns

Example Usage

Input snippet:

async function fetchUserData(userId) {
  try {
    const response = await fetch(`/api/users/${userId}`);
    const data = await response.json();
    return data;
  } catch (error) {
    console.error('Failed to fetch user:', error);
    return null;
  }
}

Search process:

  • Call chain: Search for fetch(), response.json(), console.error()
  • Textual: Search for async functions with try-catch, similar variable names
  • Functional: Search for API data fetching patterns, error handling

Expected results:

  • Other API fetch functions (high similarity)
  • Data retrieval functions using different libraries (medium similarity)
  • Functions with similar error handling (low-medium similarity)

Tips

  • Start with a complete, representative code snippet (10-30 lines)
  • Include context (imports, surrounding code) for better matching
  • For large codebases, narrow search scope to relevant directories
  • Adjust score weights based on what matters most (calls vs. structure vs. purpose)
  • Review medium-scored results (0.4-0.6) for unexpected but useful matches
  • Use results to discover alternative implementations or refactoring opportunities

Other skills for the same job

different authors, same section of the catalogue
MCP Builder
by anthropics
vendor ×13

Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).

30k tokens scripts
Changelog Generator
by frostant
×9

Automatically creates user-facing changelogs from git commits by analyzing commit history, categorizing changes, and transforming technical commits into clear, customer-friendly release notes. Turns hours of manual changelog writing into minutes of automated generation.

774 tokens
Finishing A Development Branch
by ZhanlinCui
×7

Use when implementation is complete, all tests pass, and you need to decide how to integrate the work - guides completion of development work by presenting structured options for merge, PR, or cleanup

1k tokens
MCP Builder
by JayZeeDesign
×7

Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).

37k tokens scripts
Vercel React Native Skills
by vercel-labs
vendor ×6

React Native and Expo best practices for building performant mobile apps. Use when building React Native components, optimizing list performance, implementing animations, or working with native modules. Triggers on tasks involving React Native, Expo, mobile performance, or native platform APIs.

39k tokens
Vercel React Best Practices
by ratacat
×5

React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.

34k tokens
Next Best Practices
by vercel-labs
vendor ×4

Next.js best practices - file conventions, RSC boundaries, data patterns, async APIs, metadata, error handling, route handlers, image/font optimization, bundling

20k tokens
Using Git Worktrees
by ZhanlinCui
×4

Use when starting feature work that needs isolation from current workspace or before executing implementation plans - creates isolated git worktrees with smart directory selection and safety verification

1k tokens

How to use it

Copy the folder

Take arabelatso/code-search-assistant from the repository into ~/.claude/skills for personal use, or into .claude/skills inside a project.

Check the name does not clash

The agent identifies a skill by the name field in its header. Two skills with the same name cannot sit side by side — one of them will be ignored.