An open API service indexing awesome lists of open source software.

https://github.com/leohenon/pi-anthropic-oauth

Pi extension for Anthropic OAuth with Claude Pro/Max.
https://github.com/leohenon/pi-anthropic-oauth

anthropic claude pi pi-agent pi-extensions

Last synced: about 17 hours ago
JSON representation

Pi extension for Anthropic OAuth with Claude Pro/Max.

Awesome Lists containing this project

README

          

# pi-anthropic-oauth

[![npm](https://img.shields.io/npm/v/pi-anthropic-oauth?style=flat-square&logo=npm&logoColor=white&label=npm&color=7c3aed)](https://www.npmjs.com/package/pi-anthropic-oauth)

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

```bash
pi install npm:pi-anthropic-oauth
```

Start Pi, then run Pi's login command:

```text
/login
```

Choose:

```text
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:

```bash
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`:

```bash
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:

```bash
PI_ANTHROPIC_OAUTH_REWRITE_MODE=custom
PI_ANTHROPIC_OAUTH_REWRITE_PATTERN='(? [!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