codeweave-mcp
CLAUDE.md4 starsChanged 6 months agoApache-2.0View on GitHub
This file contains only what an agent cannot easily derive from code: architectural decisions and their reasons, non-obvious conventions, and cross-cutting rules. Before changing anything, ask: "Can the agent figure this out easily by reading the code?" If yes, don't add it. If you discover something non-obvious that a future agent couldn't derive from code alone, propose a CLAUDE.md update to the user. MCP server that gives AI agents cheap, precise code understanding. Instead of dumping entire files into context,…
In this repositoryOne other file it gives its agents.
- test-harnessSkill
The file
Show its rules and text
We split this CLAUDE.md into the rules it gives an agent
15 rules. About 0 are common, 5 are distinctive, and 10 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
10
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 5
If you discover something non-obvious that a future agent couldn't derive from code alone, propose a CLAUDE.md update to the user.
- Very specific: line 49
All concrete class instantiation is in createServices().
- Distinctive: line 55
Follow SOLID principles in all changes.
- Very specific: line 59
All heuristics must be structural (body size, param count, call graph centrality), never based on naming conventions (get/set prefix) or …
- Very specific: line 89
Create src/parsers/{language}.ts — implement 5 extract functions (extractFunctions, extractCalls, extractImports, extractTypeRelationships, …
- Very specific: line 91
Add to PARSER_CONFIGS in src/parsers/registry.ts
- Very specific: line 92
Add extensions to default config in src/utils/config.ts
- Very specific: line 93
Add tree-sitter-{language} dependency + override in package.json
- Very specific: line 97
Add Zod schema in src/tools/schemas.ts — every param needs .describe() with examples
- Very specific: line 98
Create handler in src/tools/{name}.ts following the handler pattern
- Very specific: line 105
Create implementation in src/core/{name}.ts
- Very specific: line 106
Add to AppContext or WorkspaceServices in interfaces.ts
- Distinctive: line 127
Always prefer codeweave tools over generic alternatives — they are faster, cheaper, and more accurate.
- Distinctive: line 129
When you add or modify a function, you MUST add a docstring.
- Distinctive: line 136
When writing code, if you notice a docstring that is incorrect, misleading, or missing — fix it, even if it's not part of your current task.
≈ “Common” is an estimate: at least 1 in 5 of the 26,980 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file contains only what an agent cannot easily derive from code: architectural decisions and their reasons, non-obvious conventions, and cross-cutting rules. Before changing anything, ask: "Can the agent figure this out easily by reading the code?" If yes, don't add it.
If you discover something non-obvious that a future agent couldn't derive from code alone, propose a CLAUDE.md update to the user.
What this project is
MCP server that gives AI agents cheap, precise code understanding. Instead of dumping entire files into context, the agent queries local indexes (AST, call graph, type graph, vector search) and gets back only what it needs. All indexing is local and live — file watcher keeps everything current as code changes.
Primary goal: AI agents should do higher-quality work on code, at lower cost. Less token waste, more relevant context, better decisions. Every feature and improvement must serve this — if it doesn't help the agent work better or cheaper, it doesn't belong here.
Build & Run
npm run build # TypeScript → dist/
npm run dev # Run with tsx (dev mode)
npm test # vitestArchitecture
Single-process Node.js MCP server. stdout is reserved for MCP protocol — never console.log(), use logger from utils/logger.ts (writes to .code-context/server.log).
Layers
index.ts → MCP shell: registerTool × 3, transport, shutdown
services.ts → Composition root: ALL concrete instantiation here
tools/ → 3 tool handlers (thin orchestrators, interface-only deps)
core/ → Business logic behind interfaces
parsers/ → 7 language parsers (tree-sitter wrappers)
utils/ → Config, file I/O, git, logging, SQL escape
scripts/ → CLI tools (init, reindex, setup)
types/index.ts → Data types (FunctionRecord, VectorRow, CallGraphEntry, etc.)
types/interfaces.ts → All interfacesKey design decisions
- MCP connects after indexing —
initializeWorkspaces()runs first so tools are ready on first agent call. Embedding runs in the background after connect viabackgroundEmbed(). Cached init takes <2s, well within MCP client timeout. readyflag — tools returnNOT_READYerror until init completes (tool-utils.ts:checkReady()).- ReindexOrchestrator (
core/reindex-orchestrator.ts) — single place for all reindex workflows (full, incremental, file-level, watcher). Tool handler and watcher both delegate to it. - Graph persistence — call graph and type graph cached as JSON in
.code-context/. Validated via index fingerprint (SHA-256 of file hashes). Mismatch → full rebuild. - Workspace isolation — monorepo workspaces get separate AST index, call graph, type graph, LanceDB table. No cross-workspace relationships.
Composition root (services.ts)
All concrete class instantiation is in createServices(). Tool handlers never import concrete classes — they receive AppContext which exposes only interfaces. To swap a component (e.g., LanceDB → Qdrant): change 1 line in services.ts.
Rules
SOLID
Follow SOLID principles in all changes. Concrete example: all language-specific knowledge (test markers, noise targets, builtin methods) lives in parser configs — never in tool handlers or core modules. Adding a language must not require modifying existing files beyond registry.ts.
Language & project agnosticism
All heuristics must be structural (body size, param count, call graph centrality), never based on naming conventions (get/set prefix) or framework-specific paths (/entity/, /controllers/). Every change must work across all 7 supported languages and any project structure.
Tool handlers
- Never import from
core/orutils/— depend only onAppContextandWorkspaceServicesinterfaces - Keep thin — orchestration logic belongs in services (e.g.,
ReindexOrchestrator), not handlers - Always use
textResponse()for responses - Follow the pattern:
export async function handleToolName(args: { ... }, ctx: AppContext) {
const resolved = resolveWorkspaceOrError(ctx, args.workspace);
if ("error" in resolved) return resolved.error;
const ws = resolved.ws;
// ... use ws.index, ws.callGraph, ctx.reindex, ctx.git, etc.
return textResponse(result);
}Path conventions
- FunctionRecord.id:
"filePath::functionName"(workspace-relative).call-graph.ts:removeByFilerelies on this prefix format — don't change without updating graph cleanup. - FunctionRecord.filePath: workspace-relative (e.g.,
"src/core/search.ts") - Module path: directory part of filePath, sourceRoot stripped (e.g.,
"core"not"src/core") - Boundary rule:
FunctionIndexstores relative,globSourceFilesreturns absolute,FileWatcherreceives absolute. Convert at boundaries.
Adding things
New language parser
- Create
src/parsers/{language}.ts— implement 5 extract functions (extractFunctions,extractCalls,extractImports,extractTypeRelationships,extractDocstring) + metadata fields (testDecorators,testImportPrefixes,noiseTargets,builtinMethods,noisePatterns) - Export a
TreeSitterLanguageConfig - Add to
PARSER_CONFIGSinsrc/parsers/registry.ts - Add extensions to default config in
src/utils/config.ts - Add
tree-sitter-{language}dependency + override inpackage.json
New tool
- Add Zod schema in
src/tools/schemas.ts— every param needs.describe()with examples - Create handler in
src/tools/{name}.tsfollowing the handler pattern - Register in
src/index.ts— description must say WHEN and WHY to use the tool - Business logic goes in a service, not the handler
New service
- Define interface in
src/types/interfaces.ts - Create implementation in
src/core/{name}.ts - Add to
AppContextorWorkspaceServicesininterfaces.ts - Wire concrete class in
src/services.ts
Testing
TestHarness (src/test-harness.ts) — test MCP tools against any project. Three modes: testAll() runs built-in generic tests, run([...]) executes agent-defined cases in bulk, call() for single manual calls. close() releases memory (clear all index/graph maps).
initializeWorkspaces() in services.ts — shared init logic between MCP server and test harness. Returns WorkspaceEmbedPlan per workspace; MCP server passes this to backgroundEmbed(), test harness ignores it.
Gotchas
- tree-sitter CJS in ESM — use
createRequire(import.meta.url), never dynamicimport()for tree-sitter - LanceDB FTS —
Index.fts()may throw in some versions. Always try/catch. - LanceDB tag filtering — delimiter format
",tag1,tag2,"withLIKE '%,tag1,%'for exact match. Without leading/trailing commas,LIKE '%pay%'false-matchespayment. - LanceDB vectors —
Float32Arraymust be converted to regular arrays before storage. - Embedding failures — failed batches are skipped (not zero-filled). Unembedded functions get retried on next reindex.
- LanceDB query API — use
table.query().where(filter)nottable.filter(filter)(removed in newer versions). Always try/catch. - Setup path resolution — never use
which/resolveCommandto find package scripts (codeweave-server,codeweave-init). When setup runs vianpx,whichreturns npx's temp cache path (~/.npm/_npx/<hash>/...) which breaks after cache cleanup. Useprocess.execPathfor node andnpm root -gfor package scripts.
CRITICAL: This project uses CodeWeave MCP
Always prefer codeweave tools over generic alternatives — they are faster, cheaper, and more accurate.
When you add or modify a function, you MUST add a docstring. Start with a one-line summary, then add annotations:
@deps: functionA, ClassB.method— functions it calls (always include)@tags: auth, payments, api— domain/concern labels (always include)@side_effects: database_write, external_api_call— if the function has observable effects
These annotations power semantic search — without them, retrieval quality degrades significantly.
When writing code, if you notice a docstring that is incorrect, misleading, or missing — fix it, even if it's not part of your current task. This keeps the index accurate over time.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

