cclogin and Auth Setup: Getting Claude Code Logged In
What Happens When You Run claude
Run claude for the first time and it opens a browser window to Anthropic's authentication flow. You log in with your Anthropic account — or create one if you do not have one yet. That browser session issues a token that the CLI caches locally. After that first login, the CLI uses the cached token and you should not need to re-authenticate unless the token expires or you explicitly log out.
Where Tokens Are Stored
The CLI stores credentials in ~/.config/claude/ on Linux and macOS, or %APPDATA%/claude/ on Windows. Specifically, it writes to credentials.json in that directory. You do not need to interact with this file directly, but knowing it exists helps when something goes wrong.
If you are on a shared machine and want to log out, delete that credentials file. Next time you run claude, it will open the browser login flow again.
API Key Approach for CI and Servers
For CI/CD environments, headless servers, or team deployments where browser-based login is not practical, use an API key instead. Set the ANTHROPIC_API_KEY environment variable to your key from the Anthropic console. The CLI checks for this variable before attempting browser-based login.
export ANTHROPIC_API_KEY=sk-ant-...
For team setups, put this in a .env file that your deployment system loads. Do not commit API keys to git — use your secret management tooling instead.
Switching Accounts
If you need to switch between Anthropic accounts — personal vs work, for example — the cleanest way is to log out first:
claude auth logout
claude # will trigger browser login for the new account
You can also set ANTHROPIC_API_KEY to a different key before running claude, and it will use that credential without requiring a browser session.
When Login Breaks
Occasionally the cached token gets corrupted or expires in a way the CLI does not handle gracefully. The symptom is a browser window that opens, you log in successfully, but the CLI never proceeds. When this happens, delete credentials.json and try again. That forces a fresh authentication cycle and usually fixes it.
If you are behind a corporate proxy that intercepts HTTPS, you may also need to set HTTP_PROXY and HTTPS_PROXY environment variables so the CLI can reach Anthropic's auth servers.
Get Started with Claude Code
Start building with Claude Code today. Free to download, powerful enough for production.