SessionEnd hook: add 'prompt' type for inline AI processing
Resolved 💬 2 comments Opened Feb 3, 2026 by odysseus0 Closed Feb 3, 2026
Problem
SessionEnd hooks can only run shell commands. Any AI processing of session context requires hacking together a claude --resume subprocess, which introduces:
- Recursion — resumed session ends → triggers SessionEnd again → infinite loop
- Nested Claude bug —
--resume --print > filesilently fails when called from within Claude (stdout doesn't redirect) - Exit blocking — hook blocks session exit unless you fully detach with
nohup ... </dev/null >/dev/null 2>&1 & - Workaround overhead — env var recursion guards,
--no-session-persistence, FD management
All of this just to do something simple: process the session context with a model after the session ends.
Proposed solution
Add a prompt hook type:
{
"hooks": {
"SessionEnd": [
{
"matcher": "clear|prompt_input_exit",
"hooks": [
{
"type": "prompt",
"model": "haiku",
"prompt": "Evaluate this session and generate a note if worth documenting. Write to ~/notes/sessions/ using the Write tool."
}
]
}
]
}
}
The hook runtime already has session_id, transcript_path, and full session context. A prompt type would:
- Pass session context to the specified model directly (no
--resumeneeded) - Run as a hook-scoped invocation (no SessionEnd re-trigger, no recursion)
- Handle async execution internally (no exit blocking)
- Allow tool use (Read/Write) for the model to act on its evaluation
Current workaround
~80 lines of shell script that:
- Parses JSON input for session_id/reason
- Filters by exit reason
- Guards against recursion via env var
- Spawns
claude --resume $SESSION_ID --no-session-persistence --dangerously-skip-permissionsvianohupwith all FDs closed - Hopes it works
Why this matters
Session-end AI processing is a natural use case (auto-summarization, memory extraction, cleanup). The current command type forces users through a fragile gauntlet of subprocess management that shouldn't be necessary.
🤖 Generated with Claude Code
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗