fix: feat: SessionEnd hook for guaranteed cleanup on session exit (#276)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
7d03f2c9ee
commit
0a095c4656
2 changed files with 57 additions and 2 deletions
22
lib/hooks/on-session-end.sh
Executable file
22
lib/hooks/on-session-end.sh
Executable file
|
|
@ -0,0 +1,22 @@
|
|||
#!/bin/bash
|
||||
# on-session-end.sh — SessionEnd hook for dark-factory agent sessions.
|
||||
#
|
||||
# Called by Claude Code when a session terminates (clean exit, logout,
|
||||
# crash, OOM, etc.). Writes a termination marker so monitor_phase_loop
|
||||
# can detect session death faster than tmux has-session polling alone.
|
||||
#
|
||||
# Usage (in .claude/settings.json):
|
||||
# {"type": "command", "command": "this-script /tmp/claude-exited-SESSION.ts"}
|
||||
#
|
||||
# Args: $1 = marker file path
|
||||
|
||||
input=$(cat) # consume hook JSON from stdin
|
||||
|
||||
reason=$(printf '%s' "$input" | jq -r '
|
||||
.matched_hook // .reason // .type // "unknown"
|
||||
' 2>/dev/null)
|
||||
[ -z "$reason" ] && reason="unknown"
|
||||
|
||||
if [ -n "${1:-}" ]; then
|
||||
printf '%s %s\n' "$(date +%s)" "$reason" > "$1"
|
||||
fi
|
||||
Loading…
Add table
Add a link
Reference in a new issue