Skip to content

feat(auth): sync Claude Code CLI OAuth credentials for auto-refresh - #4894

Closed
GodsBoy wants to merge 1 commit into
openclaw:mainfrom
GodsBoy:feat/claude-cli-oauth-sync
Closed

GodsBoy wants to merge 1 commit into
openclaw:mainfrom
GodsBoy:feat/claude-cli-oauth-sync

Conversation

@GodsBoy

@GodsBoy GodsBoy commented Jan 30, 2026

Copy link
Copy Markdown
Contributor

Summary

When Anthropic OAuth tokens expire, users must re-run openclaw onboard which creates a setup-token — a limited token that only has user:inference scope. This breaks usage tracking (/status) which requires user:profile scope, and the token itself cannot be auto-refreshed.

Meanwhile, Claude Code CLI (~/.claude/.credentials.json) stores full OAuth credentials with both access and refresh tokens, plus all scopes including user:profile. OpenClaw already syncs credentials from Qwen CLI via external-cli-sync.ts, but not from Claude Code CLI.

Changes

1. Claude CLI credential sync (external-cli-sync.ts)

Extends syncExternalCliCredentials() to import credentials from Claude Code CLI, following the existing Qwen CLI pattern:

  • Full OAuth (access + refresh + expiry): stored as type: "oauth", enabling auto-refresh via the existing refreshOAuthTokenWithLock() infrastructure
  • Setup-token fallback (access only, no refresh): stored as type: "token" when no refresh token is available

2. Un-deprecate Claude CLI profile (doctor-auth.ts)

The anthropic:claude-cli profile was previously deprecated in favor of setup-token. Since Claude CLI sync now provides superior credentials (full OAuth with refresh + all scopes), the deprecation warning is removed. The doctor hint now recommends claude login to refresh credentials.

3. Generalize isExternalProfileFresh()

Accepts an optional provider parameter so it can check freshness for any CLI provider, not just qwen-portal.

4. Integration tests (external-cli-sync.test.ts)

Five tests using temporary credential files:

  • Imports full OAuth credentials from Claude CLI
  • Imports setup-token credentials (no refresh token)
  • Updates expired OAuth profile with fresher credentials
  • Skips sync when existing profile is still fresh
  • Does not mutate when no Claude CLI credentials exist

Why this matters

Problem Before After
Token expires Manual re-auth via openclaw onboard Auto-refresh via stored refresh token
Re-onboarding scope setup-token = user:inference only Full OAuth = all scopes incl. user:profile
Usage tracking Breaks after re-onboard Preserved (user:profile scope maintained)
Credential import Manual token paste Automatic sync from ~/.claude/.credentials.json

Context

Supersedes #4615 (which only warned about the scope issue) by addressing the root cause.
Complements #4593 (don't warn about expired OAuth tokens with valid refresh tokens).

Related Claude Code issues:

@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations agents Agent runtime and tooling labels Jan 30, 2026
Add Claude Code CLI credential sync to external-cli-sync, matching the existing Qwen CLI pattern. When ~/.claude/.credentials.json contains full OAuth credentials (access + refresh token), they are imported as type: oauth profiles enabling automatic token refresh.

Changes:
- external-cli-sync.ts: add Claude CLI sync (OAuth + setup-token fallback)
- doctor-auth.ts: un-deprecate anthropic:claude-cli profile
- external-cli-sync.test.ts: integration tests
- isExternalProfileFresh: accept optional provider param

Supersedes openclaw#4615. Complements openclaw#4593.
@GodsBoy
GodsBoy force-pushed the feat/claude-cli-oauth-sync branch from 66ff22a to 81abade Compare January 31, 2026 21:46
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: bluebubbles Channel integration: bluebubbles channel: discord Channel integration: discord channel: googlechat Channel integration: googlechat channel: imessage Channel integration: imessage channel: line Channel integration: line channel: matrix Channel integration: matrix channel: mattermost Channel integration: mattermost channel: msteams Channel integration: msteams channel: nextcloud-talk Channel integration: nextcloud-talk channel: nostr Channel integration: nostr channel: signal Channel integration: signal channel: slack Channel integration: slack channel: telegram Channel integration: telegram channel: tlon Channel integration: tlon channel: voice-call Channel integration: voice-call channel: whatsapp-web Channel integration: whatsapp-web channel: zalo Channel integration: zalo channel: zalouser Channel integration: zalouser app: android App: android app: ios App: ios app: macos App: macos gateway Gateway runtime extensions: copilot-proxy Extension: copilot-proxy extensions: diagnostics-otel Extension: diagnostics-otel labels Jan 31, 2026
@openclaw-barnacle openclaw-barnacle Bot added extensions: google-antigravity Extension: google-antigravity extensions: google-gemini-cli-auth Extension: google-gemini-cli-auth extensions: llm-task Extension: llm-task extensions: lobster Extension: lobster extensions: memory-core Extension: memory-core extensions: memory-lancedb Extension: memory-lancedb extensions: open-prose Extension: open-prose extensions: qwen-portal-auth Extension: qwen-portal-auth cli CLI command changes security Security documentation scripts Repository scripts docker Docker and sandbox tooling labels Jan 31, 2026
@clawdinator

clawdinator Bot commented Feb 1, 2026

Copy link
Copy Markdown
Contributor

closing thumbs up

CLAWDINATOR FIELD REPORT // PR Closure

I am CLAWDINATOR — cybernetic crustacean, maintainer triage bot for OpenClaw. I was sent from the future to keep this repo shipping clean code.

TARGET ACQUIRED. I have reviewed your PR. Your effort is br00tal.

Reality check: OpenClaw is in feature freeze while we stabilize the system. That means any new feature PRs are getting cleared out, no matter how shiny. This one falls into that bucket, so I’m closing it to keep the queue from exploding.

Think this belongs in the release after freeze? Come with me if you want to ship. Report to #pr-thunderdome-dangerzone on Discord — READ THE TOPIC or risk immediate termination. Bring the maintainers a clear briefing (impact, testing, why it survives the freeze).

I’ll be back. Stay br00tal.

🤖 This is an automated message from CLAWDINATOR, the OpenClaw maintainer bot.

@clawdinator clawdinator Bot closed this Feb 1, 2026
@thewilloftheshadow thewilloftheshadow added the trigger-response Maintainer trigger to rerun Barnacle auto-response on an item. label Feb 12, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the trigger-response Maintainer trigger to rerun Barnacle auto-response on an item. label Feb 12, 2026
@openclaw-barnacle

Copy link
Copy Markdown

Closing this PR because it has more than 20 labels, which usually means the branch is too noisy. Please recreate the PR from a clean branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: android App: android app: ios App: ios app: macos App: macos channel: bluebubbles Channel integration: bluebubbles channel: discord Channel integration: discord channel: googlechat Channel integration: googlechat channel: imessage Channel integration: imessage channel: line Channel integration: line channel: matrix Channel integration: matrix channel: mattermost Channel integration: mattermost channel: msteams Channel integration: msteams channel: nextcloud-talk Channel integration: nextcloud-talk channel: nostr Channel integration: nostr channel: signal Channel integration: signal channel: slack Channel integration: slack channel: telegram Channel integration: telegram channel: tlon Channel integration: tlon channel: voice-call Channel integration: voice-call channel: whatsapp-web Channel integration: whatsapp-web channel: zalo Channel integration: zalo channel: zalouser Channel integration: zalouser cli CLI command changes commands Command implementations docker Docker and sandbox tooling docs Improvements or additions to documentation extensions: copilot-proxy Extension: copilot-proxy extensions: diagnostics-otel Extension: diagnostics-otel extensions: google-antigravity Extension: google-antigravity extensions: google-gemini-cli-auth Extension: google-gemini-cli-auth extensions: llm-task Extension: llm-task extensions: lobster Extension: lobster extensions: memory-core Extension: memory-core extensions: memory-lancedb Extension: memory-lancedb extensions: open-prose Extension: open-prose extensions: qwen-portal-auth Extension: qwen-portal-auth gateway Gateway runtime scripts Repository scripts security Security documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants