Claude Code · Sign-in
OAuth error: Invalid code. Please make sure the full code was copied
Claude Code’s “OAuth error: Invalid code” means the login code expired or was cut off when pasted. How to sign in on SSH, WSL and narrow terminals.
Message
The exact error
OAuth error: Invalid code. Please make sure the full code was copiedMeaning
What does “OAuth error: Invalid code” mean?
When you sign in, Claude Code opens a browser page and waits for the result. If the browser can’t hand the result back automatically, the page shows a code to paste at the Paste code here if prompted prompt. Anthropic’s troubleshooting guide says this error means that code expired or was truncated during copy and paste. The codes are short-lived, so a slow paste or a code with a missing piece is refused. Nothing is wrong with your account.
Causes
Why is my login code invalid?
- Too long between opening the login page and pasting the code, so it expired
- Part of the code lost when copying: a line wrap in a narrow or SSH terminal, or a selection that missed characters
- The browser opened on a different machine from the one running Claude Code, for example in an SSH session or WSL
Fix
How do I fix “OAuth error: Invalid code”?
Retry and paste quickly
Press Enter to retry, then finish the login straight after the browser opens. Copy the whole code, and check nothing was cut off before you press Enter.
Copy the full login URL with c
If the browser doesn’t open, or the URL wraps across lines and can’t be clicked, press
cin Claude Code to copy the whole OAuth URL to your clipboard and paste it into a browser yourself.On SSH or WSL, open the URL on your own machine
In a remote session the browser may open on the wrong machine. Copy the URL shown in the terminal, open it in the browser on the computer in front of you, sign in, and paste the code back into the remote terminal.
Reset the login if it keeps failing
- Run
/logoutto sign out completely. - Close Claude Code.
- Start it again with
claudeand complete the sign-in.
- Run
For servers and CI, use a token instead
On a machine where browser sign-in is awkward, run
claude setup-tokenon a computer where it works and set the long-lived token it prints asCLAUDE_CODE_OAUTH_TOKEN, or use an API key from the Claude Console. Keep either out of your shell history and repositories.
Explained
Which other login errors look like this one?
“Failed to start OAuth callback server” means Claude Code couldn’t open its local listening port on 127.0.0.1, so no login URL or code appears at all. “Claude Code access has not been granted for this account” on the sign-in page is an Enterprise role setting that only an organisation Owner can change. If you signed in fine but every request then fails, see Not logged in or 403 Request not allowed.
FAQ
Questions people ask
How long is the Claude Code login code valid?
Anthropic doesn’t publish an exact time, but its troubleshooting guide says the code expires, which is why it recommends completing the login quickly after the browser opens. If you see the invalid code error, press Enter to start a fresh attempt rather than pasting the old code again.
Why does the login code fail in WSL or over SSH?
The browser often opens on a different machine, or the long URL wraps in the terminal and gets cut. Press c to copy the full URL, open it in the browser on your own computer, sign in, then paste the code back into the terminal running Claude Code.
Do I need to delete my credentials to fix the invalid code error?
No. The error is about one login attempt, not your saved credentials. Retry the login, or run /logout and sign in again. Deleting credential files or keychain entries by hand isn’t needed.
Can I log in to Claude Code without a browser?
Not with the normal subscription login, which always uses a browser page, but it doesn’t have to be on the same machine. For headless servers, generate a long-lived token with claude setup-token on another computer and set it as CLAUDE_CODE_OAUTH_TOKEN, or use an API key.
Related
Related errors
Keep exploring