diff --git a/scripts/amp-statusline.sh b/scripts/amp-statusline.sh index e05ddbf..590e47b 100755 --- a/scripts/amp-statusline.sh +++ b/scripts/amp-statusline.sh @@ -15,6 +15,7 @@ # Agent resolution order: # 1. AMP_AGENT_ID env var (explicit UUID) # 2. CLAUDE_AGENT_NAME env var (AI Maestro sets this) +# 2.5 Claude Code native session_name (`claude --name`), if it maps to an agent # 3. tmux session name # 4. Working directory → AI Maestro API lookup # 5. Working directory → walk up to .claude/settings.local.json for @@ -101,6 +102,9 @@ MODEL=$(echo "$input" | jq -r '.model.display_name // "?"') PCT=$(echo "$input" | jq -r '.context_window.used_percentage // 0' | cut -d. -f1) COST=$(echo "$input" | jq -r '.cost.total_cost_usd // 0') CWD=$(echo "$input" | jq -r '.workspace.current_dir // empty') +# Claude Code's native session name (set by `claude --name` / `/rename`). Present +# only when a custom or AI-generated title exists; used below as an identity hint. +SESSION_NAME=$(echo "$input" | jq -r '.session_name // empty') # --- Resolve AMP agent --- AGENTS_BASE="${HOME}/.agent-messaging/agents" @@ -119,6 +123,13 @@ if [ -n "${AMP_AGENT_ID:-}" ]; then elif [ -n "${CLAUDE_AGENT_NAME:-}" ]; then AGENT_NAME="$CLAUDE_AGENT_NAME" +# Priority 2.5: Claude Code's native session name (set by `claude --name`, as +# AI Maestro does when launching an agent). Trust it ONLY when it maps to a known +# agent — an AI-generated session title must not shadow the cwd/hint fallbacks. +elif [ -n "$SESSION_NAME" ] && [ -f "$INDEX_FILE" ] && \ + [ -n "$(jq -r --arg n "$SESSION_NAME" '.[$n] // empty' "$INDEX_FILE" 2>/dev/null)" ]; then + AGENT_NAME="$SESSION_NAME" + # Priority 3: tmux session name elif [ -n "${TMUX:-}" ]; then AGENT_NAME=$(tmux display-message -p '#S' 2>/dev/null)