claude-code - 💡(How to fix) Fix Orphaned Claude session survives 11h after worktree deletion, ignores SIGTERM [1 comments, 2 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#46493Fetched 2026-04-11 06:18:50
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Timeline (top)
labeled ×4commented ×1

Code Example

$ ps -eo pid,etime,command | grep claude
57363    11:12:23 claude

$ lsof -p 57363 | grep cwd
2.1.100 57363 user  cwd  DIR  1,14  64  7676011 /Volumes/.../worktrees/daze-protocol/replica-regions
RAW_BUFFERClick to expand / collapse

Bug Description

A Claude Code session started inside a git worktree continued running for 11+ hours after the worktree directory was deleted. The process remained alive with no valid working directory and did not exit on its own. It also ignored SIGTERM and required SIGKILL to terminate.

Environment

  • Claude Code version: 2.1.100
  • OS: macOS Darwin 25.3.0 (Apple Silicon)
  • Shell: zsh

Steps to Reproduce

  1. Start a Claude Code session inside a git worktree (e.g. /path/to/worktrees/repo/branch-name)
  2. From another terminal or session, delete/remove the worktree (git worktree remove or similar)
  3. The Claude process continues running indefinitely

Observed Behavior

  • lsof -p <pid> shows cwd pointing to the now-deleted worktree directory
  • kill <pid> (SIGTERM) has no effect — process remains alive
  • kill -9 <pid> (SIGKILL) is required to terminate it
  • Process ran for over 11 hours in this state

Expected Behavior

Claude Code should detect that its working directory no longer exists and exit gracefully, or at minimum respond to SIGTERM.

Diagnostic Output

$ ps -eo pid,etime,command | grep claude
57363    11:12:23 claude

$ lsof -p 57363 | grep cwd
2.1.100 57363 user  cwd  DIR  1,14  64  7676011 /Volumes/.../worktrees/daze-protocol/replica-regions

The directory /Volumes/.../worktrees/daze-protocol/replica-regions no longer existed at the time of discovery.

extent analysis

TL;DR

The Claude Code process may need a modification to handle the case when its working directory is deleted, such as periodically checking for the directory's existence and exiting if it no longer exists.

Guidance

  • Investigate the Claude Code source code to determine if there is a mechanism for periodically checking the existence of the working directory and handle the case when it is deleted.
  • Consider adding a signal handler for SIGTERM that checks if the working directory still exists before attempting to exit, to ensure the process can be terminated cleanly.
  • Review the system's process management configuration to understand why the process ignored SIGTERM and required SIGKILL to terminate.
  • Check if there are any open issues or pull requests in the Claude Code repository related to this problem, as it may have already been addressed or be in the process of being fixed.

Example

No specific code example can be provided without access to the Claude Code source code, but a general approach might involve adding a periodic check for the working directory's existence, such as:

import os
import time

while True:
    if not os.path.exists('/path/to/working/directory'):
        # Handle the case when the directory no longer exists
        break
    # Continue with normal operation
    time.sleep(60)  # Check every minute

Notes

The exact solution will depend on the specifics of the Claude Code implementation and its requirements. This issue may be related to how the process handles file system events or signal handling.

Recommendation

Apply a workaround, such as implementing a periodic check for the working directory's existence, as the root cause of the issue is likely related to the process's handling of its working directory and signal handling, which may require modifications to the Claude Code source code.

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