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:
openhands 2026-03-20 01:11:26 +00:00
parent 7d03f2c9ee
commit 0a095c4656
2 changed files with 57 additions and 2 deletions

22
lib/hooks/on-session-end.sh Executable file
View 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