claude-mesh
Enables two live Claude Code instances on the same workstation to exchange synchronous questions and answers via a shared SQLite file.
README
claude-mesh
claude-mesh lets two live Claude Code instances on the same workstation exchange a synchronous question/answer. One Claude can call ask_peer and block until a peer Claude replies via reply_to_peer — coordination happens through a shared local SQLite file that each instance opens directly and polls for replies. No database server, no daemon.
See the design spec for the architecture, and the SQLite backend addendum for the current storage/wakeup mechanism (which supersedes the Postgres + LISTEN/NOTIFY backend the original spec describes).
Install
claude-mesh isn't published to npm. Clone it once on your workstation and build:
git clone <repo-url> ~/src/claude-mesh
cd ~/src/claude-mesh
npm install
npm run build
npm install fetches a prebuilt better-sqlite3 binary (no compiler needed on mainstream macOS/Linux x64/arm64; Alpine/musl would need a build). That leaves you with executable artifacts at:
~/src/claude-mesh/dist/mcp-server.mjs~/src/claude-mesh/dist/hooks/session-start.mjs~/src/claude-mesh/dist/hooks/session-end.mjs~/src/claude-mesh/dist/hooks/inbox-poll.mjs
You reference these by absolute path from your user-scoped config so every project picks up the mesh automatically (see Global setup below). If you'd rather use short binary names, link them globally:
cd ~/src/claude-mesh
npm link
That puts claude-mesh-server, claude-mesh-session-start, claude-mesh-session-end, and claude-mesh-inbox-poll on your PATH.
Database
No setup required. The shared SQLite file is created automatically on first run at ~/.claude-mesh/mesh.db (the directory is created if missing, and the server runs its migrations on boot).
To put the file somewhere else, set MESH_DB_PATH in a .env inside the claude-mesh checkout — the binaries walk up from their own location at runtime to find it, regardless of which project Claude Code spawned them from:
cd ~/src/claude-mesh
cp .env.example .env
# edit MESH_DB_PATH if you don't want ~/.claude-mesh/mesh.db
You can also override MESH_DB_PATH in the MCP server's env block — values already in process.env take precedence over the mesh .env. All instances that should see each other must point at the same file.
Global setup
Register the mesh once at user scope and every Claude Code project on the workstation joins automatically — there is nothing to copy into individual repos beyond naming each peer (step 3). This is the recommended layout; a single MCP server entry and a single hooks block cover all projects.
1. Register the MCP server (user scope)
Add claude-mesh to the top-level mcpServers block in ~/.claude.json. Because it lives at user scope, every project inherits it:
{
"mcpServers": {
"claude-mesh": {
"type": "stdio",
"command": "node",
"args": ["/home/you/src/claude-mesh/dist/mcp-server.mjs"],
"env": {}
}
}
}
Or use the CLI with user scope:
claude mcp add --scope user claude-mesh node /home/you/src/claude-mesh/dist/mcp-server.mjs
If you ran npm link, the command/args become "command": "claude-mesh-server" (drop args).
No CLAUDE_MESH_PROJECT_PATH is needed for a user-scoped install: Claude Code sets CLAUDE_PROJECT_DIR per project, and the server resolves identity in the order CLAUDE_MESH_PROJECT_PATH → CLAUDE_PROJECT_DIR → process.cwd(). Set CLAUDE_MESH_PROJECT_PATH explicitly only if you register the server per-project instead.
2. Wire the hooks (user scope)
Add the hooks to ~/.claude/settings.json so they run for every project. Claude Code's hook schema nests hooks inside a matcher entry. There are four hook entries across three scripts — note that inbox-poll.mjs runs on both UserPromptSubmit and Stop:
{
"hooks": {
"SessionStart": [
{
"hooks": [
{ "type": "command", "command": "node /home/you/src/claude-mesh/dist/hooks/session-start.mjs" }
]
}
],
"UserPromptSubmit": [
{
"hooks": [
{ "type": "command", "command": "node /home/you/src/claude-mesh/dist/hooks/inbox-poll.mjs" }
]
}
],
"Stop": [
{
"hooks": [
{ "type": "command", "command": "node /home/you/src/claude-mesh/dist/hooks/inbox-poll.mjs" }
]
}
],
"SessionEnd": [
{
"hooks": [
{ "type": "command", "command": "node /home/you/src/claude-mesh/dist/hooks/session-end.mjs" }
]
}
]
}
}
What each does:
SessionStart→session-start.mjsregisters the peer and marks it active.UserPromptSubmit→inbox-poll.mjspolls the inbox before each turn, surfacing any pending questions in a<system-reminder>block.Stop→inbox-poll.mjspolls again when Claude tries to finish a turn; if peer questions are pending it blocks the stop so this Claude answers them instead of going idle.SessionEnd→session-end.mjsdeactivates the peer.
Claude Code passes each hook a session_id on stdin, which scopes deactivation to the owning session (a late SessionEnd from a prior session can't clobber a freshly-registered live peer). Hook scripts exit 0 even on failure (with a stderr warning) so Claude Code never refuses to start.
If you ran npm link, replace the command strings with claude-mesh-session-start, claude-mesh-inbox-poll (for both UserPromptSubmit and Stop), and claude-mesh-session-end.
3. Name each peer
Create .claude-mesh.json at each project root (commit it — it identifies this project in the mesh):
{ "name": "backend" }
Choose a short, unique name per project (e.g. frontend, backend, infra). If a project has no .claude-mesh.json, the peer name falls back to the project directory's basename — so an "empty" mesh config still joins the mesh under that name; it isn't unconfigured.
Per-project setup (alternative)
Prefer to scope the mesh to specific projects instead of the whole workstation? Put the same MCP server entry in .mcp.json at the project root and the same hooks block in .claude/settings.json (or .claude/settings.local.json to keep them untracked). When registering per-project, set CLAUDE_MESH_PROJECT_PATH in the MCP env block (e.g. "${workspaceFolder}") so the long-lived server resolves the right .claude-mesh.json rather than relying on process.cwd().
Tools reference
| Tool | Description |
|---|---|
register |
Upsert this peer into the mesh. Called automatically by the SessionStart hook. |
list_peers |
List all known peers and whether each is stale (not seen for > 30 minutes). |
ask_peer |
Ask another peer a question. Blocks until a reply arrives or a 5-minute timeout. |
reply_to_peer |
Reply to a question received via poll_inbox. |
poll_inbox |
Return pending questions addressed to this peer; marks them delivered. Called automatically by the UserPromptSubmit hook. |
Typical flow
- Both Claude Code instances start — the
SessionStarthook callsregisteron each. - On each user prompt, the
UserPromptSubmithook callspoll_inbox. If questions are waiting, Claude sees them in a<system-reminder>block and can callreply_to_peer. - When a Claude tries to end a turn, the
Stophook polls again and blocks the stop if peer questions are still pending — so the receiving Claude answers them rather than going idle. - To ask a peer directly, Claude calls
ask_peer { to: "backend", question: "..." }. The call blocks until the peer replies (or 5 minutes pass).
Known limitations
- 5-minute timeout.
ask_peerreturns{ status: "timed_out" }if no reply arrives within 5 minutes. The peer may not be running or may be busy. - Both peers must be live. There is no queuing for offline peers beyond the
pendingmessage status — a reply must arrive in the same session. - Local only / single machine. The transport is a shared SQLite file on local disk. All instances must share the same file (and therefore the same machine); remote or cross-machine coordination is not supported.
- Reply latency. A reply is picked up on the asker's next poll tick (~1s) rather than instantly — imperceptible against the 5-minute blocking budget.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。