aboutsummaryrefslogtreecommitdiff
path: root/hooks
diff options
context:
space:
mode:
Diffstat (limited to 'hooks')
-rwxr-xr-xhooks/session-title.sh41
-rw-r--r--hooks/settings-snippet.json6
2 files changed, 47 insertions, 0 deletions
diff --git a/hooks/session-title.sh b/hooks/session-title.sh
new file mode 100755
index 0000000..8a12f61
--- /dev/null
+++ b/hooks/session-title.sh
@@ -0,0 +1,41 @@
+#!/bin/sh
+# SessionStart(startup|resume) hook: title the session "<host> <project>"
+# (e.g. "ratio rulesets", "velox work") so remote sessions are identifiable
+# in the claude.ai/code and mobile session lists instead of auto-generated
+# names.
+#
+# Project = basename of the git toplevel when cwd is inside a repo (a session
+# started in a subdirectory still names the project), else basename of cwd.
+#
+# Only fires when the session has no title yet: a /rename, an earlier run, or
+# any other titling must not be clobbered on resume. The harness ignores
+# sessionTitle on clear/compact sources, so the settings matcher restricts to
+# startup|resume.
+#
+# Wire in settings.json:
+#
+# "SessionStart": [
+# { "matcher": "startup|resume",
+# "hooks": [ { "type": "command",
+# "command": "~/.claude/hooks/session-title.sh" } ] }
+# ]
+
+input=$(cat)
+
+existing=$(echo "$input" | jq -r '.session_title // empty')
+[ -n "$existing" ] && exit 0
+
+cwd=$(echo "$input" | jq -r '.cwd // empty')
+[ -n "$cwd" ] || cwd=$PWD
+
+project=$(git -C "$cwd" rev-parse --show-toplevel 2>/dev/null)
+if [ -n "$project" ]; then
+ project=$(basename "$project")
+else
+ project=$(basename "$cwd")
+fi
+
+# uname -n, not hostname: Arch doesn't ship hostname by default (inetutils).
+host=$(uname -n)
+
+python3 -c 'import json,sys; print(json.dumps({"hookSpecificOutput":{"hookEventName":"SessionStart","sessionTitle":sys.argv[1]}}))' "$host $project"
diff --git a/hooks/settings-snippet.json b/hooks/settings-snippet.json
index 1be5f00..a5f9d9c 100644
--- a/hooks/settings-snippet.json
+++ b/hooks/settings-snippet.json
@@ -2,6 +2,12 @@
"hooks": {
"SessionStart": [
{
+ "matcher": "startup|resume",
+ "hooks": [
+ { "type": "command", "command": "~/.claude/hooks/session-title.sh" }
+ ]
+ },
+ {
"matcher": "clear",
"hooks": [
{ "type": "command", "command": "~/.claude/hooks/session-clear-resume.sh" }