Last updated 13 October 2026
Use the login and logout commands in Claude Code
Authentication starts with a browser redirect
Claude Code requires a valid Anthropic account to function as your command line coding agent. You initiate the connection by typing /login inside an active session or by running the claude command for the first time in a project directory. The tool generates a unique temporary code and attempts to open your default web browser automatically. If your terminal environment prevents the browser from opening, the tool displays a URL that you can copy and paste into any browser window manually.
Once the browser page loads, you sign in with your Anthropic credentials. After you authorize the CLI, the browser sends a confirmation back to your terminal and the tool saves a secure session token on your local machine. This allows you to run future commands without repeating the login process every time you open a new window. The authentication link is time-sensitive, so you should complete the browser steps quickly to avoid an expiration error.
This process ensures that your primary account credentials never pass through the terminal as plain text. Instead, the tool uses a secure token to communicate with the Anthropic API. This follows modern security standards for command line applications and protects your account from being compromised by simple shell history logging.
The login command handles first time setup and account refreshes
Running the command claude in any project folder without a valid session usually triggers the login prompt. If you are already logged in but want to ensure your session is fresh, you can use the /login slash command inside the interactive interface. This is helpful if you suspect your local token has expired or if you encounter errors when the agent tries to call tools like Bash or Read. Re-authenticating can often resolve persistent connection issues without requiring a full re-installation.
When you run /login, the agent pauses its current task and waits for you to complete the browser handshake. It will not execute any code or read any files until the authentication completes successfully. This command is a primary troubleshooting step if the agent reports that it cannot reach the server or if your subscription status has changed recently. It verifies that your local installation has the correct permissions to communicate with your account.
You do not need to provide an API key manually during this process. The slash command handles the handshake between your local environment and the web service. This design reduces the risk of accidentally committing secret keys to your git repository or leaving them in your environment variables. It keeps your development environment clean and maintains a clear separation between your code and your authentication data.
Logout removes local access tokens and clears the session
If you need to step away from a shared computer or stop using a specific account, the /logout command is the correct tool. Typing /logout inside a session immediately invalidates the local authentication token. This action ensures that no one else can run the claude command and use your account balance or access your projects from that machine. It is a vital command for developers who work in open offices or use laboratory hardware.
Logging out does not delete your project files, your .mcp.json configurations, or the CLAUDE.md instructions you have created. It only removes the link between your local terminal and the Anthropic servers. If you want to use the agent again later, you must go through the browser-based login flow again. This is a clean way to end your workday or prepare a machine for use by a different developer on a different team.
After you run the logout command, the terminal may return you to your standard shell prompt. Any active sessions that were waiting for input will no longer be able to process commands or reach the model. This command is the definitive way to ensure your session is closed and your account is no longer active on the current hardware.
Switching between different Anthropic accounts
Claude Code does not currently support a single command to toggle between multiple accounts instantly. To switch from a personal account to a work account, you must first use the /logout command to clear the existing session. Once the terminal confirms you are logged out, you run the /login command to start the authentication process again. This manual cycle prevents identity confusion and ensures you are always aware of which account is being billed for the current session.
During the browser phase of the new login, make sure you are signed into the correct Anthropic account in that specific browser window. If your browser automatically logs you into your previous account, you may need to log out of the Anthropic website first or use an incognito window. The CLI receives the token for whichever account is currently active in the browser that opens the authentication URL.
This manual process prevents accidental billing to the wrong organization or project. It forces a conscious choice every time you change your identity in the terminal. While it takes a few extra steps, it keeps your work and personal projects strictly separated at the authentication level and avoids cross-contamination of project contexts.
Verify your status with the doctor command
If you are unsure whether you are logged in or which account is active, use the claude doctor command from your shell. This command performs a series of checks on your installation and environment. It reports whether a valid authentication token exists and whether the tool can reach the necessary servers. It is the fastest way to check your connection status without launching a full project session.
The doctor command is the best way to diagnose connection issues. It checks the health of your setup and can identify if your local network or firewall is blocking the authentication traffic. If the doctor command reports a failure in the login section, you know you need to run /login again to fix the state of your machine. It provides a technical summary that is more detailed than a simple success or failure message.
You can also use /status inside a session to see general information about your current environment. While /status provides details about the project and the agent's current task state, claude doctor is more focused on the underlying technical health of the tool. Together, these commands give you a clear picture of your authentication health and project readiness.
Local settings and credentials storage
The authentication tokens and configuration settings live in specific directories on your computer. Your global user settings are stored in ~/.claude/settings.json, while project-specific overrides are in .claude/settings.json. The login information itself is handled by the tool and is stored in a secure local path. You should not attempt to edit these binary token files by hand, as manual changes can corrupt your session and require a fresh login.
If you find that your login persists even after a logout, you might need to check these directories for unexpected configuration files. However, the /logout command is designed to be the definitive way to clear this data. You should trust the built-in commands before attempting to manually delete files in the .claude folders. Manually deleting files can sometimes leave the tool in an inconsistent state where it thinks it is logged in but cannot reach the server.
Understanding where these files live helps when you are moving between different machines. Since Claude Code respects .gitignore, your local settings and tokens will not be pushed to your remote repository. This protects your account even if you work in public or shared codebases. Your local environment remains private to your machine.
Managing multiple sessions simultaneously
Working on several projects at once can make account management and session tracking difficult. If you use adhdTerminal, you can see multiple Claude Code sessions arranged as tiles on a single wall. Each tile represents a separate session where you might be working on different repositories or using different permission modes like plan or acceptEdits. The app runs as a native tool on macOS and Windows to keep your work organized.
The adhdTerminal app makes it easier to monitor which sessions are active and which are idle without switching terminal tabs constantly. Since it displays the last exchanges of a conversation on each tile, you can quickly identify which project or account you are using for each specific task. This visual feedback is helpful when you are running several long-running tasks that require periodic attention.
If you need to log out of one specific project while keeping others running, you can do so within the individual tile of that session. The tile shows the current status of the agent, such as whether it is working or waiting for you. This allows you to manage complex workflows that span multiple repositories without losing track of your authentication state across the different projects.
Troubleshooting authentication errors and timeouts
Sometimes the login process fails because of a network timeout or a browser configuration issue. If the /login command does not trigger a browser window, check your default browser settings. You can also try running the command from a different terminal emulator to see if the issue is specific to your shell environment. Some terminal apps restrict the ability of child processes to launch external web browsers.
If you see errors related to permissions, remember that Claude Code operates in different modes. You can cycle through default, acceptEdits, plan, and bypassPermissions using Shift+Tab. While these modes do not change your login status, they do control what the agent can do once you are authenticated. A successful login is required before any of these modes can be used to modify your project or execute shell commands.
When all else fails, use the claude update command to ensure you are running the most recent version of the CLI. Sometimes authentication protocols change on the server side, and an outdated local tool might struggle to complete the handshake. Keeping the tool updated is the simplest way to avoid login friction and ensure that the /login and /logout commands work as intended with the Anthropic infrastructure.
Security best practices for terminal authentication
Treat your Claude Code session with the same care you give to your SSH keys or web browser sessions. Avoid running the /login command in environments where the screen is being shared or recorded, as the temporary verification codes might be visible to others. Once you are logged in, use the /permissions command or edit your settings.json to control which tools the agent can use in your environment.
If you use the iPhone app provided by adhdTerminal to mirror your wall, the link is end to end encrypted. This allows you to monitor your sessions or send a prompt from your phone without compromising your account security. It gives you the flexibility to manage your tasks even when you are away from your primary workstation, while keeping your authentication tokens secure on your computer.
Regularly using the /logout command at the end of a session is a good habit. It reduces the risk of unauthorized access if your local machine is ever compromised. If you ever lose access to your computer, you can also invalidate active sessions from your Anthropic account settings on the web. This layered approach to security keeps your development work safe and your account usage under your total control.
Questions people ask
How can I verify which account is currently logged in?
You can run the claude doctor command from your terminal to see the status of your installation and account connection. Inside an active session, you can also use the /status command to see details about the current environment. If you need to change accounts, you must logout and login again.
What should I do if the /login command does not open my browser?
If the browser does not open automatically, look at the terminal output for a manual URL and a verification code. Copy this URL into any web browser, sign in to your Anthropic account, and enter the code provided by the terminal. The session will then link to your CLI once you authorize it in the web interface.
Does logging out delete my CLAUDE.md file or project settings?
No, the /logout command only removes the authentication token from your local machine. Your project files, including CLAUDE.md, .mcp.json, and settings.json, remain untouched in your directory. You will simply need to log in again the next time you want to use the agent with those files.
Read next
- Add build instructions to your CLAUDE.md fileImprove project context by adding specific build commands and environment requirements to your CLAUDE.md file for the AI to follow.
- Add common error fixes to CLAUDE.mdImprove project memory by adding a section for common errors and their fixes to your CLAUDE.md configuration file.
- Add custom shell aliases for Claude CodeSpeed up your workflow by creating shell aliases for common Claude Code invocations and project-specific startup commands.
- Add test commands to a CLAUDE.md fileUnderstand how to define specific test runners and environment flags in your CLAUDE.md file so the tool runs the correct test suite.