Tuesday, August 11, 2026

Claude Code Asks for /login After Restarting: Cause and Fix [2026 Edition]

After restarting Claude Code, multiple sessions repeatedly displayed Please run /login or 401 OAuth access token has been revoked and then stopped responding to instructions. Running /login restored one session, but the issue returned in each newly started Claude Code process, making long-running sessions unusable.

Colored-pencil illustration of an authentication token being corrupted and lost on its way from a shell to Claude Code

What you can do with this article

  • Troubleshoot Claude Code when it requests /login at startup
  • Know what to check next when fixing the configuration file does not resolve the issue
  • Safely check the value an open shell passes to a child process and the environment variables supplied when a process started

Environment

  • Authentication used OAuth, and multiple Claude Code processes referenced the same saved OAuth credentials
  • CLAUDE_CODE_OAUTH_TOKEN was exported with a fixed value in ~/.bashrc, which interactive, non-login Bash shells read
  • The shell that had loaded the environment variable remained open and was repeatedly used to start Claude Code

Condition that reproduced the issue

The condition that reproduced the 401 authentication error was starting a new Claude Code process from a shell that still held an old token.

Running /login in another terminal does not update the environment variable held by the affected shell. Processes that are already running also retain the environment variables they received at startup.

Investigating the cause

Identifying the cause took about a month. During that time, I checked the following four points in sequence.

What I checked Action Result and conclusion
Whether /login in another session affected existing sessions Compared behavior before and after running /login in another session No connection was observed
Whether concurrently running processes caused a refresh-token update conflict Started processes one at a time instead of concurrently The 401 authentication error continued, so concurrent startup was not the cause
Whether updates to shared saved OAuth credentials applied to a new process Ran /login in one Claude Code process, then started another Claude Code process The new process encountered a 401 authentication error, leaving open the possibility that it was using a different authentication path from the saved OAuth credentials
Whether a process with a 401 authentication error could be restored individually Ran /login in that process That process recovered, but the issue returned in a newly started Claude Code process from the same shell

Cause: an old token in an environment variable took priority over saved OAuth credentials

Checking the environment variables showed that the launching shell still held an old token.

~/.bashrc
Read when an interactive, non-login Bash shell starts

Loaded when the shell starts
Shell left open
Keeps the old value after the configuration file is fixed

Inherited by a child process
Claude Code
Attempts authentication with the old token

The interactive, non-login Bash shell used in this case reads ~/.bashrc when it starts. Removing the export later does not change the environment of a shell that is already open. Every Claude Code process started from that shell received the old token as a child process.

The cause was that the old CLAUDE_CODE_OAUTH_TOKEN took priority over the saved OAuth credentials created by /login. The official Claude Code documentation also explains that this environment variable takes priority over saved OAuth credentials. If the launching shell retains an old value, that value is used.

As a result, every newly started Claude Code process from the same shell inherited the old token and encountered a 401 authentication error.

Resolution: update the shell configuration file, current shell, and Claude Code

Fixing the shell configuration file alone does not remove the value retained by an already open shell or Claude Code process. Clear it at each of the following three levels in order.

Target Action What this action alone does not change
1. Shell configuration file In this environment, remove or comment out the export in ~/.bashrc It does not affect the current shell or running processes
2. Current shell Run unset CLAUDE_CODE_OAUTH_TOKEN. If you recreate the shell, start it from an environment that does not hold the old value It does not affect running processes
3. Running Claude Code process Restart the target process from a shell where the old value has been removed None

Commands used for verification

# 現在の shell に残っているか
$ env | cut -d= -f1 | grep -c '^CLAUDE_CODE_OAUTH_TOKEN$'
0

# 起動済みプロセスに起動時に渡された環境変数
$ tr '\0' '\n' < /proc/<pid>/environ | grep -c '^CLAUDE_CODE_OAUTH_TOKEN='
0

Both commands count matches only. Printing the matching line directly would display the token as variable-name=value.

/proc/<pid>/environ generally shows the initial environment passed to a process when it started. It does not reflect environment-variable changes made by the process after startup, so I use it here only to check whether Claude Code started after inheriting the old token.

Result

After removing the export from the shell configuration file and starting Claude Code from a shell without the old value, authentication succeeded without running /login in each process.

Additional steps when using tmux

The key point with tmux is that it maintains both global and session environments and merges them when creating a new window before passing the result to the process. If the same variable exists in both, the session-environment value is used.

The environment-variable inheritance path is:

tmuxのグローバル環境・セッション環境 → tmux内のshell → Claude Code

Removing an environment variable retained by tmux

In this case, the old token remained in the global environment. Because tmux also has a session environment, check both before removing it.

# tmuxサーバに残っているか(値は表示しない)
$ tmux show-environment -g | cut -d= -f1 | grep -c '^CLAUDE_CODE_OAUTH_TOKEN$'

# 対象セッションにも残っているか(値は表示しない)
$ tmux show-environment -t <session-name> | cut -d= -f1 | grep -c '^CLAUDE_CODE_OAUTH_TOKEN$'

# tmuxサーバから削除する
$ tmux setenv -gu CLAUDE_CODE_OAUTH_TOKEN

# 対象セッションから削除する
$ tmux setenv -u -t <session-name> CLAUDE_CODE_OAUTH_TOKEN

Removing the variable from the tmux environments does not remove the old token from shells and Claude Code processes already running in existing windows or panes. Handle them in this order:

  1. Remove the variable from the tmux global environment and the target session environment
  2. Run unset CLAUDE_CODE_OAUTH_TOKEN in the existing shell inside tmux, or recreate the window or pane
  3. Restart Claude Code from that shell

If you can end every session, tmux kill-server can terminate the tmux server, existing shells, and Claude Code processes together. In this environment, I restarted 14 sessions other than the one still in use, and all 14 authenticated without an individual /login. I restarted the remaining session later and confirmed that it had no old environment variable.

Monitoring a tmux session externally

In this environment, I monitored whether the Claude Code process existed from outside the tmux session. Because the process itself did not exit after the 401 authentication error, checking only for the process could not detect that it had stopped responding.

This article records measurements from a WSL2 environment as of August 2026. Shell and client behavior may vary by version and startup method. If you notice anything, please leave a comment.

Summary

  • The 401 authentication error occurred because the old CLAUDE_CODE_OAUTH_TOKEN retained by the shell took priority over the OAuth credentials saved by /login
  • Resolving it required removing the setting from ~/.bashrc, clearing the environment variable from the current shell, and then restarting Claude Code from that shell
  • When using tmux, also remove the variable from its global and session environments and handle the old token retained by existing shells

If this article helped, I’d be happy if you shared it on X (Twitter).

App by the author of this blog

I made an iOS reading management app called My Bookstore. Simple bookshelf management — give it a try.

View on App Store →

Related articles

References

No comments:

Post a Comment