Skip to content

Anthropic / Claude

import Anthropic from '@anthropic-ai/sdk';
import { CodeIndexer } from '@upstart.gg/lucerna';
const indexer = new CodeIndexer({ projectRoot: process.cwd() });
await indexer.initialize();
await indexer.indexProject();
const tools: Anthropic.Tool[] = [{
name: 'search_code',
description: 'Search the codebase for relevant code or documentation.',
input_schema: {
type: 'object',
properties: {
query: { type: 'string', description: 'Search query' },
limit: { type: 'number', description: 'Max results', default: 5 },
},
required: ['query'],
},
}];
async function handleToolCall(name: string, input: Record<string, unknown>) {
if (name === 'search_code') {
const results = await indexer.search(input.query as string, {
limit: (input.limit as number) ?? 5,
});
return results.map(r => ({
file: r.chunk.filePath,
type: r.chunk.type,
name: r.chunk.name,
lines: `${r.chunk.startLine}${r.chunk.endLine}`,
content: r.chunk.content,
}));
}
}