Skip to content

Commit 3773e8d

Browse files
committed
feat(claude): add zellij tab activity indicators
Shows Claude status in zellij tab name: - 🔄 during tool use - 🟥 on permission request - 🟢 when stopped - Branch name in worktrees, folder name otherwise
1 parent bd8ccf7 commit 3773e8d

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

claude/hooks/zellij-activity.sh

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/bash
2+
# Displays Claude Code activity status in Zellij tab name
3+
#
4+
# Required ~/.claude/settings.json hooks configuration:
5+
#
6+
# "hooks": {
7+
# "SessionStart": [{ "matcher": "", "hooks": ["/path/to/zellij-activity.sh"] }],
8+
# "PreToolUse": [{ "matcher": "", "hooks": ["/path/to/zellij-activity.sh"] }],
9+
# "PermissionRequest": [{ "matcher": "", "hooks": ["/path/to/zellij-activity.sh"] }],
10+
# "Stop": [{ "matcher": "", "hooks": ["/path/to/zellij-activity.sh"] }],
11+
# "SessionEnd": [{ "matcher": "", "hooks": ["/path/to/zellij-activity.sh"] }]
12+
# }
13+
14+
[[ -z "$ZELLIJ" ]] && exit 0
15+
16+
input=$(cat)
17+
18+
hook_type=$(echo "$input" | jq -r '.hook_event_name // empty')
19+
cwd=$(echo "$input" | jq -r '.cwd // .session.cwd // empty')
20+
21+
state_file="/tmp/zellij-claude-tab-${ZELLIJ_PANE_ID}"
22+
23+
set_base_name() {
24+
local base_name=""
25+
26+
if [[ -n "$cwd" ]]; then
27+
cd "$cwd" 2>/dev/null || return
28+
git_path=$(git rev-parse --git-dir 2>/dev/null)
29+
if [[ "$git_path" =~ \.git/worktrees/ ]]; then
30+
base_name=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
31+
fi
32+
fi
33+
34+
[[ -z "$base_name" || "$base_name" == "HEAD" ]] && base_name=$(basename "${cwd:-$PWD}")
35+
36+
echo "$base_name" > "$state_file"
37+
echo "$base_name"
38+
}
39+
40+
get_base_name() {
41+
if [[ -f "$state_file" ]]; then
42+
cat "$state_file"
43+
else
44+
set_base_name
45+
fi
46+
}
47+
48+
rename_tab() {
49+
local name="$1"
50+
zellij action rename-tab "$name" 2>/dev/null
51+
}
52+
53+
case "$hook_type" in
54+
SessionStart)
55+
base_name=$(set_base_name)
56+
rename_tab "$base_name"
57+
;;
58+
PreToolUse)
59+
tool_name=$(echo "$input" | jq -r '.tool_name // empty')
60+
base_name=$(get_base_name)
61+
if [[ "$tool_name" == "AskUserQuestion" ]]; then
62+
rename_tab "$base_name"
63+
else
64+
rename_tab "🔄 $base_name"
65+
fi
66+
;;
67+
PermissionRequest)
68+
tool_name=$(echo "$input" | jq -r '.tool_name // empty')
69+
[[ "$tool_name" == "AskUserQuestion" ]] && exit 0
70+
base_name=$(get_base_name)
71+
rename_tab "🔴 $base_name"
72+
;;
73+
Stop)
74+
base_name=$(get_base_name)
75+
rename_tab "🟢 $base_name"
76+
;;
77+
SessionEnd)
78+
base_name=$(get_base_name)
79+
rename_tab "$base_name"
80+
rm -f "$state_file"
81+
;;
82+
esac

0 commit comments

Comments
 (0)