---
title: "@henryqw/pi-codegraph"
seo:
  description: "Initialize CodeGraph indexes in opted-in Git worktrees and expose CodeGraph through pi-mcp-adapter."
---

<div class="not-prose my-6 flex flex-wrap items-center gap-3"><a href="https://www.npmjs.com/package/@henryqw/pi-codegraph" aria-label="View @henryqw/pi-codegraph version v0.1.3 on npm"><img alt="Version v0.1.3" height="20" src="https://img.shields.io/static/v1?cacheSeconds=7200&amp;color=1d4ed8&amp;label=version&amp;labelColor=6a7282&amp;style=flat-square&amp;message=v0.1.3" width="96"></a><div class="ml-auto flex flex-wrap items-center justify-end gap-3"><a href="https://www.npmjs.com/package/@henryqw/pi-codegraph" aria-label="View @henryqw/pi-codegraph on npm"><img alt="Monthly npm downloads" height="20" src="https://img.shields.io/npm/dm/%40henryqw%2Fpi-codegraph?cacheSeconds=7200&amp;color=1d4ed8&amp;label=downloads&amp;labelColor=6a7282&amp;style=flat-square" width="144"></a><a href="https://github.com/HenryQW/pi-harness/blob/main/extensions/pi-codegraph/LICENSE" aria-label="View the MIT license for @henryqw/pi-codegraph"><img alt="MIT license" height="20" src="https://img.shields.io/npm/l/%40henryqw%2Fpi-codegraph?cacheSeconds=7200&amp;color=1d4ed8&amp;label=license&amp;labelColor=6a7282&amp;style=flat-square" width="78"></a></div></div>

Get a separate [CodeGraph](https://github.com/colbymchenry/codegraph) index when you start Pi in a new Git worktree. Use CodeGraph's explore tool through pi-mcp-adapter from Pi.

## Install

```bash
pi install npm:@henryqw/pi-codegraph
```

```bash
npm install -g @colbymchenry/codegraph
pi install npm:pi-mcp-adapter
pi install npm:@henryqw/pi-codegraph
```

Requires `codegraph` CLI on `PATH`, and [pi-mcp-adapter](https://github.com/nicobailon/pi-mcp-adapter).

## Use

From the primary checkout, initialize CodeGraph once:

```bash
codegraph init --yes
```

Then launch `pi` in a linked worktree. The adapter server is `henryqw_pi-codegraph__codegraph`. It discovers tools lazily; other CodeGraph tools remain available through `mcp`.

## Flow

- A missing worktree index is built only when the primary checkout already has `.codegraph/codegraph.db`.
- Initialization happens when Pi launches, not when Git creates the worktree.
- Each linked worktree keeps its own `.codegraph`; databases are never copied or shared between branches.
- Non-Git directories and repositories without a primary index are not initialized.

## State and storage

The extension relies on CodeGraph's own state — each worktree maintains its own `.codegraph/codegraph.db`. The extension never copies, shares, or modifies this database. Existing indexes are left alone; CodeGraph owns synchronization when its MCP server runs.

## Limits and recovery

At startup, the extension checks for a loaded adapter and runs `codegraph --version`. If either prerequisite is unavailable, Pi warns and skips setup. Restart Pi or run `/reload` after fixing prerequisites.

Initialization uses an exclusive `pi-codegraph-init.lock` in the worktree's Git metadata. Failed or interrupted initialization keeps the lock so a partial database is not accepted. To recover: remove the lock directory with `rmdir` only after `codegraph index` succeeds, then run `/reload`.

The package never installs prerequisites automatically. The `codegraph` executable must be available to both Pi and its MCP child process. An alternate `CODEGRAPH_DIR` is not supported. The extension does not add ignore rules, delete indexes, or prune worktrees — add `.codegraph/` to your own ignore rules if needed. Pi Subagent and Pi Orchestrator conservatively treat ignored files as retained work.

If you already configured a `codegraph` server manually, remove that entry after confirming the package server works.
