[BUG] SessionEnd hook stdin pipe not closed for /clear events

Status Closed — not planned
Reported on v2.1.211
Maintainer reply None cached
Activity 3 comments · opened Jul 20, 2026 · closed Aug 22, 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?

When a SessionEnd hook fires with reason: "clear" (triggered by the /clear command), Claude Code writes the JSON payload to the hook process's stdin but does not close the pipe. Any hook that reads stdin until EOF (e.g. using json.load(sys.stdin) in Python or $(cat) in shell) blocks indefinitely waiting for EOF that never comes. Claude Code eventually kills the hung hook process via timeout, so the hook never completes.

This does not affect other SessionEnd reasons (prompt_input_exit, other) — those close stdin correctly.

What Should Happen?

After writing the JSON payload to the hook's stdin, Claude Code should close the stdin pipe regardless of the reason value, so hooks that read until EOF return normally.

Error Messages/Logs

No error is surfaced to the user. The hook silently times out and exits without running.

A hook that uses a non-blocking stdin read (e.g. `select.select` with a short timeout) will log nothing on timeout — confirming stdin has no data or the pipe never closes.

Steps to Reproduce

  1. Add a SessionEnd hook that reads stdin and writes the parsed JSON to a file:

``sh
# settings.json hook command
"python3 -c \"import json,sys; d=json.load(sys.stdin); open('/tmp/hook-out.json','w').write(str(d))\""
``

  1. Open any project in Claude Code.
  2. Send at least one message.
  3. Run /clear.
  4. Check /tmp/hook-out.json — the file is never written.
  5. Repeat step 4 but end the session normally (close the window) — /tmp/hook-out.json is written immediately.

Claude Model

Sonnet (default)

Is this a regression?

Yes, this worked in a previous version

Last Working Version

2.1.211

Claude Code Version

2.1.215

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Other

Additional Information

I'm using Ghostty as my emulator, and zsh as my shell.

View original on GitHub ↗

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