# @agimon-ai/po-claude-bridge

Standalone Pi extension that runs Claude Code through the Claude Agent SDK. It
registers the `claude-bridge` model provider and an optional `AskClaude` delegation
tool. It does not register a Po runtime extension or HTTP service.

## Install from npm

```sh
pi install npm:@agimon-ai/po-claude-bridge@alpha
```

The package participates in this repository's alpha npm release workflow.

## Local install

From the repository root:

```sh
pnpm install
pnpm nx build @agimon-ai/po-claude-bridge
pi install ./packages/utils/po-claude-bridge
```

Or load the built extension for one session:

```sh
pi -e ./packages/utils/po-claude-bridge/dist/index.mjs
```

Claude Code must be installed and authenticated separately. Select a
`claude-bridge` model through Pi's model selector. Pi executes tools exposed by the
provider through its MCP bridge and retains control of compaction and session
lifecycle events.

`AskClaude` delegates a prompt to a separate Claude Code query. Its modes are
`read` (default), `none`, and `full`. Parameters also include `model`, `thinking`,
and `isolated`. Set `allowFullMode: false` to disable full-mode delegation.

## Configuration

The package preserves the imported fork's configuration paths:

- Global: `~/.pi/agent/claude-bridge.json`
- Project: `.pi/claude-bridge.json`, merged over global configuration

```json
{
  "askClaude": {
    "enabled": true,
    "defaultMode": "read",
    "allowFullMode": false,
    "defaultIsolated": false,
    "appendSkills": true
  },
  "provider": {
    "appendSystemPrompt": true,
    "strictMcpConfig": true,
    "plan": "pro",
    "longContextExtraUsage": false
  }
}
```

Optional `askClaude.name`, `askClaude.label`, and `askClaude.description` override
the tool's name, label, and description. `provider.pathToClaudeCodeExecutable`
selects a Claude Code binary. `provider.settingSources` applies when
`appendSystemPrompt` is false. The imported model catalog and context-window
selection behavior are preserved.

## Logging

Bridge diagnostics use the existing LogSink OTLP transport, under service
`po-claude-bridge`. The global collector is discovered automatically. Standard
`OTEL_EXPORTER_OTLP_*`, `LOG_SINK_ENDPOINT`, and `LOG_SINK_INSTANCE` settings work
as usual. No collector is started by this package.

Without a collector, standalone Pi continues normally without writing fallback
log files. Diagnostic events export numeric and boolean metadata by default, plus
validated cache fingerprints, opaque query IDs, and fixed session-sync paths.
`CLAUDE_BRIDGE_DEBUG=1` enables debug events and SDK stderr capture. Add
`AGENT_OTEL_REDACT=0` only when you explicitly want verbose content, which may
include prompts, tool results, paths, and credentials, sent to the collector.

`AGENT_TELEMETRY_DISABLED=1` or `OTEL_SDK_DISABLED=1` disables export. Logs flush
when an agent settles or its session shuts down. The shared transport closes when
the process exits. `CLAUDE_BRIDGE_DEBUG_PATH` is no longer used.

Cache diagnostics work without debug mode or disabling redaction:

- `claude_bridge.cache_query`: a fresh provider query's `queryId`, `syncPath`
  (`clean-start`, `empty-rebuild`, `reuse`, `append`, `rebuild`), SHA-256
  `hostPromptHash` and `toolsHash`, change flags, and the gap between comparable
  query starts. Comparisons require an explicit session owner and stay within
  that owner, project, and model.
- `claude_bridge.cache_query_reuse`: tool results delivered to an existing SDK
  query, rather than a new process. It carries the same `queryId`.
- `claude_bridge.cache_usage`: SDK query totals, emitted once on its result,
  including standard `gen_ai.usage.*` input/output and cache-read/write counters,
  available 5m/1h write counts, and
  `cacheHitPercent = read / (input + read + write) * 100`.
  AskClaude delegation emits this event with `askClaude: true`.

`requestedTtlSeconds` is 300 or 3600 for explicit short/long retention, otherwise
zero (automatic or disabled). `environmentTtlSeconds` records a recognized SDK
TTL environment override, otherwise zero. These are configuration inputs, not
proof of the effective TTL, which can also depend on Claude settings and account
policy. `cacheDisabled` records the child environment's disable switch.

Join query and usage events by `queryId`. Query totals overlap Pi's per-turn
usage: do not sum the two sources. A changed host fingerprint is a candidate for
cache invalidation, not proof: the SDK-rendered preset and actual API prefix are
not captured. Prompt snapshots and forwarding behavior remain unchanged.

Query from this repository:

```sh
pnpm --filter @agimon-ai/po-log exec po-logsink logs query --global --service po-claude-bridge --limit 20
```

Older collectors may still write `~/.log-sink-mcp/global/session.db`. Query that
file with `--db-path ~/.log-sink-mcp/global/session.db` when needed. The bridge
does not migrate or restart the collector.

## Development

```sh
pnpm nx run-many -p @agimon-ai/po-claude-bridge -t build,typecheck,lint,test
```

Tests run with Vitest. They use scripted SDK queries, temporary session files, an
in-process MCP client, and Pi's extension loader. They do not verify live Claude
Code authentication or subscription billing.
The imported implementation and tests remain at the package root and in `test/`
to retain their standalone structure. Runtime dependencies stay external to the
ESM build; Pi supplies the peer dependencies.

## Attribution and license

Imported from the local Pi-compatible fork of
[omp-claude-bridge](https://github.com/barisdemirdelen/omp-claude-bridge), itself
based on [pi-claude-bridge](https://github.com/elidickinson/pi-claude-bridge).

This package alone is MIT licensed. Copyright notices for Eli Dickinson, Baris
Demirdelen, and Agimon Pty Ltd are retained in [LICENSE](LICENSE). No other
repository package's license is changed.
