Anthropic subscription AI connections expire after ~8h: only the access token is stored, env-injected, never refreshed
Summary
An Anthropic subscription AI connection stops working ~8 hours after it is connected. Every run then fails with acpx_turn_failed / ACP agent reported a terminal access failure. until a human clicks Connect again. Reconnecting fixes it for another ~8 hours, so it looks intermittent, but it is deterministic: Paperclip stores a short-lived OAuth access token for Anthropic with no way to refresh it.
Root cause (traced in 2026.916.1)
Only the access token is captured.
server/dist/services/local-ai-credentials.js→readVerifiedLocalAiCredential("anthropic")readsclaudeAiOauth.accessTokenfrom the host's~/.claude/.credentials.jsonand returns just that string. The refresh token in the same file is never stored.For Anthropic the token is env-injected, not file-backed.
server/dist/services/ai-connection-runtime.js:const subscriptionFile = selection.attribution.method === "subscription" && input.binding.provider !== "anthropic"; ... if (subscriptionFile) await writeFile(authFile, value, { mode: 0o600 }); else env[capability.envKey] = value; // anthropic → CLAUDE_CODE_OAUTH_TOKEN(
envKey: "CLAUDE_CODE_OAUTH_TOKEN"inshared/dist/ai-connections.js.)The refresh/rotate path can't apply. The post-run logic that re-reads
authFileand rotates the secret (ai-connection-runtime.js~L222–260,errorLabel: "AI account refresh") only works for the file-backed providers. A staticCLAUDE_CODE_OAUTH_TOKENcannot be refreshed by Claude Code, so nothing ever rotates for Anthropic.Failure surfaces as an "access" session failure. The spawned Claude process gets an auth rejection and reports
_meta.jetbrains.air.sessionFailure.category = "access", whichacpxturns intoACP agent reported a terminal access failure.(prompt-turninacpx/dist/live-checkpoint-*.js). The run record showserrorCode: acpx_turn_failed, and after the pre-flight starts failing,configuration_incomplete/reason: "ai_connection_unavailable"withnextAction: "Reconnect the selected AI account…".
Net effect: Anthropic subscription connections silently expire on the access-token TTL. Agents with no runtimeConfig.aiConnection binding don't hit this because they use the host's live ~/.claude login, which self-refreshes — but once a binding exists it can't be removed through the API (aiConnection is .optional(), not nullable, and PATCH /agents/:id refills it when omitted), so users can't opt back out.
Reproduce
- Sign in to Claude Code on the host (subscription account).
- In Paperclip, connect Anthropic → Claude subscription ("Claude Code is signed in. Click Connect to use this account.") and bind an agent to it (
responsible_userorshared). - Run tasks — they work.
- Wait for the access token TTL (~8h; the host's
~/.claude/.credentials.jsonexpiresAtshows when). - Every run now fails with
ACP agent reported a terminal access failure.Click Connect again → works again for ~8h.
Observed: 5/5 runs on one agent failed identically over ~10h, then succeeded immediately after POST /companies/:id/ai-connections/local with the existing connectionId (re-snapshot), with no other change.
Expected
Either store the refresh token as well and refresh before/after runs (as the file-backed providers effectively get), or give the Anthropic subscription flow a file-backed CLAUDE_CONFIG_DIR so Claude Code can refresh it itself, or at minimum surface "token expired — reconnect" instead of a generic access failure.
Workaround in use
A systemd user timer re-runs the local reconnect every 4h:
POST /api/companies/<companyId>/ai-connections/local with {provider:"anthropic", method:"subscription", ownership:"personal", connectionId:"<existing>"}. It works because readVerifiedLocalAiCredential re-reads the host's (self-refreshing) login and verifies it with fetchClaudeQuota before storing.
Related
While debugging, PATCH /agents/:id with any change to an agent that has an aiConnection binding consistently returned 422 The selected AI connection failed validation in this agent’s environment (the validateManagedAgentBinding(..., test=true) hello-probe with engine: "cli"), even while normal persistent-session runs on the same connection succeeded. Happy to split that into its own issue if useful.
Environment
- Paperclip
2026.916.1(server, adapter-claude-local, shared, adapter-utils all2026.916.1), embedded Postgres,local_trustedmode - Claude Code
2.1.273, Claude Pro subscription - Linux (Arch/Omarchy), agents on
claude_local,mode: persistent
Source: paperclipai/paperclip