clangd-mcp-server: Instructions file for Claude Code

CLAUDE.md

clangd-mcp-server CLAUDE.md is an instructions file for Claude Code from felipeerias/clangd-mcp-server. It costs 669 tokens per session, scanned A, original, MPL-2.0.

Project instructions for a server that connects Claude Code to clangd, a C++ code-analysis service. It explains how to add tools for finding definitions, references, and other code information through the Language Server Protocol.

In plain words
What is it for?
Use it when developing or extending the clangd MCP server, especially when adding LSP tools, registering them, building the project, or handling files and results.
Why use it?
It records the repository’s required patterns and common mistakes, such as mixing file paths with resource addresses or using the wrong position format.

Instructions file for Claude Code

Written for Claude Code: the file is CLAUDE.md. Also seen: mentions CLAUDE.md; mentions Claude Code.

This is felipeerias/clangd-mcp-server's own configuration. It tells Claude Code how to work on clangd-mcp-server itself, so it is not a mod to install elsewhere. Copy it as a starting point and replace the rules that are about this project. Everything clangd-mcp-server configures →

Reuse

Borrowing it

Nothing to install: this file belongs to felipeerias/clangd-mcp-server. Take a copy, put it at the same path in your own repository, and replace the rules that are about this project with yours.

Copy the file
curl -O https://raw.githubusercontent.com/felipeerias/clangd-mcp-server/main/CLAUDE.md
Clone the repo
git clone --depth 1 https://github.com/felipeerias/clangd-mcp-server

Made for: Claude Code.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for clangd-mcp-server CLAUDE.md

README.md
[![agentmods](https://agentmods.dev/badge/instructions/felipeerias/clangd-mcp-server/claude-md/github.svg)](https://agentmods.dev/instructions/felipeerias/clangd-mcp-server/claude-md)
Your own site
<a href="https://agentmods.dev/instructions/felipeerias/clangd-mcp-server/claude-md"><img src="https://agentmods.dev/badge/instructions/felipeerias/clangd-mcp-server/claude-md/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for clangd-mcp-server CLAUDE.md

Your own site · 80×15
<a href="https://agentmods.dev/instructions/felipeerias/clangd-mcp-server/claude-md"><img src="https://agentmods.dev/badge/instructions/felipeerias/clangd-mcp-server/claude-md.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 669 This file is loaded in full into every session.
When invoked 669 The same file — it is already loaded in full.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00669 $0.00669
Opus 5.5 $0.00268 $0.00268
Sonnet 5.5 $0.00134 $0.00134
Haiku 4.5 $0.00067 $0.00067

Measured 2mo ago against content hash ff264944fc12, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

clangd-mcp-server CLAUDE.md scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

CLAUDE.md · 54 lines

How it starts

The opening of the file, as written. The whole thing — 54 lines — stays where its author put it; the contents beside it link to each section on GitHub.

CLAUDE.md

Guidance for Claude Code when working with this MCP server codebase.

Project Overview

MCP server that bridges Claude Code with clangd LSP for C++ code intelligence on large codebases (Chromium-scale). Production-ready with 6 tools, crash recovery, and lazy initialization.

Critical Patterns

Adding New LSP Tools

  1. Create src/tools/your-tool.ts with MPL-2.0 header
  2. Follow pattern: fileTracker.ensureFileOpen() → withRetry(() => lspClient.request()) → return JSON string
  3. Register in src/index.ts: import, add to ListToolsRequestSchema, add case to CallToolRequestSchema
  4. Build with npm run build

See existing tools (find-definition.ts, find-references.ts) for examples.

Key Gotchas

  • URI handling: Always use normalizeToUri()/uriToPath() from utils/uri.ts, never mix paths and URIs
  • File lifecycle: Must call fileTracker.ensureFileOpen() before any file-based LSP request
  • LSP results: textDocument/definition returns Location | Location[] | null - normalize to array
  • Imports: Must use .js extension (ES modules), not .ts
  • Positions: LSP uses 0-indexed line/column

Architecture Notes

  • ClangdManager (src/clangd-manager.ts): Subprocess lifecycle, auto-restart on crash (max 3 attempts)
  • LSPClient (src/lsp-client.ts): JSON-RPC over stdio, Content-Length framing, request correlation
  • FileTracker (src/file-tracker.ts): Manages didOpen/didClose, prevents duplicates
  • ConfigDetector (src/config-detector.ts): Auto-detects compile_commands.json, project type detection, and project bundled clangd (Chromium auto-detected, others via CLANGD_PATH)

Data flow: MCP request → index.ts routes → FileTracker opens file → LSPClient sends request → format response

Design Decisions

  • Background indexing OFF by default: MCP sporadic queries don't benefit, saves GBs of memory
  • Lazy initialization: clangd starts on first query, not at server startup
  • ES modules: Required by MCP SDK, all imports need .js extension
  • Retry logic: Exponential backoff for transient LSP errors (100ms → 200ms → 400ms, max 3 attempts)
  • Project bundled clangd: Auto-detects project bundled clangd (Chromium supported via .gclient detection) and allows manual specification via CLANGD_PATH for other projects, with version validation and warnings

Read the full file on GitHub · 54 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2mo ago First seen · 54 lines · 669 tokens per session scan A ff264944fc12

Subscribe to this mod's changes

clangd-mcp-server CLAUDE.md is an instructions file published in the GitHub repository felipeerias/clangd-mcp-server (50 stars, last pushed 11mo ago), licensed MPL-2.0. It adds 669 tokens to every session, about $0.0027 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

clangd-mcp-server CLAUDE.md compared with instructions from other repositories

clangd-mcp-server CLAUDE.md next to 6 instructions from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
clangd-mcp-server CLAUDE.mdfelipeerias/clangd-mcp-serverInstructions file5011mo agoMPL-2.0A669Claude Code
vscode buildNext.instructions.mdmicrosoft/vscodeInstructions file195kyesterdayMITA9,719GitHub Copilot
next.js AGENTS.mdvercel/next.jsInstructions file143kyesterdayMITA7,461Codex, OpenCode
langchain AGENTS.mdlangchain-ai/langchainInstructions file149kyesterdayMITA4,680Codex, OpenCode
vscode oss-third-party-notices.instructions.mdmicrosoft/vscodeInstructions file195kyesterdayMITA5,516GitHub Copilot
vscode copilot-instructions.mdmicrosoft/vscodeInstructions file195kyesterdayMITA3,093GitHub Copilot
deepseek-harness AGENTS.mddeepseek-ai/deepseek-harnessInstructions file274k2d agoMITA4,313Codex, OpenCode