Claude Context

repository·master·Indexed 11 days ago

https://github.com/zilliztech/claude-context

An MCP plugin and code indexing tool that enables semantic code search for AI coding agents like Claude Code. It utilizes a vector database to allow agents to access relevant parts of large codebases more efficiently than traditional grep-based methods. The project includes an MCP Server (@zilliz/claude-context-mcp), a VSCode extension (semanticcodesearch), a core package (@zilliz/claude-context-core), and a Chrome extension for GitHub code vector search.

Tokens
48.1K
Snippets
150
Records
227
Agent score
93%

What's inside Claude Context

  1. Overview of Claude Context

    master

    Claude Context is an MCP (Model Context Protocol) plugin designed to provide semantic code search capabilities to Claude Code and other AI coding agents.

    Key benefits include:

    • Full Codebase Context: Uses semantic search to retrieve relevant code snippets from large codebases, eliminating the need for manual multi-round discovery.
    • Cost Efficiency: Instead of feeding entire directories into the LLM context (which is expensive), it stores the codebase in a vector database and only injects the most relevant code segments into the context window.
    • Integration: Works via the Model Context Protocol (MCP) to connect with AI assistants like Claude Code.
  2. Features of Claude Context MCP

    master

    The Claude Context MCP server provides several key capabilities for AI-assisted coding:

    • Hybrid Code Search: Combines BM25 and dense vector search for natural language queries.
    • Codebase Indexing: Indexes entire codebases for high-scale search.
    • Incremental Indexing: Uses Merkle trees to re-index only changed files.
    • Intelligent Chunking: Uses AST-based analysis for syntax-aware code chunking.
    • Scalability: Integrates with Zilliz Cloud for large-scale vector search.
    • MCP Compliance: Fully compatible with any MCP-enabled assistant using stdio transport.
  3. Overview of Claude Context core components

    master

    Claude Context is a monorepo designed to provide codebase context to AI agents and developers. It consists of three primary pillars:

    1. @zilliz/claude-context-core: The engine responsible for indexing (using AST-based chunking and Merkle trees for incremental updates) and semantic search (hybrid BM25 + dense vector).
    2. VSCode Extension: A user interface for semantic code search within the IDE.
    3. @zilliz/claude-context-mcp: A Model Context Protocol (MCP) server that allows AI agents (like Claude Code) to interact with your codebase via semantic search.

    Supported Technologies:

    • Embedding Providers: OpenAI, VoyageAI, Ollama, Gemini.
    • Vector Databases: Milvus or Zilliz Cloud.
    • Languages: TypeScript, JavaScript, Python, Java, C++, C#, Go, Rust, PHP, Ruby, Swift, Kotlin, Scala, Markdown.
  4. How incremental file synchronization works

    master

    Claude Context uses a Merkle tree-based approach combined with SHA-256 file hashing to detect changes, allowing for efficient incremental updates instead of full re-indexing.

    The Process

    1. File Hashing: Every file is hashed using SHA-256 based on content.
    2. Merkle Tree Construction: Hashes are organized into a Merkle tree. A single root hash represents the entire codebase state.
    3. Snapshot Management: State is persisted in ~/.context/merkle/. Each codebase has a unique snapshot based on its absolute path hash.
    4. Change Detection:
      • A quick check compares the current Merkle root hash with the stored snapshot.
      • If they differ, a file-by-file comparison identifies Added, Modified, or Removed files.
    5. Incremental Updates: Only changed files are processed. The vector database is updated only for modified chunks, and entries for deleted files are removed.
  5. Explore Claude Context components

    master

    Claude Context is composed of several key packages depending on your integration needs:

    • MCP Server (@zilliz/claude-context-mcp): The Model Context Protocol server that enables Claude and other MCP-compatible clients to access semantic search.
    • VSCode Extension (semanticcodesearch): A VSCode extension that provides semantic code search directly within the editor.
    • Core Package (@zilliz/claude-context-core): The foundational logic and core functionality of the project.
  6. How the asynchronous indexing workflow works

    master

    Claude Context MCP uses an asynchronous background process for codebase indexing. When you trigger an indexing task, the server returns an immediate response, allowing the agent to continue working while the actual heavy lifting (scanning, chunking, and embedding) happens in the background. This non-blocking approach allows you to perform searches and monitor progress without waiting for the entire process to complete.

    Key characteristics:

    • Non-blocking: The agent receives an immediate response upon starting indexing.
    • Progressive Search: You can use search_code to find results even while indexing is still in progress (though results may be partial).
    • Persistence: Progress is periodically saved to a local snapshot file at ~/.context/mcp-codebase-snapshot.json.
  7. Identify codebases by absolute path

    master

    Claude Context identifies and tracks codebases using their resolved absolute path.

    Important considerations:

    • Path Resolution: All MCP tools (index_codebase, search_code, clear_index, get_indexing_status) resolve relative paths to absolute paths before performing operations.
    • Identity: Collection identity is derived from the normalized absolute path.
    • Avoid Duplicates: If you access the same repository via different paths (e.g., through a symlink, a different clone, or a different mount point), Claude Context will treat them as separate, distinct codebases.

    Tip: To ensure consistent behavior, always use the same absolute path for all indexing and search operations.

  8. Understand file inclusion and exclusion rules

    master

    Claude Context determines which files to index using an additive rule system. The final set of files is calculated as:

    Final Files = (All Supported Extensions) - (All Ignore Patterns)

    Extensions

    Extensions are additive, combining:

    • Default extensions
    • MCP custom extensions
    • Extensions defined via environment variables

    Ignore Patterns

    Ignore patterns are also additive, combining:

    • Default patterns
    • MCP custom patterns
    • Patterns defined via environment variables
    • .gitignore files
    • .xxxignore files
    • Global .contextignore files
  9. How Claude Context handles multiple projects

    master

    Claude Context supports multiple codebases by leveraging MCP client workspace awareness.

    Key Behaviors

    • Automatic Path Detection: In MCP mode, it identifies the current working directory automatically.
    • Seamless Switching: It detects when you switch between different codebases without manual path input.
    • Background Sync: It monitors for changes and re-indexes modified parts automatically.
    • Path-Based Indexing: Claude Context keys each codebase by its absolute path.

    Warning: If you access the same repository via different paths (e.g., a symlink, a different clone, or a mounted path), Claude Context will treat them as separate, isolated indexed codebases.

  10. Understand indexing progress calculation

    master

    The get_indexing_status tool reports a coarse, phase-based percentage rather than an exact count of files completed. It is normal to see large jumps in percentage (e.g., jumping from 5% to 10% quickly).

    Progress Phases:

    • 0%: Preparing the target collection and validating prerequisites.
    • ~5%: Scanning the codebase and building the file list.
    • 10% → 100%: Processing files, chunking code, generating embeddings, and writing batches to the vector database.
    • 100%: Indexing finished successfully.
  11. Understand the Claude Context vs. Grep Case Study methodology

    master

    The evaluation/case_study directory contains comparative analyses between two methods of navigating codebases for LLM agents:

    1. Traditional Grep-only method: Relies on literal text matching.
    2. Grep + Claude Context semantic search method: Combines literal matching with semantic understanding.

    These studies use cases from the SWE-bench_Verified dataset. Each case study folder contains:

    • Original Issue: GitHub issue description and requirements.
    • Problem Analysis: Technical breakdown of the bug and expected solution.
    • Method Comparison: Detailed comparison of both approaches.
    • Conversation Logs: Interaction records showing how the LLM agent calls the tools and generates answers.
    • Results: Performance metrics and outcome analysis.

    To generate these results and logs yourself, use the run_evaluation.py script located in the parent directory.

  12. How file inclusion and exclusion works in Claude Context

    master

    Claude Context determines which files to index using a specific mathematical rule: it takes the union of all supported file extensions and subtracts the union of all ignore patterns.

    The Core Rule: Final Files = (All Supported Extensions) - (All Ignore Patterns)

    Supported Extensions (Additive)

    Extensions are gathered from three sources:

    1. Default Extensions: Built-in support for common programming languages (e.g., .ts, .py, .go, .rs) and documentation (e.g., .md, .ipynb).
    2. MCP Custom Extensions: Extensions provided dynamically via the MCP customExtensions parameter.
    3. Environment Variable Extensions: Extensions defined in the CUSTOM_EXTENSIONS environment variable.

    Ignore Patterns (Additive)

    Files are excluded if they match patterns from any of these sources:

    1. Default Ignore Patterns: Built-in exclusions for build outputs (node_modules/**, dist/**), IDE files (.vscode/**), version control (.git/**), caches, logs, and minified files.
    2. MCP Custom Ignore Patterns: Patterns provided via the MCP ignorePatterns parameter.
    3. Environment Variable Ignore Patterns: Patterns defined in the CUSTOM_IGNORE_PATTERNS environment variable.
    4. .gitignore Files: Standard Git ignore patterns found in the codebase root.
    5. .xxxignore Files: Any file in the codebase root matching the pattern .xxxignore (e.g., .cursorignore, .contextignore).
    6. Global .contextignore: User-wide patterns located at ~/.context/.contextignore.