Usage Examples
Relevant source files
The following files were used as context for generating this wiki page:
Claude Context provides multiple ways to integrate semantic code search into development workflows, ranging from low-level API usage to high-level IDE extensions and agent protocols. The usage examples demonstrate how to leverage the core indexing engine, vector databases, and embedding providers to achieve context-aware code discovery.
The project supports three primary integration tiers: the Core SDK for custom application building, the Model Context Protocol (MCP) for AI agents like Claude Code, and IDE Extensions (VSCode and Chrome) for direct developer interaction within the browser or editor.
Sources: README.md:165-175, packages/core/README.md:14-18, packages/mcp/README.md:10-15
Core API Usage
The @zilliz/claude-context-core package allows developers to programmatically index codebases and perform semantic searches. This requires initializing an embedding provider (e.g., OpenAI, VoyageAI) and a vector database (Milvus/Zilliz Cloud).
Basic Initialization and Search
To use the core library, you must configure the Context instance with a vector database connection and an embedding provider.
import { Context, MilvusVectorDatabase, OpenAIEmbedding } from '@zilliz/claude-context-core';
// 1. Setup Embedding and Vector DB
const embedding = new OpenAIEmbedding({
apiKey: process.env.OPENAI_API_KEY,
model: 'text-embedding-3-small'
});
const vectorDatabase = new MilvusVectorDatabase({
address: process.env.MILVUS_ADDRESS,
token: process.env.MILVUS_TOKEN
});
// 2. Initialize Context
const context = new Context({ embedding, vectorDatabase });
// 3. Index and Search
const stats = await context.indexCodebase('./my-project');
const results = await context.semanticSearch('./my-project', 'authentication logic', 5);
Sources: packages/core/README.md:46-95, examples/basic-usage/index.ts:30-60
Logic Flow for Indexing and Search
The following diagram illustrates the sequence of operations when performing a basic indexing and search task using the Core API.
The Core API handles the complexity of file scanning, AST-based or character-based chunking, and vector database management.
Sources: packages/core/README.md:139-160, examples/basic-usage/index.ts:65-95
Model Context Protocol (MCP) Integration
MCP is the recommended method for providing codebase context to AI agents like Claude Code, Cursor, and Cline. It exposes specialized tools that the agent can call to understand the repository.
MCP Configuration Example (Claude Code)
To add Claude Context to Claude Code, environment variables for the embedding provider and vector database must be passed during the MCP server addition.
claude mcp add claude-context \
-e OPENAI_API_KEY=sk-your-key \
-e MILVUS_TOKEN=your-zilliz-key \
-- npx @zilliz/claude-context-mcp@latest
Sources: README.md:65-72, packages/mcp/README.md:155-165
Available MCP Tools
AI agents interact with the following tools provided by the MCP server:
| Tool Name | Purpose | Key Parameters |
|---|---|---|
index_codebase | Indexes a directory for search | path, force, splitter, ignorePatterns |
search_code | Performs natural language search | path, query, limit, extensionFilter |
get_indexing_status | Checks progress of active indexing | path |
clear_index | Removes the index for a path | path |
Sources: packages/mcp/README.md:380-425, README.md:255-275
VSCode Extension Usage
The VSCode extension provides a UI-driven approach to semantic search, allowing users to index their workspace and search via a sidebar or context menu.
Extension Workflow
- Configuration: Users set their
Embedding ProviderandMilvus Addressin VSCode settings. - Indexing: Users trigger "Semantic Code Search: Index Codebase" from the Command Palette.
- Searching: Users enter queries in the sidebar or right-click a code selection to find "Similar Code".
Configuration Summary
The behavior of these usage examples is heavily influenced by environment variables and configuration objects.
| Parameter | Source | Description | Default |
|---|---|---|---|
EMBEDDING_PROVIDER | Env / settings | Provider (OpenAI, VoyageAI, Gemini, Ollama) | OpenAI |
SPLITTER_TYPE | Env / settings | Strategy: ast (syntax-aware) or langchain | ast |
MILVUS_ADDRESS | Env / settings | Endpoint for the vector database | localhost:19530 |
CHUNK_SIZE | Config | Max characters per code chunk | 1000 |
AUTO_SYNC | Extension Settings | Periodic re-indexing of changed files | true |
Sources: packages/core/README.md:115-135, packages/mcp/README.md:60-120, packages/vscode-extension/README.md:120-140
Conclusion
These examples demonstrate the versatility of Claude Context across different environments. Whether through the direct TypeScript API, the MCP server for AI agents, or specialized IDE extensions, the system maintains a consistent flow: chunking code via AST or character logic, generating embeddings via chosen providers, and storing data in Milvus for high-performance similarity retrieval.