What it does
/login authenticates Claude Code with your Anthropic account via OAuth. It opens your browser to the Anthropic auth page, where you sign in and grant Claude Code permission to act on your behalf. On success, Claude Code stores a session token locally—the agent uses this token to call the Claude API and bill your account (for pay-as-you-go API keys) or your Claude Code Pro subscription.
The token is stored in ~/.claude/auth/session.json and is valid indefinitely until Anthropic revokes it. If you revoke Claude Code's OAuth grant from your Anthropic account settings, the token becomes invalid and you'll need to re-run /login.
When to use it
Run /login when:
- You're setting up Claude Code for the first time
- You see an auth error like "not authenticated" or "invalid token"
- You want to switch to a different Anthropic account (log out, then re-run
/login) - Your session token has been revoked (you removed Claude Code access from Anthropic settings)
- You're troubleshooting a "permission denied" error from the API
If you're using Claude Code Pro, /login authenticates with the same Anthropic account that owns your subscription—this is how the agent's usage is billed against your Pro quota instead of API credits.
Try it yourself
Open your terminal and run /login without arguments. Watch Claude Code launch your browser to the Anthropic OAuth page. Sign in with your Anthropic account, review the permissions Claude Code is requesting, and click approve. Your terminal should confirm the auth succeeded and return control back to you.
Gotchas
Token expiry and revocation. OAuth tokens don't have a fixed expiry—they're valid until you revoke them. However, Anthropic reserves the right to revoke tokens. If you see errors like "invalid OAuth token" days after a successful /login, your token may have been revoked. Fix: re-run /login.
Browser fallback. If /login can't open your default browser (e.g., in a headless SSH session), it will print an auth URL for you to paste into a browser on another machine. Do that, then return to the terminal—Claude Code polls for the OAuth callback.
Account switching. There is only one active session per Claude Code installation. If you need to switch accounts, run /login again with a different Anthropic user—it overwrites the stored token. There's no "logout" command; re-authenticating is how you change accounts.
Network and proxy. OAuth requires HTTPS to Anthropic's servers. If you're behind a corporate proxy, configure it in your terminal or Claude Code settings before running /login.
Claude Code Pro vs API billing. If you're using Claude Code Pro, /login links your session to the Pro subscription. If you later downgrade to a free tier, your agent usage will bill against pay-as-you-go API credits instead. Check your Anthropic account settings to confirm which plan is active.
Try it yourself
Type the command in the fake terminal. Nothing leaves your browser.