Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
431d7c8
OpenCode 2: custom headers only on API-key routes; cache diagnostics …
ualtinok Nov 23, 2026
3480011
OpenCode 2: subscription price zeroing and Prime at plugin start; Ope…
ualtinok Nov 23, 2026
06a33ed
Pi: turn billing lineage and the hybrid 20-block bridge marker, as on…
ualtinok Nov 23, 2026
c3a7ad6
OpenCode 1 on Thalamus: shared routing in every mode, wait-start repo…
ualtinok Nov 23, 2026
76ac9f6
OpenCode 1: keep-warm and thread cache boundary survive restarts; war…
ualtinok Nov 23, 2026
219290a
Pi /claude: quota refresh, limit editors and lane start, as on OpenCode
ualtinok Nov 23, 2026
96f4d32
mason: align Pi header quota and paid model routing
ualtinok Nov 23, 2026
b2e13fe
mason: add Pi conversation cache diagnostics
ualtinok Nov 23, 2026
2174ce7
Paid API-key requests unshaped on every host; ANTHROPIC_INSECURE removed
ualtinok Nov 23, 2026
75b281b
mason: align cache default and remove OpenCode quota feed
ualtinok Nov 23, 2026
15352e7
mason: align strict test expectations with host parity
ualtinok Nov 23, 2026
c5714d7
mason: restore CacheKeep prewarms without turn diagnostics
ualtinok Nov 23, 2026
d760593
mason: exercise the right CacheKeep tick and cache default
ualtinok Nov 23, 2026
8db8f60
Test comments: say what the Prime timer is
ualtinok Nov 23, 2026
3508c5c
Docs: ARCHITECTURE.md and STRUCTURE.md match host parity
ualtinok Nov 23, 2026
64080c1
Changelog: parity entries under Unreleased after the 2.16.6 release
ualtinok Nov 23, 2026
d09e41d
OpenCode 1: a routing ask after a failed attempt doesn't wait for cap…
ualtinok Nov 23, 2026
49186bf
Comment: say which host imposes the 5-minute limit
ualtinok Nov 23, 2026
5e7c897
OpenCode 1 shared routing: provider waits, credential failures, paid …
ualtinok Nov 23, 2026
3f7542c
Pi: paid requests keep Pi's own cache markers; hybrid layout independ…
ualtinok Nov 23, 2026
6e4e08c
Keep-warm restore never delays OpenCode startup; one claim per sessio…
ualtinok Nov 23, 2026
5100e75
Pi: use Core's shared keep-warm session claim
ualtinok Nov 23, 2026
5964445
Cache diagnostics never delay OpenCode 2 or Pi replies; reply IDs cap…
ualtinok Nov 23, 2026
b11eb8d
Changelog: parity audit fixes
ualtinok Nov 23, 2026
41e7f70
Comments and changelog wording from review
ualtinok Nov 23, 2026
3af1d9a
Tests: Pi killswitch-set leaves the switch alone; loopback test fetch…
ualtinok Nov 23, 2026
d7e754d
Keep-warm session claims survive a wall-clock step during setup and a…
ualtinok Nov 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 34 additions & 21 deletions ARCHITECTURE.md

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,40 @@ This repo is a CortexKit-maintained Anthropic auth monorepo for OpenCode and Pi.

- OpenCode 1, OpenCode 2 and Pi: when shared routing reports that every account is at its concurrent-request limit, requests wait for a free slot instead of ending the turn.
- OpenCode: the one-time state move no longer treats a running older plugin as gone after the system clock is corrected forward. A start with a different XDG_STATE_HOME no longer moves the state while an earlier move under another state folder is unfinished; it stops and says to start again with the setting used then.
- OpenCode 1 CacheKeep can run a one-off prewarm again without dropping its normal account and destination checks.
- Pi keep-warms no longer send the conversation's previous message ID to Claude.
- OpenCode 1: idle sessions can keep warming a still-live Claude prompt cache after a server restart without resetting their budgets; `auto` keep-warm now uses the accepted prefix's token counts to price warms, even without a restart.
- OpenCode 1: after a server restart, a threaded session's first full request can reuse the previous full request's cache boundary, as on OpenCode 2 and Pi.
- OpenCode 1 and Pi: eligible direct CacheKeep requests now use gzip, like OpenCode 2, and resend uncompressed if gzip is rejected.
- OpenCode 1: keep-warm requests no longer appear in cache diagnostics or replace the previous real response, as on OpenCode 2.
- OpenCode 1 and Pi now send paid API-key requests like OpenCode 2, without adding a Claude Code prompt or billing signature or renaming tools. Claude subscription requests are unchanged.
- OpenCode 1, OpenCode 2 and Pi always verify TLS for API-key requests to custom HTTPS addresses. The `ANTHROPIC_INSECURE` environment variable is gone.
- OpenCode 2 now keeps custom proxy headers off Claude sign-in requests, like OpenCode 1 and Pi, while still sending them on API-key routes.
- For conversation requests, OpenCode 2 now matches OpenCode 1: the first eligible request sends a null previous message ID, and cache results and beta lists appear in debug logs.
- OpenCode 2: Claude subscription models now show zero token prices by default, like OpenCode 1. You can opt out to display catalogue prices; API-key prices are unchanged.
- OpenCode 1 and 2: opt-in Prime can start a quota window without a first chat request, and enabling Prime in the settings file takes effect without restarting OpenCode.
- Pi now links Claude subscription requests to the same user turn across tool calls and retries, matching OpenCode 1 and 2.
- Pi's hybrid prompt cache now reuses an earlier conversation boundary after long replies or tool exchanges, matching OpenCode 1 and 2.
- OpenCode 1 on Thalamus now asks for the shared login choice in every routing mode and when switching logins on a retry, like OpenCode 2.
- OpenCode 1 on Thalamus now reports when a request starts waiting for routing or quota, like OpenCode 2; OpenCode still handles the wait.
- OpenCode 1 on Thalamus now reports which login paid for each Claude send and how many tokens it used, including relayed sends and keep-warm requests, like OpenCode 2.
- Pi: `/claude` can now refresh quota and edit quota floors, like OpenCode 1 and 2.
- Pi: `/claude` can now start a five-hour quota window with a one-time request, like OpenCode 1 and 2.
- Pi, like OpenCode 1 and 2, now updates each subscription account's quota from Claude's replies without waiting for the next quota poll.
- Pi's paid API-key route now honors the same model aliases as OpenCode 1 and 2 and keeps its configured endpoint.
- Pi now links cache diagnostics across conversation replies like OpenCode 1 and 2, with cache results and beta lists in the debug log.
- OpenCode 2 now uses the five-minute Claude prompt cache by default, like OpenCode 1 and Pi. An explicit cache setting or Agent Runner session policy still takes precedence.
- OpenCode 1 no longer publishes the optional quota header feed; quota readings still reach the vault. The `quota_header_feed_enabled` setting is gone and can be deleted from your settings file.
- OpenCode 1 on Thalamus honors Claude's own wait before using the main login, even when shared routing picks it, and tries another eligible login when a routing pick can't authenticate.
- OpenCode 1 no longer switches to a paid API key on a retry where shared routing picked a login, retries an earlier login once when nothing untried can serve, and asks shared routing before sending one-shot request bodies.
- OpenCode 1 and 2 no longer wait for saved keep-warm sessions before starting or sending the first request.
- OpenCode 1 and 2 servers sharing an account store no longer warm the same saved session twice or overwrite its warm budget; all three hosts now use one keep-warm session claim.
- Pi's paid API-key requests keep Pi's own prompt-cache markers.
- Pi's hybrid cache keeps the same layout at five minutes and one hour, can reuse a long first prompt's cache after a long tool exchange, and lets forks reach the head's cache at the 20-block lookback limit.
- Pi: only the cache-warming request queued from `/claude` is cut to one token (a prompt with the same text is sent normally), and it no longer joins the conversation's request chain.
- Pi: `/claude` quota refresh continues when one account fails, and editing killswitch thresholds no longer turns the killswitch on.
- OpenCode 2 and Pi no longer wait for optional cache diagnostics before delivering replies, and keep diagnostics linked to the latest reply when detailed cache usage is missing.
- OpenCode 2 keeps subscription prices at zero when a credential lookup fails temporarily.

## 2.16.6

Expand Down
9 changes: 6 additions & 3 deletions STRUCTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ docs/ public user and contributor documentation
- **Menus:** `native-menu-model.ts`, `native-menu-executor.ts` and `native-ui.ts`. `commands/account.ts` holds the account command execution.
- **Request:**
- Claude Code shape: `claude-code.ts`, `cch.ts` (billing header and body signature), `constants.ts` (the emulated Claude Code version and betas).
- Paid API-key routes: `api-key-request.ts` (history checks, internal-marker cleanup and model aliases without OAuth shaping) and `api-route-url.ts` (saved URL and environment precedence).
- Cache diagnostics: `cache-diagnostics.ts` (previous-message tracking, record validation and debug formatting shared by all hosts).
- Per-model handling: `model-capabilities.ts` (one row per model) and `models.ts` (catalogue and pricing).
- Mid-conversation controls: `thinking-binding.ts`, `mid-conversation-output-config.ts` (effort markers) and `turn-end-note.ts`.
- History and transport: `request-history.ts` (structural checks), `message-threads.ts`, `request-gzip.ts`, `relay.ts`, `oauth-origin.ts` and `request-abort.ts`.
- **Routing and quota:**
- Routing: `routing.ts` and `sticky-routing.ts`.
- Quota policy: `killswitch.ts`, `quota-refusal.ts` and `session-cache-activity.ts`.
- Quota readings: `quota-manager.ts`, `quota-headers.ts`, `quota-header-feed.ts`, `insula-quota.ts` and `quotas.ts`.
- Quota readings: `quota-manager.ts`, `quota-headers.ts`, `insula-quota.ts` and `quotas.ts`.
- **Cache:** `cache1h.ts`, `session-cache-policy.ts` (per-session policy from Thalamus), `cachekeep.ts`, `cachekeep-store.ts` (restart store), `cachekeep-registry.ts` (session list) and `prime.ts`.
- **State layout:** `state-layout-*.ts`, `holder-registry.ts`, `layout-fence.ts`, `relocation-guard.ts` and `state-home-serving-guard.ts`.
- **Shared plumbing:** `logger.ts`, `logging.ts`, `dump.ts`, `json.ts` (redacting JSON parse), `sse.ts`, `owner-only.ts`, `publication-rename.ts`, `network-errors.ts` and `provider-error.ts`.
Expand All @@ -51,6 +53,7 @@ docs/ public user and contributor documentation

- `index.ts`: the OpenCode 1 plugin factory. It must export only `AnthropicAuthPlugin`, because OpenCode's file loader calls every exported function.
- `transform.ts`: OpenCode 1 request and stream rewriting.
- `cachekeep-restart.ts`: OpenCode 1 restart ownership, persistence and staggered restore.
- **Shared by OpenCode 1 and 2:**
- Server fallback and OpenCode 1 recovery rounds: `server-fallback.ts`, `fable-fallback.ts`.
- Request plumbing: `effort-history.ts` (the effort plan), `billing-lineage.ts`, `lane-start.ts`, `routing-relay.ts` (shared routing), `prompt-context.ts`.
Expand All @@ -72,9 +75,9 @@ docs/ public user and contributor documentation

- `index.ts`: extension entry; registers the provider, commands and session hooks.
- `convert.ts` and `transcript.ts`: build the Anthropic body from Pi's context.
- `stream.ts` and `transport.ts`: send, relay, threads and stream mapping.
- `stream.ts` and `transport.ts`: send, relay, threads, billing lineage, quota-header observation, cache diagnostics and stream mapping.
- `native.ts` and `native-commands.ts`: the account runtime and menu.
- `cachekeep.ts` and `cachekeep-claim.ts`: keep-warm, with the restart store and the per-session claim.
- `cachekeep.ts`: keep-warm, with the restart store and Core's per-session claim (`CacheKeepClaim`, shared with OpenCode 1 and 2).
- `prime.ts`: the Prime scheduler, which sends through `stream.ts`'s registered Prime sender.
- Other files: `effort-history.ts`, `quota-wait.ts`, `custody.ts` and `paths.ts`.

Expand Down
6 changes: 2 additions & 4 deletions docs/accounts-and-routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,15 @@ Sticky-balanced waits on the assigned account only when every exhausted window b

## Quota and limits

Quota shows five-hour, seven-day and model-scoped windows when available. OpenCode's **Refresh quota** action requests fresh readings; Pi shows the summary without a refresh action. Passive response headers and quota API polling have different coverage: headers can update standard windows without supplying model-scoped limits.
Quota shows five-hour, seven-day and model-scoped windows when available. OpenCode's **Refresh quota** action requests fresh readings; Pi shows the summary without a refresh action. On OpenCode 1, OpenCode 2 and Pi, response headers can update the standard windows before the next quota poll. Quota polls supply the model-scoped limits and extra usage shown in the summary.

Quota figures use the shared wording, such as `5h 40% left, resets 2h29m` and `7d 70% left, resets 3d23h`. Readings older than fifteen minutes include their age, such as `checked 1d6h ago`. Extra usage is shown as `credits 40% left` or `credits spent`, followed by the amount spent and the monthly limit in your account's currency: `credits 75% left · $25.00/$100.00`, `credits spent · $100.35/$100.00`. Without a limit (or without amounts), only the credit figure is shown. In a narrow OpenCode sidebar, amounts that would make the line too wide are shown without cents (`$1,250/$5,000`), and the collapsed sidebar's one-line form is unchanged.

`quota_minimum_remaining_five_hour` and `quota_minimum_remaining_seven_day` are minimum **remaining** percentages, not usage percentages (`5h` and `1w` are menu aliases). `quota_fail_closed_on_unknown_quota` controls unknown readings where no positive killswitch floor applies. Killswitch thresholds are separate hard blocks:

- A positive five-hour or seven-day floor blocks missing readings for that window regardless of `failClosedOnUnknownQuota`.
- A positive `scoped` minimum-remaining percentage blocks missing model-specific quota information. An explicitly empty scoped-window list means no separate window applies.
- OpenCode can edit killswitch thresholds in **Limits**; Pi does not expose those edits.

The optional `quota_header_feed_enabled` setting is OpenCode-only, disabled by default and requires restart. It publishes allowlisted quota observations, opaque identity and timestamps to owner-only temporary lease files, not tokens, request bodies, model IDs or refresh errors. It shares observations already obtained from responses rather than making new quota API requests.
- OpenCode and Pi can edit killswitch thresholds in **Limits**.

## Settings and custody

Expand Down
8 changes: 5 additions & 3 deletions docs/cache-diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

## Measure-only beta

The Anthropic API opt-in `cache-diagnosis-2026-04-07` (sent in the `anthropic-beta` header) asks for cache diagnostics; it does not change cache controls or routing. OpenCode captures the response's opaque top-level message ID and sends it as `diagnostics.previous_message_id` on the next request in that session. The first request sends `null`.
The Anthropic API opt-in `cache-diagnosis-2026-04-07` (sent in the `anthropic-beta` header) asks for cache diagnostics; it does not change cache controls or routing. OpenCode 1, OpenCode 2 and Pi capture the response's opaque top-level message ID and send it as `diagnostics.previous_message_id` on the next eligible request in that session. The first eligible request sends `null`. On Pi, session-associated Claude sign-in requests can use the preceding ID, but only the main conversation advances it. Paid API-key requests, forks, Prime and keep-warm do not advance that chain or write its diagnostic records.

Keep-warm requests on OpenCode do not opt in to cache diagnostics or change the previous-message ID. In older OpenCode 1 logs, `prewarm_cachekeep` identifies a keep-warm response.

`MC-CACHE-DIAG ` records and the beta-list side channel are emitted only at debug level. Choose **Logging level** → `debug` in `/claude` → **Diagnostics**. An empty stream can mean no activity or a lower log level: compare it with an independent activity witness such as usage rows, billing or dumps before drawing conclusions.

Expand All @@ -18,7 +20,7 @@ Each record is one JSON line after the exact prefix `MC-CACHE-DIAG `, including
| `account_id` | Opaque persisted routing/account identifier; do not validate its string shape |
| `betas_hash` | 16-character lowercase xxHash64 (seed 0) of the sorted sent beta list |
| `requested_model` | Optional sent model, only when different from the response model |
| `session_id` | OpenCode session affinity |
| `session_id` | Identifier of the host conversation this record belongs to |
| `ts_ms_received` | Integer local receipt time |
| `model` | Anthropic response model |
| `is_subagent` | Original request context |
Expand Down Expand Up @@ -58,4 +60,4 @@ A short-gap `previous_message_not_found` reason is also captured as a canary whe

When dumps are enabled, `.response.json` holds status and parsed response metadata without response content. Lane-start filenames include `-start-`; CacheKeep uses `-prewarm-cachekeep-`. Treat related request bodies as sensitive local data. See [dump handling](transports.md#diagnostics-and-dumps) and [the OpenCode history analyzer](cache.md#diagnostics-and-history-analysis) for retrospective estimates.

Implementation: [schema and record validation](../packages/opencode/src/cache-diagnostics.ts), [OpenCode emission](../packages/opencode/src/index.ts), and [wire opt-in](../packages/opencode/src/transform.ts).
Implementation: [schema and record validation](../packages/core/src/cache-diagnostics.ts), with host integrations in [OpenCode 1](../packages/opencode/src/index.ts), [OpenCode 2](../packages/opencode/src/v2/wire.ts) and [Pi](../packages/pi/src/stream.ts).
Loading