Skip to content

Instantly share code, notes, and snippets.

@saltycrane
Created August 27, 2026 15:55
Show Gist options
  • Select an option

  • Save saltycrane/1a55bc0fec43c2c163f12acf1f7f9f55 to your computer and use it in GitHub Desktop.

Select an option

Save saltycrane/1a55bc0fec43c2c163f12acf1f7f9f55 to your computer and use it in GitHub Desktop.
Vibe coded custom status line for claude code
#!/bin/bash
input=$(cat)
cwd=$(echo "$input" | jq -r '.workspace.current_dir // empty')
[ -z "$cwd" ] && cwd="$PWD"
# Collapse $HOME to ~ like PS1's \w does
dir="$cwd"
if [ -n "$HOME" ] && [ "${dir#"$HOME"}" != "$dir" ]; then
dir="~${dir#"$HOME"}"
fi
printf '\033[01;32m%s\033[00m:\033[01;36m%s\033[00m' "$dir"
# Project name from nearest package.json (walking up from cwd)
# (This was added for sandboxes where the cwd is always the same.)
project=""
search_dir="$cwd"
while [ -n "$search_dir" ] && [ "$search_dir" != "/" ]; do
if [ -f "$search_dir/package.json" ]; then
project=$(jq -r '.name // empty' "$search_dir/package.json" 2>/dev/null)
break
fi
search_dir=$(dirname "$search_dir")
done
if [ -n "$project" ]; then
printf '\033[00;36m(%s)\033[00m' "$project"
fi
# Git branch (only shown when cwd is inside a git repo; optional locks skipped)
branch=$(git -C "$cwd" --no-optional-locks branch --show-current 2>/dev/null)
if [ -n "$branch" ]; then
printf ':\033[00;35m%s\033[00m' "$branch"
fi
# Model name and effort
model=$(echo "$input" | jq -r '.model.id // empty')
effort=$(echo "$input" | jq -r '.effort.level // empty')
if [ -n "$model" ]; then
printf ' \033[00;33m%s:%s\033[00m' "$model" "$effort"
fi
# Total session cost in USD (only present if the input provides it)
cost=$(echo "$input" | jq -r '.cost.total_cost_usd // empty')
if [ -n "$cost" ]; then
printf ' \033[00;37m$%s\033[00m' "$(awk -v c="$cost" 'BEGIN { printf "%.2f", c }')"
fi
# Context usage as a compact token count (e.g. 35.1k, 1.2m)
format_compact_tokens() {
awk -v n="$1" 'BEGIN {
if (n >= 1000000) printf "%.1fm", n/1000000;
else if (n >= 1000) printf "%.1fk", n/1000;
else printf "%d", n;
}'
}
used_tokens=$(echo "$input" | jq -r '.context_window.total_input_tokens // empty')
total_tokens=$(echo "$input" | jq -r '.context_window.context_window_size // empty')
if [ -n "$used_tokens" ]; then
used_fmt=$(format_compact_tokens "$used_tokens")
if [ -n "$total_tokens" ]; then
total_fmt=$(format_compact_tokens "$total_tokens")
printf ' \033[00;37m%s/%s\033[00m' "$used_fmt" "$total_fmt"
else
printf ' \033[00;37m%s\033[00m' "$used_fmt"
fi
fi
printf '\n'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment