Skip to content

fix(agents): keep a Claude Platform login across sessions - #353

Merged
artempartos merged 1 commit into
developfrom
artempartos/claude-cli-platform-auth
Sep 29, 2026
Merged

artempartos merged 1 commit into
developfrom
artempartos/claude-cli-platform-auth

Conversation

@artempartos

Copy link
Copy Markdown
Contributor

Summary

Logging in to Claude Code through Claude Platform (the Console / API-usage-billing option) never finished in the auth modal, and even once a login existed a session could not use it.

Claude Code 2.1.281 no longer mints a primaryApiKey for this login. It writes the Anthropic profile the SDKs share:

  • ~/.config/anthropic/credentials/default.json — type: oauth_token, access + refresh token, expires_at (epoch s, ~8h), scope, org/workspace/account
  • ~/.config/anthropic/configs/default.json — org, workspace, authentication: {type: user_oauth, client_id}

Our watcher and adapter only looked at .claude.json / .credentials.json, so the login was never detected or captured.

What changes

  • Capture: both profile files are watched and read back; access_token finishes the login. Stored as platformOauth (normalized to the claudeAiOauth shape, so expiry, freshest-copy merging and the refresh sweep treat both logins alike) plus platformProfile.
  • Render: both files are written back on session start and on mid-session delivery, 0600 and agent-owned — the CLI refuses a group/world-readable credentials file (Credentials file at … is group/world-readable), which is what broke the first live session. The config is rebuilt from the token block if it was never captured.
  • Refresh: server-side against api.anthropic.com/v1/oauth/token (JSON body, anthropic-beta: oauth-2025-04-20, the profile's client_id) — the endpoint the CLI itself uses. The URL is fixed in code, never taken from the profile's base_url, so a refresh token never goes to a host a container wrote down. A rejected refresh condemns the credential like a rejected claude.ai base login.
  • Write-back: a running session's own rotation of credentials/default.json is accepted (rotation rules unchanged).
  • One inference credential: a Platform login replaces a stored claude.ai login / API key and vice versa — with both present the CLI silently runs on claude.ai.
  • Image: docker/claude-code/Dockerfile pre-creates ~/.config/anthropic/{credentials,configs} as claude, 0700, so a single-entry tar write doesn't leave them root-owned.
  • UI: "Connect Design" is offered on a Platform login too.
  • Docs: docs/design/oauth-implementation.md, docs/design/agent-credential-lifecycle.md.

MITM logging is unaffected: /oauth/token is already an auth path, so refresh bodies are never logged.

Verification

  • Real Claude Platform login in an isolated worktree stack (CLI 2.1.281): credential captured with platformOauth + platformProfile, a new interactive session started logged in ("API Usage Billing") and answered a prompt; the in-session write-back endpoint accepted the CLI's rotation.
  • Probed the CLI directly: only both files together log it in; claudeAiOauth wins when both are present; exact refresh request shape read from the 2.1.281 binary.
  • make check_all green (backend 93.31%, frontend 82.59%).

Deploy note

Ship main-images with or before the web change: with an old image the platform writes into root-owned auto-created directories. The CLI can still read the files, but cannot rewrite them on its own refresh (the server-side sweep still refreshes).

🤖 Generated with Claude Code

Claude Code 2.1.281's Claude Platform (Console) login no longer mints a
primaryApiKey. It writes the Anthropic profile the SDKs share instead: a
user-OAuth token pair in ~/.config/anthropic/credentials/default.json and the
org, workspace and OAuth client in configs/default.json. The watcher never saw
that login finish, nothing was captured, and a session started logged out.

The adapter now stores the pair as platformOauth (in the claudeAiOauth shape,
so expiry, merging and the refresh sweep treat both logins alike) plus
platformProfile, renders both files back 0600 and agent-owned (the CLI refuses
a group/world-readable credentials file), takes the CLI's own rotations back
from a running session, and refreshes server-side against
api.anthropic.com/v1/oauth/token. A Platform login is its own inference
credential: it replaces a stored claude.ai login and vice versa, since the CLI
prefers claude.ai when both are present.

The image pre-creates ~/.config/anthropic, so a single-entry tar write does not
leave the directories root-owned and the CLI can still rewrite the token.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
@artempartos
artempartos merged commit 410cc90 into develop Sep 29, 2026
7 checks passed
aixle-com Bot pushed a commit that referenced this pull request Nov 26, 2026
The Google-font scan read every file under app/frontend as UTF-8 and
raised on the agent-logo PNGs. Read them with File.binread instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Aixle Flow <[email protected]>
dvislov pushed a commit that referenced this pull request Nov 30, 2026
The OFL-licensed variable woff2 files from @fontsource-variable 5.3.0,
with the same unicode subsets Google Fonts serves, and one stylesheet
under the family names the frontend theme uses. The v1 path segment is
the cache buster: public/ is served with a one-year max-age.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Aixle Flow <[email protected]>
Signed-off-by: Dmitry Vislov <[email protected]>
dvislov pushed a commit that referenced this pull request Nov 30, 2026
Every page, the static error pages and the admin panel sent each
visitor's IP address to Google for fonts. They now link
/fonts/v1/fonts.css, the mailer links no web font, and the CSP drops
the Google hosts and the blanket https: source from font-src and
style-src.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Aixle Flow <[email protected]>
Signed-off-by: Dmitry Vislov <[email protected]>
dvislov pushed a commit that referenced this pull request Nov 30, 2026
The Google-font scan read every file under app/frontend as UTF-8 and
raised on the agent-logo PNGs. Read them with File.binread instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Aixle Flow <[email protected]>
Signed-off-by: Dmitry Vislov <[email protected]>
artempartos added a commit that referenced this pull request Nov 30, 2026
A font bundled by Vite is served from the asset host in production, where the
policy is enforced, so font-src matches script-src and style-src. The partial
takes no locals now; strict locals make a leftover `families:` call fail.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
artempartos added a commit that referenced this pull request Nov 30, 2026
* build(web): vendor Inter, JetBrains Mono and Spline Sans Mono (#353)

The OFL-licensed variable woff2 files from @fontsource-variable 5.3.0,
with the same unicode subsets Google Fonts serves, and one stylesheet
under the family names the frontend theme uses. The v1 path segment is
the cache buster: public/ is served with a one-year max-age.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Aixle Flow <[email protected]>
Signed-off-by: Dmitry Vislov <[email protected]>

* feat(web): load web fonts from our own origin, not Google (#353)

Every page, the static error pages and the admin panel sent each
visitor's IP address to Google for fonts. They now link
/fonts/v1/fonts.css, the mailer links no web font, and the CSP drops
the Google hosts and the blanket https: source from font-src and
style-src.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Aixle Flow <[email protected]>
Signed-off-by: Dmitry Vislov <[email protected]>

* fix(web): scan files as bytes in the self-hosted fonts test (#353)

The Google-font scan read every file under app/frontend as UTF-8 and
raised on the agent-logo PNGs. Read them with File.binread instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Aixle Flow <[email protected]>
Signed-off-by: Dmitry Vislov <[email protected]>

* fix(web): allow asset-host fonts, forbid fonts partial locals (#353)

A font bundled by Vite is served from the asset host in production, where the
policy is enforced, so font-src matches script-src and style-src. The partial
takes no locals now; strict locals make a leftover `families:` call fail.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>

---------

Signed-off-by: Aixle Flow <[email protected]>
Signed-off-by: Dmitry Vislov <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
Co-authored-by: Aixle Flow <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Artem Petrov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant