pi-anthropic-oauth
v0.2.0
Published
Claude Pro/Max OAuth extension for Pi
Readme
pi-anthropic-oauth
Use Claude Pro/Max in Pi with browser OAuth.
[!IMPORTANT] This release requires Pi 0.80.8 or later in the 0.80.x release line.
Features
- Claude Pro/Max login from
/login - Automatic token refresh
- Claude Code-compatible OAuth headers and prompt shaping
- No Anthropic API key needed
- Uses Pi's Anthropic model registry
- Adds Claude Opus 4.8 and Claude Fable 5 by default
- Auto-creates
~/.Claude Code→~/.pisymlink when missing
Quick start
pi install npm:pi-anthropic-oauthStart Pi, then run Pi's login command:
/loginChoose:
Claude Pro/MaxComplete the browser login. After login, select an Anthropic model in Pi.
When the extension is active, /login includes Claude Pro/Max and Anthropic models show (sub) after OAuth login.
Update with:
pi update npm:pi-anthropic-oauth[!NOTE] Anthropic auth changes are closely monitored for quick compatibility updates.
System prompt rewriting
When using Claude Pro/Max OAuth, the extension prepends Claude Code identity text and rewrites standalone Pi / pi references in Pi's system prompt to Claude Code. The rewrite mode defaults to aggressive:
PI_ANTHROPIC_OAUTH_REWRITE_MODE=aggressiveOther modes are opt-in and avoid rewriting some technical strings such as paths, package names, or repository names. If OAuth starts failing, switch back to aggressive.
Available modes:
| Mode | Behavior |
| ---------------- | ----------------------------------------------------------------------------------------------------------- |
| aggressive | Default. Replaces standalone Pi / pi wherever the word-boundary pattern matches. |
| path-safe | Avoids replacing Pi / pi immediately after / or \, preserving path segments like /srv/dev/pi-foo. |
| technical-safe | Avoids replacing Pi / pi next to common technical-token separators: /, \, ., @, :, _, -. |
| custom | Uses PI_ANTHROPIC_OAUTH_REWRITE_PATTERN as the replacement regex. |
Custom patterns can be a regex source or a JavaScript-style regex literal. The g flag is added automatically when omitted:
PI_ANTHROPIC_OAUTH_REWRITE_MODE=custom
PI_ANTHROPIC_OAUTH_REWRITE_PATTERN='(?<![/\\])\b[Pp]i\b'
# or
PI_ANTHROPIC_OAUTH_REWRITE_PATTERN='/\bpi\b/gi'There is no separate off mode. If you need to disable rewriting entirely, use a custom pattern that never matches, such as (?!). Disabling or weakening the rewrite may affect OAuth compatibility.
Extra models
To add another Anthropic model, create ~/.pi/agent/models.json:
{
"providers": {
"anthropic": {
"baseUrl": "https://api.anthropic.com",
"apiKey": "unused",
"api": "anthropic-messages",
"models": [
{
"id": "your-model-id",
"name": "Your Model Name"
}
]
}
}
}[!NOTE] Opus 4.8 and Fable 5 are included in Pi's built-in Anthropic model catalog.
Pi requires
baseUrl,apiKey, andapiwhen defining custom models inmodels.json. With this extension, requests normally authenticate through Claude Pro/Max OAuth after/login, soapiKeyis only a placeholder to satisfy Pi's config requirements and does not need to be a valid Anthropic API key.Do not use a fake
sk-ant-oat...value as the placeholder. If OAuth login has not completed, Pi may try to use that fake token and Anthropic will return401 Invalid bearer token. Use a harmless placeholder such as"unused", then run/loginand chooseClaude Pro/Max.
Troubleshooting
- Run
/loginwith no arguments, then chooseClaude Pro/Max. - If local callback login does not complete, paste the final callback URL or
code#statewhen prompted - If you see
401 Invalid bearer token, remove any fakesk-ant-oat...placeholder from~/.pi/agent/models.jsonand log in again - If something breaks, please open an issue with your Pi version, extension version, and error output
License
MIT
