Skip to content
 
 

Latest commit

 

History

64 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pi-anthropic-oauth

npm

Use Claude Pro/Max in Pi with browser OAuth.

Important

This extension supports Pi 0.80.8 or later.

Features

  • Claude Pro/Max login from /login
  • Automatic token refresh
  • Claude Code-compatible OAuth headers and prompt shaping
  • No Anthropic API key needed
  • Uses the Anthropic models available in Pi's built-in model registry
  • Auto-creates ~/.Claude Code~/.pi symlink when missing

Quick start

pi install npm:pi-anthropic-oauth

Start Pi, then run Pi's login command:

/login

Choose:

Claude Pro/Max

Complete 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=aggressive

Other 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 5 and Fable 5 are included in Pi's built-in Anthropic model catalog as claude-opus-5 and claude-fable-5.

Pi requires baseUrl, apiKey, and api when defining custom models in models.json. With this extension, requests normally authenticate through Claude Pro/Max OAuth after /login, so apiKey is 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 return 401 Invalid bearer token. Use a harmless placeholder such as "unused", then run /login and choose Claude Pro/Max.

Troubleshooting

  • Run /login with no arguments, then choose Claude Pro/Max.
  • If local callback login does not complete, paste the final callback URL or code#state when prompted
  • If you see 401 Invalid bearer token, remove any fake sk-ant-oat... placeholder from ~/.pi/agent/models.json and log in again
  • If something breaks, please open an issue with your Pi version, extension version, and error output

License

MIT

About

Pi extension for Anthropic OAuth with Claude Pro/Max.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages