disinto/lib/hooks/on-session-end.sh
openhands 0be64bdf31 fix: Hook scripts don't follow #!/usr/bin/env bash convention from AGENTS.md (#330)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 08:59:56 +00:00

22 lines
725 B
Bash
Executable file

#!/usr/bin/env 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