[BUG] tasks/.lock file never released on normal session exit

Resolved 💬 3 comments Opened Jan 31, 2026 by clthuang Closed Feb 4, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

The ~/.claude/tasks/<session-id>/.lock file is never released, even when a session ends normally. This causes the lock to accumulate over time and can block future sessions that restore from backup.

Evidence from Debug Log

Session f95a8114-818e-4532-8659-24ee005472fb:

11:40:13.147 - First TaskCreate → .lock file created
11:40:13 to 11:40:21 - Multiple TaskCreate operations (9 total)
11:47:03.794 - Session ended NORMALLY with SessionEnd hook

Result: Lock file still exists after normal session termination.

$ ls -la ~/.claude/tasks/f95a8114-818e-4532-8659-24ee005472fb/
-rw-r--r--  1 terry  staff  0  31 Jan 19:40  .lock      # Never released
-rw-r--r--  1 terry  staff  2  31 Jan 19:44  .highwatermark

Comparison with history.jsonl.lock

| Lock | Type | Released on normal exit? |
|------|------|-------------------------|
| history.jsonl.lock | Directory | ✅ Yes |
| tasks/<session>/.lock | File | ❌ No |

Impact

  1. Lock files accumulate with each session that uses tasks
  2. When restoring ~/.claude from backup, stale locks cause hangs
  3. Users may not realize the tasks lock exists (only history.jsonl.lock is documented)

What Should Happen?

The tasks/.lock file should be:

  1. Released when the session ends normally (SessionEnd hook)
  2. Released in a cleanup handler for SIGINT/SIGTERM
  3. Subject to stale lock detection (check if owning PID is alive)

Steps to Reproduce

  1. Start Claude Code
  2. Create tasks using TaskCreate tool
  3. Exit normally (Ctrl+D or /exit)
  4. Check: ls ~/.claude/tasks/*/.lock
  5. Result: Lock file still exists

Workaround

find ~/.claude/tasks -name ".lock" -delete

Related Issues

  • #22166 - Stale history.jsonl.lock causes freeze (different lock, similar symptoms)

Environment

  • OS: macOS (Darwin 25.2.0)
  • Claude Code Version: 2.1.27

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗