omp packages

pi-claude-oauth0.3.1

Use Claude Pro, Max, and Ultra subscription OAuth tokens from Pi

GitHub Actions Published 4 days ago ~1.4K downloads/mo

Untested on omp

This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.

Did it work for you?

Result

One report per person. A new report replaces your old one.

Reports 0

No reports yet.

Readme

pi-claude-oauth

pi-claude-oauth is an extension that lets you use a Claude Pro, Max, or Ultra subscription from Pi through Anthropic's OAuth tokens. This README covers installing the extension, signing in, using the anthropic provider, billing, terms, security, and working on the source.

The Anthropic provider

The extension adds its OAuth sign-in and refresh methods to Pi's built-in anthropic provider. Pi owns the model catalog and Anthropic Messages transport. API-key requests go directly to that transport. OAuth requests go through Pi's existing OAuth compatibility code before reaching the same transport.

Requirements

  • Pi 1.6.0 or newer. CI loads the packed extension with the minimum and the pinned development version of Pi.
  • Node.js on Linux or macOS. Use 22.23.5 or newer in the 22.x series, 24.22.3 or newer in the 24.x series, or 26.13.1 or newer in the 26.x series. CI also runs on Windows.
  • A Claude Pro, Max, or Ultra subscription with Claude Code access.

Install the extension

To install the extension, run:

pi install npm:pi-claude-oauth

To try the extension for one run without saving it to your Pi settings, run:

pi -e npm:pi-claude-oauth

Sign in

Run the /login anthropic command:

/login anthropic

Sign-in options

Pi first asks how to sign in:

Option What it does
Sign in with an account Offers the Claude subscription sign-in methods below.
Sign in with an API key Accepts an Anthropic API key or a token from claude setup-token.

Claude subscription sign-in methods

Method What it does
Browser sign-in Authorizes in your browser. Returns through http://localhost:53692/callback, or through a free port when 53692 is taken. If the browser runs on another machine, paste the final redirect URL instead.
Copy code (headless) Uses Anthropic's manual redirect. Asks you to paste the code#state value that the manual redirect shows. Runs no local server.
Import setup token from environment Saves the claude setup-token token from CLAUDE_CODE_OAUTH_TOKEN. Pi never asks you to type or paste the token.

Use Browser sign-in when you can open a browser on the machine running Pi. Choose Copy code (headless) when you cannot use the loopback callback.

Sign-in without a browser

For ambient headless authentication, set Pi's native ANTHROPIC_OAUTH_TOKEN before starting Pi. To save a setup token explicitly instead, export CLAUDE_CODE_OAUTH_TOKEN and choose Import setup token from environment during /login anthropic. The legacy variable is not ambient authentication.

Credential precedence and setup token expiry

  • Pi resolves stored credentials and native environment authentication. CLAUDE_CODE_OAUTH_TOKEN is only used for explicit import.
  • A setup token expires after a year and cannot be refreshed.
  • When a setup token expires, replace it in either of these ways:
    • Run /login anthropic and paste a new setup token with Sign in with an API key.
    • Export a new setup token, restart Pi, and import it with Sign in with an account → Import setup token from environment.

Use the Anthropic provider

Example commands:

/model anthropic/claude-opus-5-5
/claude status
/claude usage

Claude commands

Command What it does
/claude status Renders a card with the sign-in source, the number of registered models, and the active model.
/claude usage Shows the subscription's rolling usage windows with reset times.
/claude login Points at the built-in /login command.
/claude logout Points at the built-in /logout command.

Claude model catalog

Pi owns the anthropic catalog, including live updates. /claude usage requires a resolved OAuth or setup token, not an ordinary API key.

Migration from the claude provider

Pi stores one credential per provider. If you already have a saved Anthropic API key and want to keep it, use a separate Pi --agent-dir for the subscription before signing in. Installing the upgrade does not change either saved credential.

  1. Replace claude/<id> model references in your configuration with anthropic/<id>.
  2. Run /login anthropic to sign in again or import a setup token. The extension does not move the old claude credential. For environment-only authentication, replace CLAUDE_CODE_OAUTH_TOKEN with ANTHROPIC_OAUTH_TOKEN.
  3. If you resume a session that used the old provider, select the model again with /model anthropic/<id>. There is no claude provider alias.

Billing and terms

What the extension does with tokens

  • This extension does not bypass anything.
  • The extension performs the same OAuth client, scopes, and token refresh that Claude Code uses.
  • The extension sends the tokens to Anthropic's API.

Billing warning

  • Third-party harness usage is billed per token as extra usage, outside your Claude plan limits. Usage and billing still apply.
  • Manage extra usage at https://claude.ai/settings/usage.

Account-level use

Treat subscription OAuth as an account-level credential, not as a way to move plan limits into another harness. Review Anthropic's consumer terms and usage settings before relying on it for daily work.

Security

Token storage and logging

  • Pi stores the credential in ~/.pi/agent/auth.json.
  • The extension never writes tokens anywhere else.
  • Access and refresh tokens are never logged.
  • Error messages include the HTTP status or Anthropic's OAuth error code.
  • Error messages redact the submitted code, state, PKCE verifier, or refresh token and remove terminal control characters from provider diagnostics.
  • Token and usage responses are limited to 256 KiB.

OAuth callback and PKCE

  • The loopback callback accepts only requests with the matching state nonce.
  • The PKCE verifier is published to neither the browser nor the callback URL.
  • The PKCE verifier goes directly to the token endpoint.

Token refresh and Claude Code credentials

  • Refresh rotates the refresh token under Pi's credential-store lock, so concurrent requests and concurrent Pi processes refresh once.
  • The extension deliberately does not import the refresh token from Claude Code's own credential store. Anthropic rotates refresh tokens, so copying Claude Code's refresh token and refreshing it in this extension would invalidate your Claude Code login.

OAuth client id

  • The OAuth client id is Claude Code's public PKCE client id, so it is not a secret.

Protocol reference

OAuth constants

The constants in src/oauth.ts mirror Claude Code 2.1.331:

Item Value
Authorize https://claude.com/cai/oauth/authorize
Token https://platform.claude.com/v1/oauth/token
Manual redirect https://platform.claude.com/oauth/code/callback
Client id 9d1c250a-e61b-44d9-88ed-5944d1962f5e
Scopes user:profile user:inference user:sessions:claude_code
PKCE S256, independent state nonce, code=true
Grants authorization_code, refresh_token with JSON bodies
Inference beta oauth-2025-04-20, added by Pi's Anthropic implementation for sk-ant-oat tokens

Documentation the protocol reference follows

Documentation Topics
Authentication Credential storage, precedence, long-lived tokens
CLI reference claude setup-token
Environment variables CLAUDE_CODE_OAUTH_TOKEN
GitHub Actions Plans whose subscriptions issue these tokens
Pi extension API: docs/extensions.md and docs/custom-provider.md in the Pi install Specifically registerProvider, OAuth callbacks, and registerEntryRenderer

Development

Development tool versions

  • Use npm 12.2.3 and a supported Node.js version.
  • Pi loads the TypeScript sources directly, so there is no build step.
  • TypeScript checks the extension, tests, and scripts. It skips checks on dependency declarations.

Development commands

npm ci --ignore-scripts
npm run check          # check Biome formatting and lint rules, then typecheck
npm test               # run all three projects and enforce coverage thresholds
npm run test:watch     # rerun affected tests without whole-suite gates
npm run test:unit      # run tests for individual modules
npm run test:integration # run tests across extension and host boundaries
npm run test:e2e       # drive the Pi CLI against a loopback Anthropic endpoint
npm run test:coverage  # run the full suite and write reports to coverage/
npm run bench          # measure offline copy-code sign-in with and without paste retries
npm run audit          # fail on high or critical dependency advisories
npm run pack:check     # list the files that would ship
npm run test:package   # install the tarball in a temporary directory and load it in offline Pi
npm run test:package -- path/to/package.tgz # load a specific tarball instead of packing
npm run dev            # load this checkout in Pi

If Pi has no configured model, use /login before sending a prompt. npm run dev uses your Pi configuration.

Versioning

Before 1.0, releases can contain breaking changes. Check the BREAKING CHANGES section in CHANGELOG.md before upgrading.

Releasing

See how to stage and approve npm releases.

Source layout

src/
  index.ts            extension entry: provider, card renderer, /claude command
  provider.ts         OAuth override for the native Anthropic provider
  login.ts            browser, copy-code, and setup-token login methods
  oauth.ts            endpoints, PKCE, authorize URL, token exchange, refresh
  callback-server.ts  loopback redirect handler
  credential.ts       credential shaping and setup-token rules
  usage.ts            /api/oauth/usage lookup and formatting
  commands.ts         /claude status and usage cards
  ui.ts               durable card renderer

Limitations

  • Anthropic does not publish a long-term stability contract for this OAuth flow.
  • If Claude Code changes endpoints, scopes, or headers, the constants in oauth.ts and usage.ts need the same change.
  • Usage windows come from Claude's internal usage endpoint.
  • When Claude's internal usage endpoint is unavailable, /claude usage reports the HTTP status instead of guessing.