Skip to content

Instantly share code, notes, and snippets.

@prmichaelsen
Created May 6, 2026 12:11
Show Gist options
  • Select an option

  • Save prmichaelsen/c918a32050e443f5d1f35fe78e33f699 to your computer and use it in GitHub Desktop.

Select an option

Save prmichaelsen/c918a32050e443f5d1f35fe78e33f699 to your computer and use it in GitHub Desktop.
#!/bin/sh
input=$(cat)
# Date/time (magenta)
dt=$(date "+%Y-%m-%d %H:%M:%S")
# Current directory styled like PS1: show ~ prefix when inside $HOME
cwd=$(echo "$input" | jq -r '.workspace.current_dir // .cwd')
home="$HOME"
case "$cwd" in
"$home"*) cwd="~${cwd#$home}" ;;
esac
# Output style — show caveman badge when caveman mode is active
style_name=$(echo "$input" | jq -r '.output_style.name // empty')
caveman_badge=""
case "$style_name" in
*[Cc]aveman*) caveman_badge=" \033[0;33m[CAVEMAN]\033[0m" ;;
esac
# Token usage — show used% and total context tokens (input + cache reads) formatted as Nk
# Also try to extract message-only tokens for visibility
used_pct=$(echo "$input" | jq -r '.context_window.used_percentage // empty')
used_tokens=$(echo "$input" | jq -r '
if .context_window.current_usage != null then
(.context_window.current_usage.input_tokens // 0) +
(.context_window.current_usage.cache_read_input_tokens // 0)
else empty end')
msg_tokens=$(echo "$input" | jq -r '.context_window.current_usage.messages_tokens // empty')
token_info=""
if [ -n "$used_pct" ]; then
used_int=$(printf "%.0f" "$used_pct")
if [ -n "$used_tokens" ] && [ "$used_tokens" -gt 0 ] 2>/dev/null; then
tokens_k=$(echo "$used_tokens" | awk '{printf "%.1fk", $1/1000}')
if [ -n "$msg_tokens" ] && [ "$msg_tokens" -gt 0 ] 2>/dev/null; then
msg_k=$(echo "$msg_tokens" | awk '{printf "%.1fk", $1/1000}')
token_info=" \033[0;32m[ctx:${used_int}% | ${tokens_k} msg:${msg_k}]\033[0m"
else
token_info=" \033[0;32m[ctx:${used_int}% | ${tokens_k}]\033[0m"
fi
else
token_info=" \033[0;32m[ctx:${used_int}%]\033[0m"
fi
fi
# Assemble: magenta date, cyan dir, optional caveman badge, optional token usage
printf "\033[0;35m%s\033[0m \033[0;36m%s\033[0m%b%b" "$dt" "$cwd" "$caveman_badge" "$token_info"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment