-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
Summary
When running multiple Claude Code sessions concurrently (e.g., in separate tmux sessions), the second session's SessionStart hooks fail with errors because the worker port (37777) is already in use by the first session's worker.
Steps to Reproduce
- Start Claude Code in tmux session A (e.g.,
tmux new -s motor) - Start Claude Code in tmux session B (e.g.,
tmux new -s manager) - Session B shows
SessionStart:startup hook errortwice (worker start + context hooks)
Expected Behavior
The worker start hook should detect that a healthy worker is already running on port 37777 and exit silently with success, rather than attempting to start a new instance and reporting an error.
Actual Behavior
The hook attempts to start a new worker, fails with Worker failed to start Failed to start server. Is port 37777 in use?, and reports this as a SessionStart:startup hook error to the user. The subsequent health check (Worker already running and healthy) succeeds, confirming the existing worker is usable.
Relevant Log Entries
[2026-03-13 06:04:22.624] [ERROR] [SYSTEM] ✗ Worker failed to start Failed to start server. Is port 37777 in use?
[2026-03-13 06:04:22.633] [INFO ] [SYSTEM] Aggressive startup cleanup: killing orphaned processes {platform=Unix, count=8, ...}
After cleanup, the hook retries and finds the existing worker:
[2026-03-13 06:07:24.015] [INFO ] [SYSTEM] Worker already running and healthy
Impact
- Functional: None — the existing worker serves all sessions correctly
- UX: Confusing error messages on startup; users may investigate a non-issue
- Side effect: The "aggressive startup cleanup" kills orphaned processes that may belong to the first session's initialization
Suggested Fix
In the worker start hook (worker-service.cjs), check if a healthy worker is already responding on the configured port before attempting to start a new instance. If healthy, return {"continue":true,"suppressOutput":true,"status":"ready"} immediately.
Environment
- claude-mem: v10.5.2
- Claude Code: v2.1.73
- OS: Ubuntu 24.04.4 LTS
- Node: v22.x
- Bun: v1.3.10