# Pi Claude Bridge: origin and maintenance

## Origin and ownership

Pi Claude Bridge is an independent continuation of [prateekmedia/claude-agent-sdk-pi](https://github.com/prateekmedia/claude-agent-sdk-pi), maintained by Bruno Orsolon in [brunoorsolon/pi-claude-bridge](https://github.com/brunoorsolon/pi-claude-bridge). Its npm package name is `@puglab/pi-claude-bridge`. The repository has left GitHub's fork network and preserves the original Git history. The previous distribution was `@puglab/claude-agent-sdk-pi` at `brunoorsolon/claude-agent-sdk-pi-puglab`. Use `origin` for this repository; an optional `upstream` remote can still track the original without reconnecting the fork network.

The baseline is upstream npm `claude-agent-sdk-pi@1.0.22`, git commit `de1a64373e1c4839a177802eeeb894f611235ca3`, using `@anthropic-ai/claude-agent-sdk@0.2.126`. The upstream package's npm `gitHead` identifies that commit.

The original MIT permission text and `Copyright (c) 2026 Prateek Sunal` are preserved unchanged in [LICENSE](LICENSE), with a separate `Copyright (c) 2026 Bruno Orsolon` notice added for his contributions. Upstream authors own the original implementation. This continuation includes the compatibility repairs and tests described below, thinking-budget fixes, and separate distribution and release automation. Neither the original maintainer nor Anthropic endorses this project. MIT permission covers the extension, not additional rights over Anthropic services, SDK dependencies, branding, or subscription access.

## Independent development

Develop on feature branches and open pull requests against this repository's `master`. The original repair and distribution branches remain historical context, not required integration branches. Keep commit-specific preparation history, review evidence, and publication status in the corresponding pull request or release record, not in the shipped package documentation. When contributing fixes to the original project, use a focused branch without this project's branding or distribution changes.

## Repairs and compatibility implications

1. **Effective Pi instructions:** the complete supplied `context.systemPrompt` now reaches the official SDK unchanged. Pi 1.x supplies only a `{ messages }` transcript, so the provider rebuilds the prompt and custom tools from its system messages with the `getCurrentSystemPrompt` and `getCurrentTools` helpers from Pi's extension view. Default mode appends it once to the Claude Code preset. The provider no longer rereads a nearest `AGENTS.md`, extracts only skills, rewrites `pi` into other words, or substitutes `.claude` paths. The matching tool-path alias rewriting is removed; ordinary built-in tool-name and argument-key translation stays intact.
2. **Custom-tool contracts:** the Agent SDK's high-level tool factory expects Zod shapes, not raw JSON Schema. The SDK-created server also exposes the MCP SDK's public low-level request handlers. This provider uses those handlers to advertise Pi's original JSON Schema directly, avoiding conversion altogether. Required fields, nested structures, arrays, unions, enums, references, records, descriptions, and constraints survive discovery. Invalid MCP envelopes report the offending tool by name. The permission callback still denies SDK execution; direct MCP calls still return the existing denial result, and unknown names return a protocol error. Pi alone validates and executes real tool calls.

**Setting migration:** `appendSystemPrompt: false` no longer omits Pi instructions. It now sends the complete Pi prompt as a replacement system prompt, without the Claude Code preset. The default `true` retains that preset and appends Pi's complete prompt. Claude filesystem setting-source selection and strict-MCP defaults remain unchanged. Explicit Claude resources can add their own instructions; do not symlink duplicate Pi instructions into Claude resources. See the [README](README.md#context-loading) for isolated settings.

Production SDK versions are unchanged. `@modelcontextprotocol/sdk` is declared directly at the same compatible range already required by the installed Agent SDK; the lockfile retains version 1.29.0. Development dependencies retain upstream's Pi 0.74.x versions. The peer range now also admits Pi 1.4 and compatible later 1.x versions. Pi 1.x runtime compatibility is through Pi's extension-loader compatibility view, not a migration to the newer standalone `pi-ai` API. Direct standalone imports or type-checking against the Pi 1.x root API are not supported by this patch.

## Verification and consumer integration

Consumer integration is separate from maintaining this package. Check the consumer's current Pi, managed-tool, and Claude Code executable pins before validating a release. Record the exact candidate, commands, results, and unavailable evidence in its pull request and release records.

The retained tests exercise parent, subagent-role, and project payload transmission despite a nearer `AGENTS.md`; replacement mode; actual SDK MCP discovery with meaningful schema constraints; custom-call argument delivery through Pi's registered-tool wrapper; SDK permission and execution denial; unknown-tool errors; text/thinking streaming; adaptive-thinking options; manual thinking budgets and the child process's output limit for model limits, caller and user caps, and missing model metadata; historical tool-result content; invalid envelopes; and cancellation. Transport fixtures are disposable and credential-free. They are not live Claude responses, subscription authentication, service-policy approval, or evidence of a successful npm deployment. Schema discovery checks establish transport preservation, not acceptance of every JSON Schema keyword by Claude Code or the remote API.

To reproduce from a checkout, run `npm ci --ignore-scripts` and `npm test` with Node 24. For a separately installed loader, use `PI_TEST_AGENT_ENTRY=file:///absolute/path/to/pi-coding-agent/dist/index.js npm test`. `npm run typecheck` runs the exactly pinned development dependency TypeScript 5.9.3 (`tsc --noEmit -p tsconfig.json`) against the Pi 0.74 development types; it emits no files. The workflow repeats the runtime suite with exact Pi 0.74.0, 1.4.0, and 1.5.0 loaders.

Live subscription testing requires the maintainer's official human-controlled login. Credentials must not be shared in chat, extracted, impersonated, or routed through a custom proxy. Verify live service access and end-to-end npm publishing separately from the transport fixtures. Thinking checks cover the flags and output limit handed to the Claude Code process, not live token use.

## Thinking and output limits

The budget policy in the [README](README.md#thinking-and-output-limits) adapts the approach of [upstream pull request 16](https://github.com/prateekmedia/claude-agent-sdk-pi/pull/16) by Joseph Mearman: raise `CLAUDE_CODE_MAX_OUTPUT_TOKENS` for manual thinking and cap the budget against the model's output limit. Unlike that patch, this provider derives the output limit from the capped budget, keeps explicit caps, sends no unbounded fallback, and leaves adaptive requests at Claude Code's model default. Claude Code 2.1.126 (bundled with the SDK) and 2.1.316 both use per-model output limits, not one universal 32,000-token limit. Both cap the environment variable at the model's maximum and clamp a manual budget below the output limit. On Anthropic's first-party API, both also run every model outside their pre-adaptive list adaptively, whatever budget they receive. The provider therefore treats a model as adaptive unless it is on Claude Code's pre-adaptive list. This also covers the Opus 4.8, Opus 5, Sonnet 5, Haiku 5 and Fable 5 models that Pi 1.4 and 1.5 list.

## Automatic npm publishing

Two workflows keep testing and publishing separate. `test.yml` runs the three Pi test jobs on pull requests and `master` pushes; each job runs the type check before its runtime suite. `publish.yml` runs only for a published GitHub Release with a `vX.Y.Z` tag in `brunoorsolon/pi-claude-bridge`; pushing a tag alone does not publish. Publishing does not rerun the runtime tests: it relies on the tagged commit being reachable from this repository's `master`, whose push already ran `test.yml`. It verifies the package name `@puglab/pi-claude-bridge` and that the release tag equals `v<package.json version>`, reruns the type check, and only then publishes npm version `X.Y.Z`; a type error stops the release. It uses GitHub-hosted runners, Node 24.22.1, and npm trusted publishing via OIDC rather than a stored publish token. No GitHub environment is required. Action revisions are pinned. The npm artifact includes only the extension, TypeScript configuration, documentation, license, screenshot, and standard npm metadata.

The maintainer must complete these steps before making a release:

1. Rename the existing GitHub repository to `brunoorsolon/pi-claude-bridge`; do not create a replacement repository. Update existing clones with `git remote set-url origin git@github.com:brunoorsolon/pi-claude-bridge.git`. GitHub redirects old repository URLs, but do not reuse the old repository name because that breaks redirects. Check branch protections, required checks, and Actions permissions after detachment; if required checks refer to workflow names, account for the renamed workflows.
2. Review and merge the rebranding feature branch into this repository's `master`. Protect `master` and the `v*` release-tag pattern appropriately. Until the repository is renamed, the publish workflow deliberately skips releases rather than publishing metadata for the wrong repository.
3. Confirm control of the npm `@puglab` scope and new package name `@puglab/pi-claude-bridge`. This is a separate npm package, not an in-place rename, and does not inherit the old package's publisher settings. If npm requires a bootstrap publication before package-level settings are available, the maintainer must perform it through their own official npm login, using the reviewed merged commit. Version `1.0.25` continues the version sequence and uses a fresh release tag. If published manually, do not ask the workflow to publish that version again; the first automated release must use a new version.
4. In the new npm package's settings, configure the GitHub trusted publisher with owner `brunoorsolon`, repository `pi-claude-bridge`, and workflow filename `publish.yml`. Leave the environment field blank. Explicitly allow direct `npm publish`, not stage-only publishing. No GitHub environment or stored npm token is required. Newly created npm publisher configurations currently expire unless their first successful publication occurs within two days, so coordinate setup with the intended release.
5. After `test.yml` passes on `master`, validation, and publication approval, publish a GitHub Release whose tag points to the merged commit and matches an unused package version. Package version `1.0.27` requires release tag `v1.0.27`. Publishing the GitHub Release requests a real public npm publication; creating or pushing a tag alone does not. Never reuse an already published npm version, including one published manually. After the new package is available, migrate the consumer as described below; optionally deprecate the previous scoped package with a message pointing to the new one, without unpublishing it.

Project versions can match their upstream baseline, but npm versions are immutable: project changes cannot overwrite an existing package version. Each distinct publication needs a distinct version, even if upstream has not advanced. Preserve the upstream baseline in this document when that happens. The workflow does not bump versions or create tags automatically.

Official references: [npm trusted publishing](https://docs.npmjs.com/trusted-publishers/) and [npm provenance](https://docs.npmjs.com/generating-provenance-statements/). Trusted publishing requires npm 11.5.1 or later and Node 22.14.0 or later. The package's repository URL must match this repository; public provenance also requires the repository and package to be public. No traditional npm token is needed by the workflow.

## Dependency updates

`.github/dependabot.yml`, adapted from [upstream pull request 18](https://github.com/prateekmedia/claude-agent-sdk-pi/pull/18) by Joseph Mearman, checks the root npm package and the GitHub Actions revisions weekly. Each ecosystem keeps at most five version-update pull requests open and skips releases younger than seven days. Dependabot only opens pull requests: nothing merges automatically, and merging an update neither bumps the package version nor creates a tag or GitHub Release, so it publishes nothing.

Every update pull request runs `test.yml` and needs human review like any other change. Seven days of age and a green run are not enough for `@anthropic-ai/claude-agent-sdk` or Pi updates: the tests use disposable transport fixtures, so review those updates against the prompt/settings seam, MCP contracts, and tool denial as described for upstream updates below.

The seven-day cooldown is not a security guarantee. It only delays version updates; a broken or malicious release can stay published longer than seven days. It does not apply to Dependabot security updates, which are a separate repository setting, are not delayed by the cooldown, and have their own fixed limit of ten open pull requests.

## Consumer migration and exact pins

After the new package is published, remove the previous source with `pi remove npm:@puglab/claude-agent-sdk-pi`, then install `pi install npm:@puglab/pi-claude-bridge@1.0.27` and reload Pi. If declarative consumer configuration owns installation, replace its old npm or Git source there instead. Keep any consumer dependency lockfile. A Git alternative is `pi install git:github.com/brunoorsolon/pi-claude-bridge@v1.0.27` after that tag exists; an exact full commit SHA is preferable if tag mutability is a concern. Manage consumer installation and updates in the consumer repository.

The provider ID `claude-agent-sdk` and settings keys `claudeAgentSdkProvider` / `claude-agent-sdk-provider` are unchanged. Existing model selections and settings do not need renaming. Do not load the old scoped package, the original upstream package, and Pi Claude Bridge together: they register the same provider ID. The previous package can remain published for rollback; do not unpublish it as part of this migration.

## Optional upstream maintenance

An optional `upstream` remote can still fetch the original project. Evaluate upstream changes on a new feature branch based on this repository's `master`, without reviving the old two-branch distribution workflow. Review the prompt/settings seam, MCP contracts, tool denial, and SDK version before merging or cherry-picking changes. Drop repairs that upstream has independently implemented rather than maintaining competing versions. Repeat the focused checks against the consumer's current pins, update the baseline here, and record validation evidence in the pull request. Preserve this project's identity and original attribution when resolving metadata conflicts.

If choosing to return to the original package, first validate its exact release with the same seams and current consumer pins, then replace this project's installation source rather than loading both. Replacement-mode settings need an explicit review because upstream's semantics may differ.
