Skip to content
UseAgent

Engineering · Claude Code · Debugging

Claude Code login expired with many sessions open: the fix

Claude Code login expired or 'OAuth access token has been revoked' across many sessions? Processes share one token and revoke each other. The cause and the fix.

Abhishek6 min read
On this page

If you run a lot of Claude Code sessions on one machine and they all fail in the same minute with one of these, your account is probably fine:

text
Login expired · Please run /login
text
Please run /login · API Error: 401 OAuth access token has been revoked.

On our Mac the cause was about 30 Claude Code processes sharing one login and revoking each other's token. The fix comes first, then how we found it.

Claude Code login expired: the fix

  1. See how many processes hold your login. On macOS or Linux:

    bash
    ps -axo pid,etime,command | grep -i '[c]laude'

    Look at the etime column. Anything measured in days is a suspect: forgotten terminal sessions, subagent processes from an old fan-out that never exited, the Chrome extension's helper (claude --chrome-native-host), the desktop app.

  2. Quit what you aren't using. Close old terminals properly; kill orphaned subagents.

  3. Use one account per machine and stop switching while sessions are running.

  4. Run /login once, in one session.

  5. If some sessions really need to live for hours, take them off the shared login. Give each its own CLAUDE_CONFIG_DIR with its own login, or run headless work on an API key, which has no OAuth refresh at all.

On a Mac you can see the stored logins with:

bash
security dump-keychain | grep 'Claude Code-credentials'

That prints item names, not secrets. Ours had two: Claude Code-credentials, which every default-config process shares, and an older one with a hash suffix.

Eighteen sessions failed in the same minute

We build UseAgent with a fleet of Claude Code sessions running in parallel on one Mac, each working its own branch, which we call lanes. On the night of September 13, eighteen lanes died together. Then again. The failures landed at 03:16, 03:36, 03:56, 04:17, 04:56 and 05:57 IST, and each one hit every lane at once. The first message was "OAuth access token has been revoked", then every session showed "Login expired".

In this repo's session logs, those two errors appear 123 times that night. Nothing the lanes had done was lost: their branches were pushed or on disk, and each one picked up again once its session had a valid login. What we lost was time: every event stopped all eighteen until someone logged in again.

When we counted, the login had about 30 holders: the 18 lanes, three interactive sessions still alive from two days earlier in other terminals, the session doing the counting, the Chrome extension's native host, and the Claude desktop app. All of them on the default config dir. All reading the same keychain item.

Find it in your own session logs

Claude Code writes every session to a .jsonl file under ~/.claude/projects/, and the failure is recorded there as an API error, so you can check whether your sessions hit it and when. The revoked case looks like this in the file:

text
"text":"Please run /login · API Error: 401 OAuth access token has been revoked."
"error":"authentication_failed","isApiErrorMessage":true,"apiErrorStatus":401

List the sessions that hit it:

bash
grep -l 'OAuth access token has been revoked' ~/.claude/projects/*/*.jsonl

If several sessions fail within the same minute or two, you are looking at a shared login, not a bad account.

One keychain item, thirty holders

Claude Code on macOS keeps its OAuth login in one keychain item. The access token inside it is issued for an hour; you can see the expiresAt one hour after each login. Normally the CLI refreshes it quietly before it runs out.

With one process that works. With thirty, any process can refresh, and when one does the server issues a new token and revokes the old one. Every other process is still holding the old one. Their next API call gets the 401, "OAuth access token has been revoked", and the session drops to "Login expired". So one refresh looks like a mass outage.

Account switching makes it worse. /login doesn't add a login, it overwrites the one item. Earlier that day we had sessions on four different accounts on the same Mac, and every /login rescued the session it was typed in and killed every session that had been running on the previous token. A switch also mints a fresh one-hour token, so the clock restarts for everybody.

The clock didn't explain all of it

My first explanation was the hour boundary: the token expires, every lane tries to refresh at once, one wins, the rest are revoked. Some of the failures fit that. Others came 20 to 60 minutes apart, which is too early for a one-hour token. Something was refreshing on its own schedule.

The obvious suspects were the long-lived holders. The Chrome native host had been running for days, so we stopped it first. The next revocation came anyway, 25 minutes after a fresh login. That left the interactive sessions that were three days old, which would have refreshed dozens of times by then, and the desktop app.

Then we hit a wall. Claude Code's debug logs had no auth lines, and macOS doesn't log keychain reads, so there was no way to see which process refreshed when. We never named the exact culprit.

What we did was reduce the number of holders: close the stale sessions, stop each lane the moment its work lands, no account switches during a night run. In this repo's session logs, the last "Login expired" is from that night, a month ago. I can't prove which of those changes mattered most. I'd guess the days-old sessions, but it's a guess.

Many processes are easy to accumulate

This wasn't the first time we found a crowd. A month earlier a process listing showed 39 Claude Code processes using about 9.3 GB of RAM. About 30 were subagent workers from a parallel fan-out a day and a half old, idle, around 300 MB each, never reaped. Killing that one parent tree took memory from 9.3 GB to 0.8 GB.

Nobody starts 30 sessions on purpose. Subagents, a browser extension's helper, a desktop app and a few terminals you forgot to close add up. Each one is a holder of the same login.

Codex has the same shape

Codex CLI did the same thing that week, for a slightly different reason. Long-running interactive codex resume sessions in other terminals, some started days earlier under an older login, keep their credentials in memory and write them back into ~/.codex/auth.json. A fresh sign-in got clobbered within the hour, and the CLI started failing with a revoked refresh token.

The fix that held was a separate home for the sessions that must not break. Our review runs use their own CODEX_HOME with a file credential store and a copy of a fresh login, and no interactive session ever points at it:

toml
# $CODEX_HOME/config.toml for the isolated review home
cli_auth_credentials_store = "file"
bash
CODEX_HOME="$HOME/.codex-review" codex exec "Reply with exactly: OK"

The Claude equivalent is a separate CLAUDE_CONFIG_DIR per long-lived lane, at the cost of one login per lane. We haven't moved our Claude lanes to it.

Treat "revoked" as a race, not a fault

What I'd tell anyone running Claude Code at this scale on one machine:

  • Keep the number of live processes small and know what each one is.
  • Stop sessions when their work is done instead of leaving them parked.
  • Don't switch accounts with sessions running.
  • If a session must outlive the hour, expect a re-login per hour per account unless it has its own login or an API key.
  • When "revoked" shows up, look for other holders before you look at your account.

We hit this because running many agents at once is the whole point of what we build. In UseAgent each run gets its own sandbox and a short-lived credential minted for that run, so nothing in the sandbox holds an OAuth login that another process can refresh out from under it (how we run Claude Code in the cloud). If you'd rather your parallel agents ran there than on your laptop, start a thread.

Frequently asked questions

Why does Claude Code keep saying Login expired?

If several Claude Code processes share one login, any of them can refresh the token, and the server then revokes the copy the others hold. They fail with 'OAuth access token has been revoked' and then 'Login expired'. Quitting the processes you don't need usually stops it.

Does running /login fix it?

Only for the session you run it in. Every /login replaces the single stored login, so the other running sessions are now holding a revoked token. Close the extra sessions first, then log in once.

Is my Claude account being blocked?

Not in our case. The errors lined up with token refreshes and account switches on one machine, not with anything on the account. Many processes on one login is enough to cause it.

All posts →

Hand your next task
to a coding agent.

UseAgent runs Claude Code, Codex and OpenCode in cloud sandboxes. The core is open source, so you can read the code or host it yourself.