#!/usr/bin/env bash # Claude Code status line: shows topic, model, and context usage # Reads session JSON from stdin, displays topic from per-session file set -euo pipefail DATA=$(cat) SESSION_ID=$(echo "$DATA" | jq -r '.session_id // empty') MODEL=$(echo "$DATA" | jq -r '.model.display_name // "unknown"') CONTEXT_PCT=$(echo "$DATA" | jq -r '.context_window.used_percentage // 0' | cut -d. -f1) FIVE_HR=$(echo "$DATA" | jq -r '.rate_limits.five_hour.used_percentage // empty' | cut -d. -f1) SEVEN_DAY=$(echo "$DATA" | jq -r '.rate_limits.seven_day.used_percentage // empty' | cut -d. -f1) MODE_TAG="" MODEL_DISPLAY="$MODEL" if [[ -n "${CLAUDE_CONFIG_DIR:-}" && -f "$CLAUDE_CONFIG_DIR/active-mode.env" ]]; then env_file="$CLAUDE_CONFIG_DIR/active-mode.env" MODE_TAG=$(grep '^CLAUDE_MODE_TAG=' "$env_file" 2>/dev/null | cut -d= -f2- || true) raw_driver=$(grep '^CLAUDE_DRIVER=' "$env_file" 2>/dev/null | cut -d= -f2- || true) escalates_to=$(grep '^CLAUDE_ESCALATES_TO=' "$env_file" 2>/dev/null | cut -d= -f2- || true) if [[ -n "$raw_driver" ]]; then # Capitalize first letter of driver (sonnet→Sonnet, haiku→Haiku, opus→Opus) driver_cap="$(tr '[:lower:]' '[:upper:]' <<< "${raw_driver:0:1}")${raw_driver:1}" if [[ "$escalates_to" == "opus" ]]; then MODEL_DISPLAY="${driver_cap}→Opus" else MODEL_DISPLAY="$driver_cap" fi fi fi TOPIC="" if [[ -n "$SESSION_ID" ]]; then # Write session ID to a known location so Claude can discover it CWD=$(echo "$DATA" | jq -r '.cwd // empty') if [[ -n "$CWD" ]]; then HASH=$(echo -n "$CWD" | md5sum | cut -d' ' -f1) echo "$SESSION_ID" > "/tmp/claude-session-id-$HASH" # Apply any pending topic that was set before the session ID existed PENDING_FILE="/tmp/claude-pending-topic-$HASH" if [[ -f "$PENDING_FILE" ]]; then TOPIC_DIR="$HOME/.claude/status/$SESSION_ID" mkdir -p "$TOPIC_DIR" mv "$PENDING_FILE" "$TOPIC_DIR/claude-topic.txt" fi fi TOPIC_FILE="$HOME/.claude/status/$SESSION_ID/claude-topic.txt" if [[ -f "$TOPIC_FILE" ]]; then TOPIC=$(cat "$TOPIC_FILE") fi fi USAGE="" if [[ -n "$FIVE_HR" ]]; then USAGE=" | 5h: ${FIVE_HR}%" if [[ -n "$SEVEN_DAY" ]]; then USAGE="$USAGE 7d: ${SEVEN_DAY}%" fi fi # Prepend mode tag to topic if set if [[ -n "$MODE_TAG" && -n "$TOPIC" ]]; then TOPIC="${MODE_TAG} · ${TOPIC}" elif [[ -n "$MODE_TAG" ]]; then TOPIC="$MODE_TAG" fi if [[ -n "$TOPIC" ]]; then echo "[$MODEL_DISPLAY] $TOPIC | ${CONTEXT_PCT}% context${USAGE}" else echo "[$MODEL_DISPLAY] ${CONTEXT_PCT}% context${USAGE}" fi