Claude Code login not working? The cause is almost always one of four things: a login code that expired or was only partly copied, a terminal that will not paste into the code prompt, a browser that opened on a different machine, or an old credential overriding your login. The most common message is OAuth error: Invalid code. Please make sure the full code was copied, and Anthropic’s own documentation says it means the code expired or was truncated. If pasting does nothing at all, the documented fallback is claude auth login, which reads the code from standard input instead of the interactive prompt. This guide was checked against Claude Code v2.1.296, the latest release on 12 October 2026.

This page started life as a fix for one specific bug: in April 2026, Claude Code v2.1.105 broke pasting into the /login code prompt, and v2.1.108 fixed it the next day. We hit that bug ourselves, and our story is further down. Since then, Anthropic has shipped dozens of smaller login fixes, so the advice below starts with what fails today and keeps the April bug as history. If you are new to the Claude stack, our guide to Claude Mythos and Project Glasswing is a useful companion piece on what Anthropic is building next.

Fastest fix: run claude update, then run claude auth login, open the link it prints, and paste the whole code from the browser page back into the terminal, including the # and everything after it.

The Key Takeaways

  • “OAuth error: Invalid code” means the login code expired or was cut short while you copied it. Press Enter to retry and paste the new code quickly.
  • If pasting into the prompt does nothing, run claude auth login. Anthropic documents it as the fallback for any terminal where paste does not reach the prompt.
  • Over SSH, WSL2 or a container, the browser opens on a different machine. Press c to copy the login URL and open it in your local browser.
  • A leftover ANTHROPIC_API_KEY in your shell profile overrides your Pro or Max login once you have approved it.
  • The April 2026 paste bug lived in v2.1.105 to v2.1.107 and was fixed in v2.1.108. Do not downgrade to v2.1.104 today; update instead.

Claude Code Login Not Working? Find Your Error

From the publisher

Every AI model in one app

Fello AI puts GPT-6, Claude 5.5, Gemini 4 Argon, Grok 4.7 and more in one native Mac and iPhone app.

Download now!
From the publisher

Stop tab-hopping between AI apps

Ask ChatGPT, Claude and Gemini the same question in one window and keep the best answer. On Mac, iPhone and iPad.

Try it free

Match what you see on screen to the row below, then jump to the fix. Every cause and fix in this table comes from Anthropic’s official Claude Code troubleshooting documentation or the Claude Code changelog.

What you see Likely cause Fix
OAuth error: Invalid code. Please make sure the full code was copied The code expired, or part of it was lost when you copied it Press Enter, sign in again, paste the whole new code at once
Paste does nothing at the Paste code here if prompted prompt Your terminal’s paste shortcut is not reaching the input field Try right-click or Shift+Insert, or run claude auth login
Browser opens, but the terminal sits on “Waiting for authentication…” The browser cannot reach Claude Code’s local callback (SSH, WSL2, containers, strict firewalls) Copy the code the browser shows and paste it into the terminal
No browser opens at all No browser on that machine, or WSL2 cannot find your Windows browser Press c to copy the URL, or set BROWSER in WSL2
API Error: 400 ... This organization has been disabled An old ANTHROPIC_API_KEY is overriding your subscription Unset the key and remove it from your shell profile
Asked to log in again after every session on a Mac The macOS Keychain is locked or refusing writes Run claude doctor, unlock the Keychain, log out and back in

Fix 1: Update Claude Code to the Latest Version

Updating fixes more Claude Code login failures than any other single step, because Anthropic keeps shipping login fixes. Since the April paste bug, the Claude Code changelog has listed fixes for a sign-in URL that opened truncated in Windows Terminal (v2.1.191) and a URL that lost characters when copied in fullscreen (v2.1.234). Later releases fixed the c shortcut over SSH (v2.1.243) and /login reporting success on a Mac when the Keychain had refused the new login (v2.1.290).

If you used the native installer, run:

claude update

If you installed with npm, Anthropic says to upgrade like this and to avoid npm update -g, which may not move you to the newest release:

npm install -g @anthropic-ai/claude-code@latest

To reinstall from scratch, the native installers are curl -fsSL https://claude.ai/install.sh | bash on macOS and Linux, and this on Windows PowerShell:

irm https://claude.ai/install.ps1 | iex

After updating, restart your terminal, confirm the version with claude --version, run /logout if a session is stuck, then run claude to start a fresh login. Homebrew and WinGet installs do not update themselves, so run brew upgrade claude-code or winget upgrade Anthropic.ClaudeCode instead.

If a new release ever breaks login again, switch to the stable release channel. Anthropic describes it as a version about one week old that skips releases with major regressions, which is exactly the kind of bug the April paste failure was.

Fix 2: Paste the Code Into claude auth login

claude auth login is the official fallback when pasting into the interactive login prompt does nothing. It reads the pasted code from standard input, so it does not depend on how your terminal delivers a paste to Claude Code’s input field. Anthropic says it applies on WSL2, SSH, containers, native Windows and “any terminal where pasting into the interactive prompt fails”.

claude auth login

Open the URL it prints, sign in, copy the code the browser page shows, paste it into the terminal and press Enter. Before switching commands, try your terminal’s alternate paste shortcut first: in Windows Terminal that is often right-click or Shift+Insert. To check that the login took, run claude auth status --text.

Note that claude login on its own is not a Claude Code command. The commands are /login inside a session and claude auth login from your shell.

How to Fix “OAuth error: Invalid code”

“OAuth error: Invalid code. Please make sure the full code was copied” means the login code expired or was truncated during copy and paste. That is Anthropic’s own explanation. Work through these checks in order:

  1. Start over and be quick. Press Enter to retry, finish signing in as soon as the browser opens, and paste the new code right away. Codes are short-lived, so a code from an earlier attempt may already have expired.
  2. Copy the whole code, including the #. A user who traced the error on GitHub (issue #91157) found that the code has two parts joined by a #, and that Claude Code rejects any paste without the # and text on both sides. Double-clicking to select the code stops at the #, so drag across the whole line instead.
  3. Open the URL on the right machine. In an SSH session, the browser can open on the remote host. Copy the URL from the terminal and open it in your local browser.
  4. Do not type the code by hand. It is long, and a single wrong character or a slow typist produces the same error.

If the error keeps coming back on the latest version, use claude auth login from Fix 2 so the code arrives in one piece. As of October 2026, users are still reporting “Invalid code” on GitHub in specific setups such as GitHub Codespaces (issue #91176). Check the Claude Code GitHub issues tracker for your environment before you spend an hour on it.

Fix 3: Login Fails Over SSH, in WSL2 or in a Container

Over SSH, in WSL2 or inside a container, the browser usually opens on a different host, so its redirect cannot reach Claude Code’s local callback. After you sign in, the browser shows a login code instead of sending you back automatically. Paste that code into the terminal at the Paste code here if prompted prompt.

If no browser opens: press c at the login prompt to copy the full OAuth URL, then paste it into a browser yourself. This also works when the URL wraps across lines in a narrow terminal and cannot be clicked. Since v2.1.243, pressing c over SSH tells you how the URL was copied instead of always claiming success.

If WSL2 cannot find your browser: point the BROWSER variable at your Windows browser before starting Claude Code.

export BROWSER="/mnt/c/Program Files/Google/Chrome/Application/chrome.exe"
claude

If the terminal sits on “Waiting for authentication…”: the localhost callback is blocked, which Anthropic’s support center says is common over SSH, in devcontainers and behind strict firewalls. Copy the URL, finish signing in in any browser, and paste the returned code back into the terminal.

Fix 4: Skip OAuth With an API Key or a Long-Lived Token

An Anthropic Console API key lets Claude Code skip the browser login entirely. Create a key in the Claude Console, then export it before running Claude Code:

export ANTHROPIC_API_KEY=sk-ant-your-key-here
claude

On Windows PowerShell:

$env:ANTHROPIC_API_KEY = "sk-ant-your-key-here"
claude

Claude Code asks you once to approve the key, then uses it. API key usage is billed per token through your Console account, separate from any Pro or Max subscription. If you are weighing whether to stay on Claude at all, our roundup of the best Claude Cowork alternatives is a quick sanity check.

The Leftover API Key Trap

An approved ANTHROPIC_API_KEY outranks your Pro or Max login. If an old key from a previous job or project still sits in ~/.zshrc, ~/.bashrc or ~/.profile, Claude Code can fail with This organization has been disabled even though your subscription is active. Run unset ANTHROPIC_API_KEY (or Remove-Item Env:ANTHROPIC_API_KEY in PowerShell), delete the line from your profile, and run /status inside Claude Code to confirm which login is active.

For CI pipelines and servers with no browser, claude setup-token generates a one-year OAuth token tied to your Claude subscription. Set it as CLAUDE_CODE_OAUTH_TOKEN. Remove that variable from your profile when you are done with it, because Claude Code reads it again in every new session.

Fix 5: Reset Your Login Safely

A clean re-authentication fixes most login failures whose cause is unclear. Anthropic’s reset is three steps: run /logout, close Claude Code, then start it again with claude and log in. If claude will not start at all, run this from your shell for a diagnostic report:

claude doctor

Do not delete ~/.claude/ to “reset” a login. That folder holds your settings, memory and session history, and on a Mac your login normally is not stored there anyway: Claude Code saves it in the login Keychain.

When the Mac Keychain Is the Problem

If the Keychain is locked, which is common in an SSH session, or its password is out of sync with your account password, Claude Code falls back to a plain-text ~/.claude/.credentials.json file. claude doctor then shows a warning starting with macOS Keychain is not writable. Unlock the Keychain:

security unlock-keychain ~/Library/Keychains/login.keychain-db

If the warning stays, open Keychain Access, select the login keychain and choose Edit > Change Password for Keychain “login” to resync it. Then run /logout and /login to move your login back into the encrypted Keychain. Logging out also removes saved MCP server logins, so expect to re-authorize those.

The April 2026 Paste Bug

From 13 to 14 April 2026, Claude Code silently dropped any code pasted into the /login prompt while still accepting typed characters. v2.1.105 was published on npm at 19:51 UTC on 13 April. v2.1.108 followed at 18:35 UTC the next day, with the changelog line “Fixed paste not working in the /login code prompt (regression in 2.1.105)”. GitHub reports blamed the terminal’s bracketed paste sequences, which wrap every paste, for being swallowed by the prompt.

This was not a clipboard, VPN or account problem, and restarting the terminal did nothing. A separate clipboard quirk trips people feeding Claude Code a screenshot instead of a login code, which our guide on how to paste images into Claude Code handles on its own.

How We Hit This Bug (And What Actually Worked)

We ran into the bug the first time we installed Claude Code on a fresh machine. Ctrl+V in Windows Terminal did nothing. Shift+Insert and right-click paste did nothing. Cmd+V on the Mac behaved the same way. The prompt just sat there, blinking, as if the clipboard was empty.

We asked Claude itself what was going on, and it suggested the usual suspects: restart the terminal, check the clipboard, try a different shell. None of it helped. Typing the code by hand got it accepted, and Anthropic answered with a 401 error, because a long code typed character by character is easy to get wrong or let expire.

We checked status.anthropic.com to rule out an outage. Everything was green. On the Claude Code GitHub issues tracker we found several reports filed within hours of each other (#47669, #47745, #47799, #47887). All of them described the same failure starting in v2.1.105, and users on r/ClaudeAI were hitting the same wall.

What worked for us that day was downgrading to v2.1.104, the last version before the bug. Login went through on the first attempt. Anthropic shipped the real fix in v2.1.108 the next day.

Should You Still Downgrade?

No. v2.1.104 is six months old and misses every login fix listed in Fix 1, so a downgrade now trades one bug for several. If you need to pin a version, the native installer accepts a version number, such as curl -fsSL https://claude.ai/install.sh | bash -s 2.1.104. The stable release channel from Fix 1 is still the safer way to avoid a fresh regression.

If Claude Code keeps giving you trouble and you just need Claude for a question while the terminal is locked out, Fello AI puts Claude, GPT and Gemini in one chat window on your Mac. Your work does not wait on a login prompt. To benchmark your options before committing more time, the Muse Spark vs ChatGPT vs Claude vs Gemini comparison shows where each major model wins. The Grok vs ChatGPT breakdown is a solid reference if you are rethinking your default coding assistant entirely.

Conclusion

Claude Code login problems in 2026 come down to a short list. “OAuth error: Invalid code” means the code expired or was not copied whole, so retry and paste the entire code, # included. A paste that does nothing is solved by claude auth login. Remote and WSL2 sessions need the URL opened on your own machine, and a leftover API key or a locked Mac Keychain explains the rest. Update first, because most of these failures have a fix in a newer release. Once you are back in, our guide to AI system instructions will help you get noticeably better output from your first prompt.

FAQ

Why can’t I paste the authentication code in Claude Code?

Your terminal’s paste shortcut is not reaching Claude Code’s input field. Try right-click or Shift+Insert, or run claude auth login, which reads the pasted code from standard input. In April 2026, versions 2.1.105 to 2.1.107 had a bug that dropped every paste in that prompt; v2.1.108 fixed it, so update if you are on one of those.

What does “OAuth error: Invalid code” mean in Claude Code?

It means the login code expired or was truncated when you copied it. Press Enter to retry, sign in again quickly, and paste the whole new code, including the # in the middle and everything after it.

Do I still need to downgrade to v2.1.104?

No. The paste bug was fixed in v2.1.108 on 14 April 2026, and v2.1.104 misses six months of later login fixes. Update with claude update instead.

Why does Claude Code login fail in WSL2 or over SSH?

The browser opens on a different host, so it cannot redirect back to Claude Code. Copy the code the browser shows and paste it into the terminal, or press c to copy the URL and open it locally. In WSL2, set BROWSER to your Windows browser path.

Can I log in without pasting anything?

Yes. Set ANTHROPIC_API_KEY in your shell and Claude Code skips OAuth, billed per token through the Claude Console. For servers and CI, claude setup-token creates a one-year token you set as CLAUDE_CODE_OAUTH_TOKEN.

Why did I get a 401 error when I typed the code manually?

Login codes are long and short-lived. Typing one by hand usually means a wrong character or an expired code by the time it reaches Anthropic. Paste the code instead, or use claude auth login.