Skip to content

Instantly share code, notes, and snippets.

@ryx2
Created August 11, 2025 00:15
Show Gist options
  • Save ryx2/6b593ef2d6fa8903e5237f7fb5bb96bb to your computer and use it in GitHub Desktop.
Save ryx2/6b593ef2d6fa8903e5237f7fb5bb96bb to your computer and use it in GitHub Desktop.
my claude code status line
#!/bin/bash
# Read JSON input from stdin
input=$(cat)
# printf "input: %s\n" "$input"
# Extract current directory and replace home with ~
current_dir=$(echo "$input" | jq -r '.workspace.current_dir' | sed "s|^$HOME|~|")
# Extract session id and Claude version
session_id=$(echo "$input" | jq -r '.session_id // "unknown"')
claude_version=$(echo "$input" | jq -r '.version // ""')
# Prepare per-session timing log and compute last command duration
log_dir="$HOME/logs"
mkdir -p "$log_dir"
log_file="$log_dir/claude_${session_id}.txt"
# Current epoch milliseconds (use python3 if available for precision)
if command -v python3 >/dev/null 2>&1; then
now_ms=$(python3 -c 'import time; print(int(time.time()*1000))')
else
now_ms=$(( $(date +%s) * 1000 ))
fi
prev_ms=""
if [ -f "$log_file" ]; then
prev_ms=$(tail -n 1 "$log_file" | awk '{print $1}')
fi
duration_ms=0
if [ -n "$prev_ms" ] && [ "$prev_ms" -gt 0 ] 2>/dev/null; then
if [ "$now_ms" -gt "$prev_ms" ] 2>/dev/null; then
duration_ms=$(( now_ms - prev_ms ))
fi
fi
# Append current timestamp and computed duration to the session log
echo "$now_ms $duration_ms" >> "$log_file"
# Human-readable seconds with one decimal
last_cmd_secs=$(awk -v ms="$duration_ms" 'BEGIN { printf "%.1f", (ms/1000.0) }')
# Get git branch name if we're in a git repository
git_branch=""
workspace_dir=$(echo "$input" | jq -r '.workspace.current_dir')
if [ -d "$workspace_dir/.git" ] || git -C "$workspace_dir" rev-parse --git-dir >/dev/null 2>&1; then
branch_name=$(git -C "$workspace_dir" branch --show-current 2>/dev/null)
if [ -n "$branch_name" ]; then
git_branch="🌿 $branch_name"
fi
fi
# Get current datetime in Pacific timezone with AM/PM format and attach last command duration
current_time=$(TZ="America/Los_Angeles" date "+%Y-%m-%d %I:%M:%S %p PST")
time_display="$current_time ⏱️ ${last_cmd_secs}s"
# Get weather with emoji (using a simple weather service), cached for 30 minutes
# Cache file stores two lines: epoch_ms and the rendered weather string
weather_info="🌤️ cant see the weather lol"
weather_cache="$log_dir/claude_weather_cache.txt"
cache_valid=false
if [ -f "$weather_cache" ]; then
cache_ts=$(sed -n '1p' "$weather_cache")
cached_weather=$(sed -n '2p' "$weather_cache")
if [ -n "$cache_ts" ] && [ -n "$cached_weather" ] && [ "$cache_ts" -gt 0 ] 2>/dev/null; then
diff_ms=$(( now_ms - cache_ts ))
if [ "$diff_ms" -ge 0 ] 2>/dev/null && [ "$diff_ms" -lt 1800000 ]; then
weather_info="$cached_weather"
cache_valid=true
fi
fi
fi
if [ "$cache_valid" != true ] && command -v curl >/dev/null 2>&1; then
# Use wttr.in with explicit Fahrenheit via `?u` and include feels-like via `%f`
# Use pipe `|` delimiters for easy parsing: condition|temp|feels
weather_raw=$(curl -s -m 3 "wttr.in/?format=%C|%t|%f&u" 2>/dev/null || echo "")
if [ -n "$weather_raw" ] && [ "$weather_raw" != "" ]; then
IFS='|' read -r condition temp feels <<< "$weather_raw"
if [ -n "$condition" ] && [ -n "$temp" ] && [ -n "$feels" ]; then
emoji="🌤️"
case "$condition" in
*"Clear"*|*"Sunny"*) emoji="☀️" ;;
*"Partly cloudy"*|*"Partly Cloudy"*) emoji="⛅" ;;
*"Cloudy"*|*"Overcast"*) emoji="☁️" ;;
*"Rain"*|*"Drizzle"*) emoji="🌧️" ;;
*"Snow"*) emoji="❄️" ;;
*"Thunderstorm"*|*"Storm"*) emoji="⛈️" ;;
*) emoji="🌤️" ;;
esac
temp_clean=${temp#+}
feels_clean=${feels#+}
weather_info="$emoji $condition ${temp_clean} feels ${feels_clean}"
else
case "$weather_raw" in
*"Clear"*|*"Sunny"*) weather_info="☀️ $weather_raw" ;;
*"Partly cloudy"*|*"Partly Cloudy"*) weather_info="⛅ $weather_raw" ;;
*"Cloudy"*|*"Overcast"*) weather_info="☁️ $weather_raw" ;;
*"Rain"*|*"Drizzle"*) weather_info="🌧️ $weather_raw" ;;
*"Snow"*) weather_info="❄️ $weather_raw" ;;
*"Thunderstorm"*|*"Storm"*) weather_info="⛈️ $weather_raw" ;;
*) weather_info="🌤️ $weather_raw" ;;
esac
fi
# Write cache atomically
tmp_cache="${weather_cache}.tmp"
printf "%s\n%s\n" "$now_ms" "$weather_info" > "$tmp_cache" && mv "$tmp_cache" "$weather_cache"
fi
fi
# No variable needed for colored version; embed color codes in printf format
# Format the status line with colors
if [ -n "$git_branch" ]; then
printf "\033[01;34m%s\033[00m | \033[01;32m%s\033[00m | \033[01;36m%s\033[00m | %s | v \033[01;33m%s\033[00m" \
"$current_dir" "$git_branch" "$time_display" "$weather_info" "$claude_version"
else
printf "\033[01;34m%s\033[00m | \033[01;36m%s\033[00m | %s | v \033[01;33m%s\033[00m" \
"$current_dir" "$time_display" "$weather_info" "$claude_version"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment