Skip to content

Background agents completing in parallel trigger 'Not logged in' and corrupt session credentials #37203

@mk-imagine

Description

@mk-imagine

Description

When background agents (launched via the Agent tool with run_in_background: true) complete, the CLI intermittently displays "Not logged in · Please run /login" and the session's auth credentials are permanently lost. The CLI must be fully restarted to recover — /login alone does not fix it.

Reproduction conditions

The error is intermittent and occurs under all of the following conditions:

  • Multiple background agents completing simultaneously (2-5 agents finishing within seconds of each other)
  • A single background agent completing (only one agent running)
  • Multiple Claude Code CLI sessions open simultaneously — however, closing other sessions does NOT fix an already-affected session
  • A single Claude Code CLI session with no other sessions running
  • Fresh CLI session — sometimes stable for the first few agent completions, then begins failing
  • Long-lived CLI session — seems more likely to occur after many agent completion cycles, but also occurs on the first completion in a fresh session

There is no reliable way to prevent it. It appears to be a timing-dependent issue related to auth token state during background agent completion processing.

Reproduction steps

  1. Start a Claude Code CLI session
  2. Launch a background agent: any Agent tool call with run_in_background: true (e.g., a software-implementer agent with isolation: "worktree")
  3. Wait for the agent to complete (typically 2-5 minutes)
  4. Observe "Not logged in · Please run /login" error on the agent completion notification (intermittent — may take several cycles)
  5. Once the error occurs, subsequent tool calls or messages fail with auth errors
  6. CLI must be fully restarted to recover

Impact

  • The background agents themselves complete successfully — their work (commits, file changes) is preserved
  • Only the parent CLI session's auth state is corrupted
  • Requires a full CLI restart after every occurrence, breaking iterative workflows
  • In a session dispatching ~12 background agents, the error occurred on roughly half of the completions

Environment

  • macOS (Darwin 25.3.0)
  • Claude Code CLI (current release as of 2025-03-21)
  • Model: claude-opus-4-6

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions