Skip to content

fix: show actionable hint when setup-token lacks user:profile scope - #4615

Closed
GodsBoy wants to merge 1 commit into
openclaw:mainfrom
GodsBoy:fix/setup-token-usage-scope-hint
Closed

GodsBoy wants to merge 1 commit into
openclaw:mainfrom
GodsBoy:fix/setup-token-usage-scope-hint

Conversation

@GodsBoy

@GodsBoy GodsBoy commented Jan 30, 2026

Copy link
Copy Markdown
Contributor

Summary

When Anthropic setup-token auth is used for onboarding, the OAuth usage endpoint returns HTTP 403 because setup-token only grants user:inference scope — not user:profile which is required for usage tracking. Users see a cryptic error in /status with no guidance on how to fix it.

Changes

1. Actionable error message (provider-usage.fetch.claude.ts)

When the 403 scope error occurs and no claude.ai web session fallback is available, return a clear error:

setup-token missing user:profile scope — run \claude login` (full OAuth) to enable usage tracking`

Previously, this fell through to the generic HTTP 403: OAuth token does not meet scope requirement user:profile message with no remediation guidance.

2. Post-onboard warning (auth-choice.apply.anthropic.ts)

After completing setup-token onboarding, display a note explaining:

  • setup-token does not include user:profile scope
  • Usage tracking in /status won't work with this token
  • How to upgrade: run claude login then openclaw models auth paste-token

3. New test (provider-usage.test.ts)

Added test for the no-fallback scope error path, verifying the actionable error message is returned when no CLAUDE_AI_SESSION_KEY is available.

Context

Closes #4614

The root cause is upstream in Claude Code CLI — setup-token only requests user:inference scope while claude login (full browser OAuth) requests all scopes including user:profile. This PR improves the user experience until/unless the upstream scope issue is resolved.

Related Claude Code issues:

When Anthropic setup-token auth is used, the OAuth usage endpoint returns
403 because setup-token only grants user:inference scope, not user:profile.

This change:
1. Returns a clear, actionable error message suggesting `claude login`
   (full OAuth) when the scope error occurs and no web session fallback
   is available, instead of the generic 'HTTP 403: ...' message.
2. Adds a post-onboard note during setup-token flow warning users that
   usage tracking in /status requires the full OAuth flow.
3. Adds a test for the no-fallback scope error path.

Refs:
- anthropics/claude-code#16075
- anthropics/claude-code#15243
- anthropics/claude-code#12020
@GodsBoy

GodsBoy commented Jan 30, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favor of #4894 which addresses the root cause (auto-sync Claude CLI OAuth credentials with refresh token) rather than just warning about the scope limitation. The new PR supersedes this by enabling auto-refresh and preserving all OAuth scopes including user:profile.

@GodsBoy GodsBoy closed this Jan 30, 2026
GodsBoy added a commit to GodsBoy/openclaw that referenced this pull request Jan 31, 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 added a commit to GodsBoy/openclaw that referenced this pull request Feb 1, 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.

This solves three problems:
1. Token expiry requires manual re-auth (auto-refresh via refresh token)
2. Re-onboarding with setup-token loses user:profile scope (full OAuth
   preserves all scopes including usage tracking)
3. No easy path to import Claude Code credentials (automatic sync)

Changes:
- external-cli-sync.ts: add Claude CLI sync (OAuth + setup-token fallback)
- doctor-auth.ts: un-deprecate anthropic:claude-cli profile, update hint
  to recommend `claude login` for refresh
- external-cli-sync.test.ts: integration tests using temp credential files
- isExternalProfileFresh: accept optional provider param for multi-CLI use
- Refactored Qwen sync to use shared syncExternalCliCredentialsForProvider

Supersedes openclaw#4615 (scope hint) by addressing the root cause.
Complements openclaw#4593 (don't warn about expired tokens with refresh tokens).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Usage tracking broken for setup-token auth (missing user:profile scope)

1 participant