CodeGraph MCP sidecar for the pi coding agent.
Fixes the core problem that caused low codegraph adoption: process.cwd() lock-in.
Both colbymchenry/codegraph-pi and SeanPedersen/pi-codegraph used process.cwd() to locate .codegraph/codegraph.db:
const dbPath = join(process.cwd(), ".codegraph", "codegraph.db");
// ^^^^^^^^^^^^^
// always points to where pi was launched, not the current sessionWhen you loaded a session from a different project (pi session=<id>), or when pi was launched from ~ instead of the project root, the DB file was never found → no codegraph tools were registered → 0% call rate.
Fix: Use ctx.cwd from the session_start event:
const projectRoot = ctx.cwd || process.cwd();
// ^^^^^^^
// the current session's working directory, provided by piPlus: pass cwd: projectRoot when spawning codegraph serve --mcp so the subprocess also resolves the correct project root.
| Feature | Source |
|---|---|
ctx.cwd instead of process.cwd() |
pi-codegraph-fix |
spawn with explicit cwd |
pi-codegraph-fix |
| Multi-project MCP clients (one per CWD) | SeanPedersen/pi-codegraph |
Dynamic tool discovery via MCP tools/list |
SeanPedersen/pi-codegraph |
| Process cleanup hooks (exit, SIGTERM, SIGHUP) | SeanPedersen/pi-codegraph |
| Self-contained single file | SeanPedersen/pi-codegraph |
before_agent_start system prompt injection (no APPEND_SYSTEM.md side effect) |
colbymchenry/codegraph-pi |
.codegraph/codegraph.db exact check (not just .codegraph/ dir) |
colbymchenry/codegraph-pi |
# pi install (from GitHub)
pi install github:GDWhisper/pi-codegraph-fix
# Or via settings.json{
"packages": ["github:GDWhisper/pi-codegraph-fix"]
}- CodeGraph CLI (
npm install -g @colbymchenry/codegraph) - Project must be indexed:
codegraph initin project root
- On
session_start, checksctx.cwd/.codegraph/codegraph.dbexists - Spawns
codegraph serve --mcpas a subprocess withcwd: projectRoot - Discovers available tools via MCP
tools/list - Registers all tools with
pi.registerTool() - Injects usage instructions into system prompt via
before_agent_start - On
session_shutdownor process exit, cleans up all MCP clients
- colbymchenry/codegraph-pi — original pi extension
- SeanPedersen/pi-codegraph — multi-client architecture