forked from code-yeongyu/oh-my-openagent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleanup-hook.sh
More file actions
executable file
·45 lines (37 loc) · 1.14 KB
/
Copy pathcleanup-hook.sh
File metadata and controls
executable file
·45 lines (37 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env bash
# Non-blocking Claude Code SessionEnd launcher for cleanup.sh.
#
# Claude may cancel shutdown hooks while the session is closing. Keep this hook
# tiny and best-effort, then let cleanup.sh do strict synchronous work outside
# the hook process.
set -u
PROJECT_DIR="${CLAUDE_PROJECT_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)}"
CLEANUP_SCRIPT="$PROJECT_DIR/script/agent/cleanup.sh"
LOG_DIR="${TMPDIR:-/tmp}"
case "$LOG_DIR" in
*..* | "")
LOG_DIR="/tmp"
;;
/tmp | /tmp/* | /private/tmp | /private/tmp/* | /var/folders/*)
;;
*)
LOG_DIR="/tmp"
;;
esac
LOG_FILE="${LOG_DIR%/}/oh-my-openagent-cleanup.log"
if [ ! -f "$CLEANUP_SCRIPT" ]; then
printf '[cleanup-hook] missing cleanup script: %s\n' "$CLEANUP_SCRIPT" >&2
exit 0
fi
mkdir -p "$(dirname "$LOG_FILE")" 2>/dev/null || true
if [ "${OMO_AGENT_CLEANUP_SYNC:-0}" = "1" ]; then
bash "$CLEANUP_SCRIPT" >>"$LOG_FILE" 2>&1 || true
exit 0
fi
if command -v nohup >/dev/null 2>&1; then
nohup bash "$CLEANUP_SCRIPT" >>"$LOG_FILE" 2>&1 </dev/null &
else
bash "$CLEANUP_SCRIPT" >>"$LOG_FILE" 2>&1 </dev/null &
fi
disown "$!" 2>/dev/null || true
exit 0