Stop hook does not fire when response text contains newlines

Resolved 💬 3 comments Opened Mar 12, 2026 by snowmirage Closed Apr 12, 2026

Description

The Stop hook does not fire when the assistant's response text contains any newline character (\n). Single-line responses trigger the hook reliably, but multi-line responses (even very short ones) cause the hook to silently not fire at all.

This was discovered while debugging #22925 (Stop hook not firing for text-only responses). The v2.1.74 fix for #22925 partially resolved the issue — single-line text-only responses now fire the hook — but multi-line responses still do not.

Reproduction

  1. Configure a Stop hook (e.g., one that logs to a file)
  2. Send a prompt that produces a single-line response → hook fires ✅
  3. Send a prompt that produces a multi-line response (contains \n) → hook does NOT fire ❌

The hook does not fire at all — no process is spawned, no stdin is delivered.

Test Evidence

Systematic testing on v2.1.74 with 25+ controlled tests:

| Test | Response format | Result |
|------|----------------|--------|
| Single sentence, one line | The quick brown fox jumped over the lazy dog. | ✅ Hook fires |
| Two sentences, one line | Sentence one. Sentence two. | ✅ Hook fires |
| Long single paragraph (~545 chars) | One line, over 500 chars | ✅ Hook fires |
| Tool call + single-line text | Read/Bash/Edit + one-line response | ✅ Hook fires |
| Two lines with blank line | Line one.\n\nLine two. | ❌ Hook does NOT fire |
| Two lines with single newline | Line one.\nLine two. | ❌ Hook does NOT fire |
| Same text on one line | Line one. Line two. | ✅ Hook fires |
| Multi-paragraph response | Three paragraphs with \n\n | ❌ Hook does NOT fire |

Key test pair (identical text, different formatting):

  • Testing a single line break.\nThis is the second line. → ❌ No hook
  • Testing a single line break. This is the second line. → ✅ Hook fires

Impact

This effectively means the Stop hook only works for short, single-line responses. Real-world assistant responses almost always contain newlines (multiple paragraphs, bullet points, etc.), so the Stop hook is non-functional for most responses.

Use case affected: TTS voice notifications — a Stop hook that pipes last_assistant_message to a TTS engine for voice output. Only single-line responses get spoken.

Environment

  • Claude Code: 2.1.74
  • Platform: Linux (WSL2, Ubuntu 24.04)
  • Shell: zsh
  • Hook type: command (reads JSON from stdin)

Hook configuration

{
  "hooks": {
    "Stop": [{
      "matcher": "",
      "hooks": [{
        "type": "command",
        "command": "INPUT=$(cat); echo \"$INPUT\" | setsid /path/to/handler > /dev/null 2>&1 &"
      }]
    }]
  }
}

Related

  • #22925 — Stop hook not firing for text-only responses (partially fixed in v2.1.74, but multi-line responses still affected)

View original on GitHub ↗

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