Framework-agnostic core for using the Claude Code OAuth subscription as an Anthropic provider. No Pi, no LangChain — just the native stack, with zero runtime dependencies.
It exists so the Claude Code internals live in one place and are shared by
@cgaravitoq/open-langchain-ts and the
pi-claude-code-auth Pi extension.
- creds — read/refresh
~/.claude/.credentials.json(and macOS Keychain), with aclaudeCLI fallback and a force-refresh path for 401s. - signing — the reverse-engineered
x-anthropic-billing-header. - model-config —
ccVersion, beta computation (computeBetas/requestBetas) and frozen per-model overrides (adaptive thinking, long context, etc.). - transforms — Claude Code payload reshaping: billing header injection, identity split,
mcp_<PascalCase>tool prefixing, and orphan tool-pair repair.
npm install @cgaravitoq/claude-code-coreESM-only, Node >= 22.19.0.
import {
readClaudeCodeCreds,
refreshClaudeCodeCreds,
applyClaudeCodeTransforms,
requestBetas,
} from "@cgaravitoq/claude-code-core";
const creds = readClaudeCodeCreds();
if (creds) {
const fresh = await refreshClaudeCodeCreds(creds);
// build your Anthropic request, then:
const params = await applyClaudeCodeTransforms(rawParams);
// send with "anthropic-beta": requestBetas(model, longContext).join(",")
}This is the building block, not a chat client — see the consumers above for ready-to-use LangChain chat models or a Pi provider.
Using a subscription OAuth session from a third-party app may violate Anthropic's terms and risk your account.
- Breaking:
buildBillingHeaderValueandapplyClaudeCodeTransformsare now asynchronous because billing signatures use WebCrypto. - Added the Worker-safe
@cgaravitoq/claude-code-core/protocolsubpath for request transforms, model configuration, billing signatures, and OAuth token refresh.
MIT