How to Log Out of Claude Code | Commands and Account Switching

Article Summary by AI Chatpowered by Claude

When using Claude Code, you may encounter situations where you want to "switch to a different account" or "log out and log back in." This article explains how to log out of Claude Code from both CLI commands and interactive mode perspectives, and provides detailed guidance on re-authentication and account switching.

結論powered by Claude
When using Claude Code, you may encounter situations where you want to "switch to a different account" or "log out and log back in." This article explains how to log out of Claude Code from both CLI commands and interactive mode perspectives, and provides detailed guidance on re-authentication and account switching.
目次 (15)

There are two ways to log out of Claude Code

Claude Code offers two routes for logging out.

  1. Log out via CLI command — Run claude auth logout from the terminal
  2. Log out in interactive mode — Type /logout at the Claude Code prompt

Both have the same effect, but it's convenient to use them depending on the context of your workflow.

Method 1: CLI command claude auth logout

The simplest way is to run the following command in your terminal.

claude auth logout

This command logs out from your Anthropic account and removes saved authentication information. After running it, the next time you start claude, a browser window will open asking you to log back in.

Checking login status

If you want to check authentication status before or after logging out, use the following command.

claude auth status
  • If logged in: exits with code 0
  • If not logged in: exits with code 1

To display in a human-readable format, add the --text option.

claude auth status --text

Method 2: /logout command in interactive mode

To log out while Claude Code is running and the prompt is displayed (during an interactive session), type the following at the prompt.

/logout

The official documentation (code.claude.com/docs/authentication) also explicitly states, "To log out and re-authenticate, type /logout at the Claude Code prompt."

How to log back in after logging out

To use Claude Code again after logging out, log in with the following command.

claude auth login

Alternatively, simply launching claude will prompt you to log in. Like the initial startup, a browser window will automatically open, asking you to authenticate with your Claude.ai account.

Login options

The claude auth login command has several options.

Option Effect
--email <email address> Pre-fill email address to speed up authentication
--sso Force SSO authentication
--console Authenticate using Anthropic Console API usage charges instead of Claude subscription

For example, to authenticate with a specified email address:

claude auth login --email your@example.com

How to switch accounts

To switch to a different Claude account (for example, from a personal account to a company account), follow these steps:

  1. Log out from your current account

    claude auth logout
    
  2. Log in with a different account

    claude auth login
    
  3. Complete browser authentication with the other account's email address

The switch is now complete. After switching, verify that you're logged in with the correct account by running claude auth status --text.

Where is authentication information stored?

Claude Code manages login status securely, and the storage location differs by operating system.

OS Storage Location
macOS Encrypted macOS Keychain
Linux ~/.claude/.credentials.json (file mode 0600)
Windows %USERPROFILE%\.claude\.credentials.json

If you set the CLAUDE_CODE_DIR environment variable on Linux or Windows, the .credentials.json file will be created in that directory.

When you log out, the saved data is removed from this authentication information file. Note that Claude Code manages this file through /login and /logout, so manually deleting the file is not recommended.

When multiple authentication methods are mixed

If both the ANTHROPIC_API_KEY environment variable and Claude subscription are configured, the API key takes priority. In this case, running claude auth logout will not affect API key authentication.

If you want to fall back to Claude subscription, remove the ANTHROPIC_API_KEY environment variable.

unset ANTHROPIC_API_KEY

You can then check the current authentication method with /status.

Authentication without logout in CI/script environments

In environments where browser login is not available, such as CI pipelines, you can issue an OAuth token valid for one year using claude setup-token.

claude setup-token

By setting the generated token to an environment variable, it can be used without login or logout.

export CLAUDE_CODE_OAUTH_TOKEN=your-generated-token

This method is well-suited for CI servers and automated scripts because browser authentication is not required.

Common troubleshooting

Still prompted to log in even after logging out

If environment variables like ANTHROPIC_API_KEY are set, they take priority. Check for environment variables with env | grep ANTHROPIC and delete any unnecessary ones.

Browser doesn't open automatically

If the browser doesn't open during login, press c in the terminal and the login URL will be copied to your clipboard. Paste the URL in your browser to complete authentication. This often occurs in WSL2, SSH sessions, or container environments.

Cannot log out or getting errors

First, check your login status with claude auth status. If the issue persists, see the official authentication troubleshooting page.

Summary

There are two main ways to log out of Claude Code.

  • From terminal: claude auth logout
  • During a session: Type /logout at the prompt

To switch accounts, log out and then re-authenticate with a different account using claude auth login. Authentication information is stored in a secure location on your OS, and CI environments can also use long-term tokens via setup-token.

References: Claude Code Authentication Documentation / CLI Reference

参考になったら ♡
Clauder Navi 編集部
@clauder_navi

Anthropic の Claude / Claude Code を中心に、日本のエンジニア向けに最新動向と実務 を毎日発信。 運営方針 は メディアについて をご覧ください。