Skip to content

Commit 6f472aa

Browse files
committed
refactor: deduplicate justfile install-claude-hook with .tmux entry point
The justfile reimplemented the Claude hook installation logic, which silently drifted from the .tmux entry point (missed the two-phase matching fix from PR #21). Replace with delegation to the .tmux script, starting a temporary tmux server if none is running. Closes #24
1 parent d85407a commit 6f472aa

1 file changed

Lines changed: 11 additions & 61 deletions

File tree

justfile

Lines changed: 11 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -46,74 +46,24 @@ install-plugins:
4646
install-hooks: install-claude-hook install-opencode-plugin
4747
@echo "All assistant hooks installed"
4848

49-
# Install Claude Code hooks (SessionStart + SessionEnd) into ~/.claude/settings.json
49+
# Install Claude Code hooks and OpenCode plugin via the TPM entry point.
50+
# Delegates to tmux-assistant-resurrect.tmux (single source of truth).
5051
install-claude-hook:
5152
#!/usr/bin/env bash
5253
set -euo pipefail
53-
settings="$HOME/.claude/settings.json"
54-
track_cmd="bash '{{repo_dir}}/hooks/claude-session-track.sh'"
55-
cleanup_cmd="bash '{{repo_dir}}/hooks/claude-session-cleanup.sh'"
56-
57-
if [ ! -f "$settings" ]; then
58-
mkdir -p "$(dirname "$settings")"
59-
echo '{}' > "$settings"
54+
started_server=false
55+
if ! tmux list-sessions &>/dev/null; then
56+
tmux new-session -d -s __install_hooks_tmp
57+
started_server=true
6058
fi
61-
62-
# Install SessionStart hook (session tracking)
63-
if jq -e '.hooks.SessionStart[]?.hooks[]? | select((.command // "") | contains("claude-session-track"))' "$settings" >/dev/null 2>&1; then
64-
echo "Claude SessionStart hook already configured"
65-
else
66-
tmp=$(mktemp)
67-
jq --arg cmd "$track_cmd" '
68-
.hooks //= {} |
69-
.hooks.SessionStart //= [] |
70-
.hooks.SessionStart += [{
71-
"matcher": "",
72-
"hooks": [{
73-
"type": "command",
74-
"command": $cmd
75-
}]
76-
}]
77-
' "$settings" > "$tmp" && mv "$tmp" "$settings"
78-
echo "Claude SessionStart hook installed in $settings"
59+
bash "{{repo_dir}}/tmux-assistant-resurrect.tmux"
60+
if [ "$started_server" = true ]; then
61+
tmux kill-session -t __install_hooks_tmp 2>/dev/null || true
7962
fi
8063

81-
# Install SessionEnd hook (state file cleanup)
82-
if jq -e '.hooks.SessionEnd[]?.hooks[]? | select((.command // "") | contains("claude-session-cleanup"))' "$settings" >/dev/null 2>&1; then
83-
echo "Claude SessionEnd hook already configured"
84-
else
85-
tmp=$(mktemp)
86-
jq --arg cmd "$cleanup_cmd" '
87-
.hooks //= {} |
88-
.hooks.SessionEnd //= [] |
89-
.hooks.SessionEnd += [{
90-
"matcher": "",
91-
"hooks": [{
92-
"type": "command",
93-
"command": $cmd
94-
}]
95-
}]
96-
' "$settings" > "$tmp" && mv "$tmp" "$settings"
97-
echo "Claude SessionEnd hook installed in $settings"
98-
fi
99-
100-
# Install OpenCode session-tracker plugin
64+
# Install OpenCode session-tracker plugin (delegates to .tmux entry point above)
10165
install-opencode-plugin:
102-
#!/usr/bin/env bash
103-
set -euo pipefail
104-
plugin_dir="$HOME/.config/opencode/plugins"
105-
plugin_file="$plugin_dir/session-tracker.js"
106-
source_file="{{repo_dir}}/hooks/opencode-session-track.js"
107-
108-
mkdir -p "$plugin_dir"
109-
110-
if [ -L "$plugin_file" ] && [ "$(readlink "$plugin_file")" = "$source_file" ]; then
111-
echo "OpenCode session-tracker plugin already linked"
112-
exit 0
113-
fi
114-
115-
ln -sf "$source_file" "$plugin_file"
116-
echo "OpenCode session-tracker plugin linked at $plugin_file"
66+
@echo "OpenCode plugin installed via install-claude-hook (shared entry point)"
11767

11868
# Add resurrect config to ~/.tmux.conf
11969
configure-tmux:

0 commit comments

Comments
 (0)