pi-claude-agent-sdk

Pi extension that uses Claude Code (via Agent SDK) as a model provider.

Packages

Package details

extension

Install pi-claude-agent-sdk from npm and Pi will load the resources declared by the package manifest.

$ pi install npm:pi-claude-agent-sdk
Package
pi-claude-agent-sdk
Version
0.8.1
Published
Aug 6, 2026
Downloads
121/mo · 0/wk
Author
edverma2
License
MIT
Types
extension
Size
281.2 KB
Dependencies
5 dependencies · 2 peers
Pi manifest JSON
{
  "extensions": [
    "./src/index.ts"
  ]
}

Security note

Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.

README

pi-claude-agent-sdk

npm version

Pi extension that integrates Claude Code as a pi model provider via the Agent SDK. Forked from pi-claude-bridge by Eli Dickinson, which was based initially on claude-agent-sdk-pi by Prateek Sunal. Adds streaming, MCP tool bridging, custom pi tool bridging, session resume/persistence, context sync, thinking support, and skills forwarding.

Use Opus/Sonnet/Haiku as models in pi, with all tool calls flowing through pi's TUI.

FYI: Anthropic announced and then unannounced a change to how you would be billed for tools that use the Agent SDK like this one. As of June 15, 2026 it uses subscription quota just like Claude Code direct does.

Install

pi install npm:pi-claude-agent-sdk

Provider

Use /model to select claude-bridge/claude-fable-5, claude-bridge/claude-opus-5, claude-bridge/claude-opus-4-8, claude-bridge/claude-opus-4-7, claude-bridge/claude-opus-4-6, claude-bridge/claude-sonnet-5, claude-bridge/claude-sonnet-4-6, or claude-bridge/claude-haiku-4-5.

Behind the scenes, pi's tools are bridged to Claude Code but it should all work like normal in pi. Bash commands get a 120-second default timeout (matching Claude Code's default) since pi's bash has no timeout by default. Skills in pi are copied over to Claude Code's system prompt so should work as they would with any other pi provider. Steering works mid-turn: a message sent while Claude is running a tool reaches it at that tool boundary, not after the whole turn finishes.

Authentication: the bridge requires an Anthropic OAuth credential (or API key) configured in Pi and uses Pi's normal token refresh. Claude Code login and inherited Claude/Anthropic authentication settings are deliberately ignored, so configure Anthropic authentication in Pi before using the provider.

1M Context: Opus 5, Opus 4.8, and Opus 4.7 get 1M context by default. Opus 4.6 only gets 1M if you're on a Max plan or pay for Extra Usage. Sonnet 4.6 only gets 1M if you pay for Extra Usage. You will need to set provider.plan and/or provider.longContextExtraUsage for 1M context in Opus 4.6/Sonnet 4.6 as described in Configuration.

Configuration

Config: ~/.pi/agent/claude-bridge.json (global) or the project Pi config directory, usually .pi/claude-bridge.json (project; merged over global).

{
  "provider": {
    "plan": "max",
    "longContextExtraUsage": false,
    "strictMcpConfig": true,
    "pathToClaudeCodeExecutable": "/home/you/.nix-profile/bin/claude"
  }
}

provider:

  • plan (default "max") — Max (or Team Premium/Enterprise). Set to "pro" on a Pro plan so Opus 4.6 stays at 200K context. If it's unset, the first interactive session points this out once, then records startupNoticeShown (the date, YYYY-MM-DD) in the global config so it doesn't nag again.
  • longContextExtraUsage — set to true to enable 1M models that cost money through Extra Usage. It enables Sonnet 4.6 with 1M on every plan and Opus 4.6 with 1M on Pro. Not needed for Opus 4.7 or 4.8.
  • appendSystemPrompt — append pi's project context files (global and ancestor AGENTS.md / CLAUDE.md) and skills (default true)
  • settingSources — CC filesystem settings to load; only applied when appendSystemPrompt: false
  • strictMcpConfig — block MCP servers from ~/.claude.json / .mcp.json (default true). Cloud MCP (Gmail/Drive via claude.ai OAuth) is always blocked.
  • autoMemoryEnabled — enable Claude Code's auto-memory system (default false)
  • pathToClaudeCodeExecutable — path to the claude binary. Useful if your OS/filesystem has the SDK's bundled musl/glibc binaries in a place where they can't run. For example, with Nix you can set the binary to e.g. "/home/you/.nix-profile/bin/claude".

Extension providers and models.json: pi's modelOverrides in ~/.pi/agent/models.json do not currently apply to extension-registered providers (like claude-bridge). Overriding contextWindow or other fields requires editing src/models.ts directly.

Tests

npm run test:unit for offline tests (tests/unit-*.mjs: queue, import, skills).

npm test for the full suite, which adds integration tests that hit APIs (tests/int-*.{sh,mjs}: smoke, multi-turn, cache, session-resume, session-rebuild, tool-message). Set CLAUDE_BRIDGE_TESTING_ALT_PROVIDER and CLAUDE_BRIDGE_TESTING_ALT_MODEL in .env.test for the provider-switch tests.

Integration tests spawn real pi and Claude Code subprocesses, so they need write access to ~/.claude for CC's session state — a sandbox that blocks it makes the next turn's --resume fail with No conversation found with session ID. The RPC harness probes for this at startup and fails fast.

Debugging

Set CLAUDE_BRIDGE_DEBUG=1 to enable debug output:

  • Bridge log at ~/.pi/agent/claude-bridge.log — every provider call, session sync decision, tool result delivery, and CC's stderr. Override location with CLAUDE_BRIDGE_DEBUG_PATH.
  • Per-query Claude Code CLI logs at ~/.pi/agent/cc-cli-logs/<timestamp>-<tag>-<seq>.log — the CC subprocess's own debug stream, one file per query() call. Tags are provider (main turn) or compact-summary. Useful when a resume fails or CC misbehaves internally — shows the CLI's own view of session loading, API requests, and tool calls.

When filing a bug about a session-resume failure (e.g. "No conversation found"), the most useful attachments are the syncResult: lines from the bridge log plus the matching cc-cli-logs/ file for the failing query.