[BUG] Hangs indefinitely on third consecutive run - process completes but never exits (macOS)

Resolved 💬 5 comments Opened Jan 27, 2026 by Blake-Andrews Closed Jan 27, 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?

Claude Code hangs indefinitely on exactly the third consecutive run - whether using -p (print) mode or interactive mode. The debug logs show the API call completes successfully, the session ends, and LSP shuts down - but the process never exits and no output is displayed to the terminal.
The terminal title shows "Initial greeting — claude" when hanging in interactive mode, and lsof shows an ESTABLISHED TCP connection to Anthropic's API (160.79.104.10:443) that never closes.
This is reproducible, runs 1 and 2 always work, run 3 always hangs.

What Should Happen?

Claude Code should complete execution and exit normally on all consecutive runs, not just the first two.

Error Messages/Logs

No error messages displayed - the process simply hangs with no output.
Debug log from hanging third run shows successful completion:
2026-01-27T00:57:36.997Z [DEBUG] Stream started - received first chunk
2026-01-27T00:57:37.863Z [DEBUG] Getting matching hook commands for Stop with query: undefined
2026-01-27T00:57:37.863Z [DEBUG] Found 0 hook matchers in settings
2026-01-27T00:57:37.863Z [DEBUG] Matched 0 unique hooks for query "no match query" (0 before deduplication)
2026-01-27T00:57:37.863Z [DEBUG] Getting matching hook commands for SessionEnd with query: other
2026-01-27T00:57:37.863Z [DEBUG] Found 0 hook matchers in settings
2026-01-27T00:57:37.863Z [DEBUG] Matched 0 unique hooks for query "other" (0 before deduplication)
2026-01-27T00:57:37.866Z [DEBUG] LSP server manager shut down successfully
Despite "shut down successfully", the process remains running indefinitely.
lsof output during hang:
2.1.19  9180 Work   11u     IPv4 0x524c8e87ce8b9196       0t0     TCP 192.168.1.149:51723->160.79.104.10:https (ESTABLISHED)
netstat shows multiple TIME_WAIT connections accumulating:
tcp4       0      0  192.168.1.149.50507    160.79.104.10.443      TIME_WAIT  
tcp4       0      0  192.168.1.149.50509    160.79.104.10.443      TIME_WAIT  
tcp4       0      0  192.168.1.149.50511    160.79.104.10.443      TIME_WAIT  
(10+ connections after just 2 runs)

Steps to Reproduce

  1. Clean slate

rm -rf ~/.claude && rm -f ~/.claude.json && rm -f ~/.claude.json.backup

  1. First run - WORKS

claude -p "test 1"
Output: "Hello! It looks like you're testing..."

  1. Second run - WORKS

claude -p "test 2"
Output: "I see you've sent test 2..."

  1. Third run - HANGS INDEFINITELY

claude -p "test 3"
No output, process hangs, requires Ctrl+C to exit

Interactive Mode:

  1. rm -rf ~/.claude && rm -f ~/.claude.json
  1. claude # Works, type /exit
  1. claude # Works, type /exit
  1. claude # Hangs on "Initial greeting" (visible in terminal title bar)

Claude Model

Not sure / Multiple models

Is this a regression?

Yes, this worked in a previous version

Last Working Version

_No response_

Claude Code Version

2.1.19 and 2.1.15

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

Things that DON'T fix it:

Waiting 30-65 seconds between runs (for TIME_WAIT connections to clear)
Using different prompts
Clean install (native installer, manual binary download)
Clearing ~/.claude and ~/.claude.json between runs
Disabling telemetry ({"telemetry": "disabled"} in settings.json)
Blocking statsig.anthropic.com via /etc/hosts
Using stdbuf -oL -eL for unbuffered output
Using script -q /dev/null
Environment variable isolation (env -i HOME=$HOME PATH=... claude)
These different Claude Code versions: 2.1.15 and 2.1.19

Things that DO affect it:

Disconnecting from WiFi prevents the hang (but obviously can't use Claude)
When running the third invocation in background with output redirected (claude -p "test 3" > /tmp/test3.txt 2>&1 &), the output file remains empty even though debug logs show the API call completed successfully. The response is received internally but never written to stdout.

Key observations:

The hang occurs AFTER the API call completes successfully (per debug logs)
The process maintains an ESTABLISHED TCP connection that never closes
Each run creates ~5 new connections to 160.79.104.10, many go to TIME_WAIT
Terminal title shows "Initial greeting — claude" during hang in interactive mode
Process state is S+ (sleeping, foreground) - waiting on something

Other info:

macOS on Apple Silicon
Home network (no VPN/corporate firewall)
Multiple user accounts/profiles on Mac
Claude.ai open in browser during some tests (closed during others - no difference)

View original on GitHub ↗

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