Fix: Claude Code OAuth Login Paste Not Working
The Error
You run claude on a fresh machine, choose Claude account with subscription, copy the OAuth authorization URL into a browser, complete the flow, and try to paste the auth code back into the terminal prompt:
Paste code here if prompted >
Nothing appears. Pressing Enter does nothing or submits an empty value. The login flow cannot complete.
Quick Fix
Skip the broken login widget entirely using CLAUDE_CODE_OAUTH_TOKEN:
# On a machine where login works (e.g., your Mac)
claude setup-token
# Copy the printed sk-ant-oat01-... token
# On the affected machine
export CLAUDE_CODE_OAUTH_TOKEN="sk-ant-oat01-..."
claude
Claude Code recognizes the environment variable, bypasses the login screen, and starts normally.
What’s Happening
The OAuth login screen uses a different TUI input widget than the main Claude Code chat prompt. This widget does not properly handle bracketed paste escape sequences that modern terminals send when you paste from clipboard.
When you paste text, your terminal wraps it in escape markers:
\x1b[200~<pasted text>\x1b[201~
The main chat prompt handles these correctly. The login input widget does not. Each character of the bracketed-paste payload is processed as an individual keystroke, and:
- The leading
\x1b[200~is interpreted as an escape-then-command-key sequence and discarded - The input reader has length or character validation that rejects the burst of characters
- Per-keystroke re-renders race with the input buffer and drop characters
This is confirmed by the fact that typing the auth code one character at a time works (but is impractical for 100+ character codes), and pasting into the main chat prompt in the exact same terminal session works fine.
Step-by-Step Solution
Option 1: Environment Variable (Recommended)
# Step 1: On a working machine, generate a long-lived token
claude setup-token
# Step 2: On the affected machine, set the env var persistently
echo 'export CLAUDE_CODE_OAUTH_TOKEN="sk-ant-oat01-YOUR-TOKEN-HERE"' >> ~/.bashrc
source ~/.bashrc
# Step 3: Verify
claude --version
Option 2: Copy Credentials File
# On a working machine, after successful login
cat ~/.claude/.credentials.json
# Copy the JSON content to the affected machine
mkdir -p ~/.claude
# Paste the credentials JSON into ~/.claude/.credentials.json
Option 3: Type the Code Manually
If you have no other machine available, you can type the auth code character by character. The code from the OAuth callback URL looks like:
https://platform.claude.com/oauth/callback?code=AUTH_CODE_HERE
Copy just the code parameter value. Type it into the prompt one character at a time. This works but is tedious for long codes.
Option 4: Use an API Key Instead
If you have API access via console.anthropic.com:
export ANTHROPIC_API_KEY="sk-ant-api03-..."
claude
This bypasses OAuth entirely and uses direct API authentication.
Prevention
- When setting up Claude Code on remote or headless servers, use
CLAUDE_CODE_OAUTH_TOKENfrom the start rather than relying on the interactive login flow - Add the token export to your shell profile (
~/.bashrc,~/.zshrc) so it persists across sessions - For CI/CD environments, store the token as a secret and inject it via environment variable
Related Issues
- Fix: Claude Code Headless Linux Auth Blocked by Cloudflare
- Fix: Claude Code Headless Linux Auth
- Fix: Claude API Error 401 Unauthorized
Tools That Help
If you are debugging authentication issues across multiple development environments, a browser extension dev tool can help inspect OAuth callback URLs and extract auth codes from redirect chains.