diff options
| author | Adam Malczewski <[email protected]> | 2026-05-30 18:53:42 +0900 |
|---|---|---|
| committer | Adam Malczewski <[email protected]> | 2026-05-30 18:53:42 +0900 |
| commit | 2228691e14be2368394e38e600bfa2ce227487b1 (patch) | |
| tree | d6b3cfffd11dc9f7eec8c88f5fc97a7ec81e61a0 /packages/core/src/credentials | |
| parent | 497b397e873f96d6fde3d8a44b3318e1ee1cbef4 (diff) | |
| download | dispatch-2228691e14be2368394e38e600bfa2ce227487b1.tar.gz dispatch-2228691e14be2368394e38e600bfa2ce227487b1.zip | |
feat(cache): Anthropic prompt caching, usage telemetry, and Cache Rate view
- send prompt-caching + oauth anthropic-beta headers on the Claude OAuth provider
- restructure the OAuth request body (billing header, identity split, relocate
third-party system prompt to the first user message) to match Claude Code
- apply rolling cache_control breakpoints and group a turn's tool results into a
single role:tool message for correct breakpoint placement
- emit per-step usage events (cache read/write split) and add the Cache Rate
sidebar panel
- dedup byte-identical tool calls within a single batch
Diffstat (limited to 'packages/core/src/credentials')
| -rw-r--r-- | packages/core/src/credentials/anthropic-betas.ts | 24 | ||||
| -rw-r--r-- | packages/core/src/credentials/claude.ts | 21 |
2 files changed, 30 insertions, 15 deletions
diff --git a/packages/core/src/credentials/anthropic-betas.ts b/packages/core/src/credentials/anthropic-betas.ts new file mode 100644 index 0000000..f2ca7a6 --- /dev/null +++ b/packages/core/src/credentials/anthropic-betas.ts @@ -0,0 +1,24 @@ +// ─── Anthropic Beta Headers ─────────────────────────────────── +// +// The set of `anthropic-beta` features the official Claude Code CLI sends on +// every request. Kept in a dependency-free module (no DB / `bun:sqlite` +// import) so the LLM provider layer (`llm/provider.ts`) can pull the list in +// without dragging the whole credentials/DB stack into its import graph. +// +// `prompt-caching-scope-2026-01-05` is load-bearing for cost: without it the +// Anthropic API silently ignores every `cache_control` breakpoint we place, +// producing a 0% cache hit rate (see claude-report.md). `oauth-2025-04-20` +// gates the Bearer/OAuth flow used by Claude Pro/Max subscriptions. + +const BASE_BETAS = [ + "claude-code-20250219", + "oauth-2025-04-20", + "interleaved-thinking-2025-05-14", + "prompt-caching-scope-2026-01-05", + "context-management-2025-06-27", + "advisor-tool-2026-03-01", +]; + +export function getAnthropicBetas(): string[] { + return [...BASE_BETAS]; +} diff --git a/packages/core/src/credentials/claude.ts b/packages/core/src/credentials/claude.ts index 6018207..168d544 100644 --- a/packages/core/src/credentials/claude.ts +++ b/packages/core/src/credentials/claude.ts @@ -10,8 +10,14 @@ import { import { homedir } from "node:os"; import { basename, dirname, join } from "node:path"; import { getDatabase } from "../db/index.js"; +import { getAnthropicBetas } from "./anthropic-betas.js"; import { getStoredCredentials, listStoredCredentials, updateStoredTokens } from "./store.js"; +// Re-exported for backward compatibility — `getAnthropicBetas` historically +// lived here and is surfaced through `credentials/index.ts`. The definition +// now lives in the dependency-free `anthropic-betas.ts` module. +export { getAnthropicBetas }; + export interface ClaudeCredentials { accessToken: string; refreshToken: string; @@ -367,21 +373,6 @@ export function buildBillingHeaderValue( export const SYSTEM_IDENTITY = "You are Claude Code, Anthropic's official CLI for Claude."; -// ─── Anthropic Beta Headers ─────────────────────────────────── - -const BASE_BETAS = [ - "claude-code-20250219", - "oauth-2025-04-20", - "interleaved-thinking-2025-05-14", - "prompt-caching-scope-2026-01-05", - "context-management-2025-06-27", - "advisor-tool-2026-03-01", -]; - -export function getAnthropicBetas(): string[] { - return [...BASE_BETAS]; -} - // ─── Anthropic Request Headers ──────────────────────────────── export function getAnthropicHeaders(accessToken: string): Record<string, string> { |
