Skip to content

Run bots on the Claude subscription through pi-claude-code - #26

Open
sousavf wants to merge 4 commits into
nikuscs:mainfrom
sousavf:feature/pi-claude-code
Open

sousavf wants to merge 4 commits into
nikuscs:mainfrom
sousavf:feature/pi-claude-code

Conversation

@sousavf

@sousavf sousavf commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Lets bots run on Claude models through the owner's Claude Pro/Max subscription, using the pi-claude-code provider, which drives the claude -p CLI.

  • Provider: makeProviderService registers createClaudeCodeProvider() as a native provider. Its models show up in provider settings next to the others.
  • Dependency: adds @earendil-works/pi-claude-code, pinned to commit d5b5e04 from GitHub (it is not on npm). It ships TypeScript sources, so the runtime, server and daemon tsconfigs gain allowImportingTsExtensions and the DOM libs needed to type-check them.
  • MCP tool names: the readable prefix is cut to 25 characters instead of 35, so mcp_<server>_<tool>_<hash> fits Claude Code's tool name limit.
  • Secret proxy: bot shells used to get the per-run token as proxy credentials in HTTP(S)_PROXY, and clients that drop proxy auth (the claude CLI among them) got a 403. The token now signs each placeholder as an HMAC tag (bots-secret-<NAME>-<tag>-placeholder), and the proxy URL carries no credentials. Only placeholders from the current daemon run are swapped, and the proxy still accepts loopback connections only.

Validation

  • bun run check and bun run lint pass.
  • bun install --frozen-lockfile passes. The lockfile diff contains only the pi-claude-code lines.
  • Checked by hand on the dev daemon:
    • The provider registers and lists its models, and a bot runs turns on it.
    • Through the proxy, HTTPS requests and pnpm view work, and claude reaches Anthropic.
    • A tagged placeholder is swapped. An untagged one, or one tagged by another run, is left as is.
  • The repo has no automated tests for these paths.

Register the pi-claude-code native provider so bots can use Claude
models through the owner's claude CLI login. Cap MCP tool name prefixes
at 25 characters so the names fit Claude Code's tool name limit, and let
the packages that import its TypeScript sources type-check them.
Proxy credentials in HTTP(S)_PROXY broke clients that drop or mishandle
proxy auth, such as the claude CLI. The per-run token now signs each
placeholder as an HMAC tag, so only placeholders from this daemon run
are swapped; the proxy still accepts loopback connections only.
@sousavf
sousavf requested a review from nikuscs as a code owner November 7, 2026 19:09
@nikuscs

nikuscs commented Nov 8, 2026

Copy link
Copy Markdown
Owner

Hey Vasco, pushed a small fix on top: Claude Code now shows up in Providers as "sign in from a terminal" with claude auth login, instead of a sign-in button that always failed (the provider's oauth login throws on purpose).

One thing I'd like your call on, the MCP tool name prefix going from 35 to 25 in mcp.utils.ts:

  • I get why you did it: pi-claude-code rejects any tool name over 50 chars for the whole request, and 35 + _ + 24 hash gives up to 60. So with 35, a bot on Claude Code with something like mcp_github_list_pull_requests fails every message.
  • The cost of 25 is that every MCP tool whose mcp_<server>_<tool> is longer than 25 gets a new name. Pi resolves tool calls by exact name, so calls that were mid-run (or waiting on approval) when the daemon restarts on the upgrade settle once as "Tool X is not available". After that it's fine.
  • It goes against the "preserve persisted Pi identifiers" line in architecture.md, but the hash already changes on any server or schema change, so names were never that stable.
  • The cleaner option would be a name mapping inside pi-claude-code (short names to Claude, real names back), not sure if that's on their side or ours.

Are you OK keeping 25 and accepting that one-off, or would you rather push for the mapping upstream? Feel free to correct me if I'm missing something on the Claude Code side.

@sousavf

sousavf commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the Providers fix, that's better than a button that always fails.

Let's keep 25. The 50-character limit comes from pi-claude-code itself (transcript.ts rejects any tool name over 50 for the whole request), so with 35 a bot on Claude Code with a long MCP tool name couldn't send any message. A one-time "Tool X is not available" for calls cut off by the upgrade restart is a fair price for that, and as you said, the hash already changes on any server or schema change. If pi-claude-code adds name mapping later, we can put the prefix back to 35.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants