The CodeGraph plugin for pi that actually works.
Two problems, one fix. Original CodeGraph plugins for pi break silently when you switch projects, and leave zombie processes piling up. This fork fixes both.
pi install npm:pi-codegraph-fixThat's it. You also need CodeGraph CLI (npm install -g @colbymchenry/codegraph) and your project indexed (codegraph init).
You pi session=<other-project> or launch pi from ~ instead of your project root. Suddenly codegraph tools disappear. No error, just nothing.
Why: The original plugin used process.cwd() to find .codegraph/codegraph.db. That always points to wherever pi was first launched — not your current session's project. Wrong project → no DB → no tools → silent failure.
Every time you close pi, the codegraph serve --mcp subprocess doesn't die. After a few sessions you have a dozen of them fighting over the same socket — causing "server disconnected" errors on every codegraph call.
Real case: 12 zombie processes accumulated over 9 hours across 6 sessions. Every codegraph call spun the roulette wheel on which zombie had the socket lock.
Two changes from the originals (codegraph-pi, pi-codegraph):
ctx.cwd instead of process.cwd() — reads the current session's working directory from pi, so it works no matter where or how you launched pi.
Three-path cleanup — kills the MCP subprocess on normal exit, crash, or terminal close:
| Path | When |
|---|---|
session_shutdown |
pi exits normally |
process.once("exit") |
Node process ends |
SIGTERM / SIGHUP |
Terminal close, kill |
No more zombies. No more "server disconnected".
| 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 |
colbymchenry/codegraph-pi |
.codegraph/codegraph.db exact check |
colbymchenry/codegraph-pi |
- On
session_start, checksctx.cwd/.codegraph/codegraph.dbexists - Spawns
codegraph serve --mcpwithcwd: 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