set-topic.sh now renames the tmux session to the project part of the
topic and stores the full topic in @claude_topic when run inside tmux.
Pairs with ~/.tmux.conf status-right showing #{@claude_topic}.
Claude-Session: https://claude.ai/code/session_01Xt2b3uQtakYGhH5Y653vwd
39 lines
1.3 KiB
Bash
Executable File
39 lines
1.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Usage: set-topic.sh <cwd> <topic text>
|
|
# Finds the session ID for the given cwd and writes the topic file
|
|
|
|
set -euo pipefail
|
|
|
|
CWD="$1"
|
|
shift
|
|
TOPIC="$*"
|
|
|
|
HASH=$(echo -n "$CWD" | md5sum | cut -d' ' -f1)
|
|
SESSION_FILE="/tmp/claude-session-id-$HASH"
|
|
|
|
# If running inside tmux, mirror the topic into the tmux status bar:
|
|
# session name = project part (before ':'), @claude_topic = full topic.
|
|
if [[ -n "${TMUX:-}" ]]; then
|
|
PROJECT="${TOPIC%%:*}"
|
|
# tmux session names may not contain ':' or '.'
|
|
PROJECT=$(echo "$PROJECT" | tr ':.' '--' | cut -c1-30)
|
|
tmux rename-session "$PROJECT" 2>/dev/null || true
|
|
tmux set -q @claude_topic "$TOPIC" 2>/dev/null || true
|
|
fi
|
|
|
|
if [[ ! -f "$SESSION_FILE" ]]; then
|
|
# Session ID file doesn't exist yet — the statusline hook hasn't run.
|
|
# Write the topic to a pending file so statusline.sh can pick it up
|
|
# on its first run for this cwd.
|
|
PENDING_FILE="/tmp/claude-pending-topic-$HASH"
|
|
echo "$TOPIC" > "$PENDING_FILE"
|
|
echo "Topic queued (session ID not yet available). Will be applied after next response."
|
|
exit 0
|
|
fi
|
|
|
|
SESSION_ID=$(cat "$SESSION_FILE")
|
|
TOPIC_DIR="$HOME/.claude/status/$SESSION_ID"
|
|
mkdir -p "$TOPIC_DIR"
|
|
echo "$TOPIC" > "$TOPIC_DIR/claude-topic.txt"
|
|
echo "Topic set for session $SESSION_ID: $TOPIC"
|