You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SessionEnd hooks are killed before completion when running async work #41577
SessionEnd hooks that perform any non-trivial async work (e.g., an API call) are killed before they can complete. Claude Code appears to exit the process without waiting for the hook to finish, even when a generous timeout is configured (tested up to 90s).
The hook script calls claude -p --model haiku to summarize the session transcript (takes ~5s):
#!/bin/bashset -euo pipefail
INPUT=$(cat)
TRANSCRIPT_PATH=$(echo "$INPUT"| jq -r '.transcript_path // empty')# ... extract condensed transcript with jq ...
SUMMARY=$(echo "$CONDENSED"| claude -p --bare --model haiku "Summarize this session"2>/dev/null)# ... write to log file ...
Exit a Claude Code session normally
Expected: The hook runs to completion within the configured 90s timeout, then Claude Code exits.
Actual: Claude Code exits almost immediately. The claude -p subprocess is killed before it can return. Debug logging confirms the script reaches the claude -p call but never reaches the line after it.
Workaround
Detach the heavy work into a background process so it survives parent exit:
nohup bash -c ' # ... summarization work here ...' _ "$TRANSCRIPT_PATH""$SESSION_ID""$CWD">/dev/null 2>&1&disownexit 0
This works reliably but means the hook has no way to report errors back to Claude Code, and users need to manage their own timeout (e.g., wrapping the API call in timeout 60).
Suggestion
Either:
Wait for SessionEnd hooks to complete (up to the configured timeout) before exiting the process, consistent with how other hook events appear to work
Document the limitation that SessionEnd hooks must not rely on completing before the parent exits, and recommend the nohup/disown pattern for async work
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.
Activity
github-actions commentedon Mar 31, 2026
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
github-actions commentedon Apr 4, 2026
This issue has been automatically closed as a duplicate of #24206.
If this is incorrect, please re-open this issue or create a new one.
🤖 Generated with Claude Code
github-actions commentedon Apr 17, 2026
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.