claude-code - 💡(How to fix) Fix Orphaned background shells from prior sessions persist and re-trigger commands in new sessions [3 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#50865Fetched 2026-04-20 12:10:54
View on GitHub
Comments
3
Participants
3
Timeline
8
Reactions
0
Author
Timeline (top)
labeled ×5commented ×3

Fix Action

Workaround

pgrep -fl snapshot-zsh at session start and kill any stale wrappers.

Code Example

4493  3197  zsh -c ... eval 'ASPNETCORE_ENVIRONMENT=Development ... dotnet run
              --project .../EntArch.WebApi.csproj --urls=http://localhost:3100 ...'
4555  3197  zsh -c ... eval 'cd src/Web && pnpm --filter @entarch/platform-admin dev ...'
4582  3197  zsh -c ... eval 'cd src/Web && pnpm --filter @entarch/tenant-admin dev ...'
RAW_BUFFERClick to expand / collapse

Environment

  • Claude Code: 2.1.114 (CLI) / desktop app running session via binary 2.1.111
  • macOS: 26.5 (build 25F5053d)
  • Hardware: Apple Silicon

What happened

While working in a LinkMan project session, xcodebuild -scheme LinkMan test kept launching on its own and respawning LinkMan.app — without me asking.

Investigation showed the culprit is the Claude Code desktop app process itself (PID 3197, running .../claude-code/2.1.111/claude.app/.../claude). It still had child /bin/zsh -c wrappers alive from an EntArch project session that started ~1 hour before the LinkMan session began:

4493  3197  zsh -c ... eval 'ASPNETCORE_ENVIRONMENT=Development ... dotnet run
              --project .../EntArch.WebApi.csproj --urls=http://localhost:3100 ...'
4555  3197  zsh -c ... eval 'cd src/Web && pnpm --filter @entarch/platform-admin dev ...'
4582  3197  zsh -c ... eval 'cd src/Web && pnpm --filter @entarch/tenant-admin dev ...'

Each wrapper sources ~/.claude/shell-snapshots/snapshot-zsh-*.sh — the signature of a Claude-launched background command. They survived the end of the EntArch session and kept running inside a completely unrelated LinkMan session. Separately, a background xcodebuild ... scheme LinkMan test chain (PIDs 29380→29382) kept respawning LinkMan.app after kill until I killed the parent zsh wrapper, not just the child.

Expected

Background shells spawned by a session should be reaped when that session ends — or at minimum not remain attached to the desktop app across sessions and unrelated project contexts.

Actual

They persist under the desktop app's PID, continue running dev servers / test loops, and produce unexplained CPU usage and process churn in the next session the user opens.

Repro (approximate)

  1. Start a Claude Code session in project A; let it spawn background dev servers via run_in_background: true.
  2. End that session without explicitly killing the background shells.
  3. Open a new Claude Code session in project B.
  4. ps -eo pid,ppid,command | grep snapshot-zsh — project A's shells are still alive, parented to the desktop app.

Workaround

pgrep -fl snapshot-zsh at session start and kill any stale wrappers.

extent analysis

TL;DR

Kill stale background shell wrappers at session start using pgrep -fl snapshot-zsh to prevent them from persisting across sessions.

Guidance

  • Investigate the Claude Code desktop app's process management to understand why background shells are not being reaped when a session ends.
  • Verify that the pgrep -fl snapshot-zsh workaround effectively kills stale wrappers and prevents them from causing issues in subsequent sessions.
  • Consider implementing a mechanism to automatically reap background shells when a session ends, to prevent this issue from occurring in the future.
  • Review the run_in_background: true configuration to ensure it is not contributing to the persistence of background shells across sessions.

Example

# Example of how to kill stale wrappers at session start
pgrep -fl snapshot-zsh | xargs kill

Notes

The provided workaround may not be a permanent solution and may need to be repeated at the start of each session. A more robust solution would involve modifying the Claude Code desktop app to properly manage background shells.

Recommendation

Apply the workaround of killing stale background shell wrappers at session start using pgrep -fl snapshot-zsh, as it provides a temporary solution to the issue. A more permanent solution would require modifications to the Claude Code desktop app.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING