claude-code - 💡(How to fix) Fix claude setup-token outputs OAuth token wrapped across two lines, breaks copy-paste [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#54738Fetched 2026-04-30 06:37:22
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
0
Timeline (top)
labeled ×5commented ×1

Error Message

Failed to authenticate. API Error: 401 {"type":"error","error":{"type":"authentication_error","message":"Invalid bearer token"}}

RAW_BUFFERClick to expand / collapse

What happened

Running claude setup-token prints the generated OAuth token wrapped across two lines instead of a single line. Selecting the visible value with the mouse and copying it captures the embedded line break, which produces a malformed token.

Pasting that value into a secret store (e.g. CLAUDE_CODE_OAUTH_TOKEN in GitHub Actions) and using it later results in a 401 from the Anthropic API:

``` Failed to authenticate. API Error: 401 {"type":"error","error":{"type":"authentication_error","message":"Invalid bearer token"}} ```

The CLI itself reports the token is set with a plausible length (80 chars in our case), so the failure is not obvious from local diagnostics — it only surfaces when the API rejects it.

What I expected

The token should be printed as a single, unwrapped line so it can be copied verbatim. Either:

  • emit it on its own line with no formatting, or
  • emit it surrounded by clear delimiters (e.g. `BEGIN TOKEN` / `END TOKEN`) so users know the exact byte boundaries to copy.

Repro

  1. `claude setup-token` (with a Pro/Max account)
  2. Complete the browser OAuth flow
  3. Observe that the printed token visually wraps across two terminal lines
  4. Mouse-select and copy the value, paste into a GitHub Actions secret
  5. From CI, run `claude --print` with that secret as `CLAUDE_CODE_OAUTH_TOKEN` → 401 invalid bearer token

Environment

  • CLI version: `2.1.123 (Claude Code)`
  • macOS default Terminal.app

Suggested fix

Bypass any line-wrap-aware printer for the token output (e.g. write raw to stdout via `process.stdout.write(token + '\n')`) and consider printing a short instruction line above it explaining how to copy it safely.

extent analysis

TL;DR

The issue can be fixed by modifying the claude setup-token command to print the OAuth token on a single line without wrapping.

Guidance

  • The problem is caused by the token being printed across two lines, resulting in a line break being included when copying the token.
  • To verify the issue, run the repro steps and observe the token being printed across two lines.
  • A potential workaround is to manually remove the line break when copying the token, or to use a text editor to remove the line break before pasting the token into a secret store.
  • The suggested fix of writing the token raw to stdout via process.stdout.write(token + '\n') could resolve the issue.

Example

// Example of writing the token raw to stdout
process.stdout.write(token + '\n');

Notes

The issue is specific to the claude setup-token command and the way it prints the OAuth token. The suggested fix should be applied to this specific command to resolve the issue.

Recommendation

Apply the workaround of manually removing the line break when copying the token, or modify the claude setup-token command to print the token on a single line without wrapping, as this will ensure that the token is copied correctly and can be used without issues.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING