← back to Waitline
statusline.sh
35 lines
#!/bin/zsh
# Waitline statusline for Claude Code — sanctioned statusLine hook, no patching.
# Claude Code pipes session JSON on stdin and renders whatever we print.
# Caches the ad for 60s so we don't ledger an impression on every repaint.
CACHE=/tmp/waitline-ad-cache.json
PORT="${WAITLINE_PORT:-9718}"
input=$(cat) # session JSON from Claude Code
session=$(echo "$input" | /usr/bin/python3 -c 'import sys,json;print(json.load(sys.stdin).get("session_id","")[:8])' 2>/dev/null)
model=$(echo "$input" | /usr/bin/python3 -c 'import sys,json;print(json.load(sys.stdin).get("model",{}).get("display_name",""))' 2>/dev/null)
fresh=0
if [[ -f $CACHE ]]; then
age=$(( $(date +%s) - $(stat -f %m "$CACHE") ))
[[ $age -lt 60 ]] && fresh=1
fi
if [[ $fresh -eq 0 ]]; then
curl -s --max-time 1 "http://127.0.0.1:${PORT}/api/ad?session=${session}" -o "$CACHE" 2>/dev/null
fi
line=$(/usr/bin/python3 - "$CACHE" 2>/dev/null <<'PY'
import json, sys
d = json.load(open(sys.argv[1]))
if d.get("line"):
print("%s: %s · $%.4f earned" % (d.get("sponsor",""), d["line"], d.get("earned_total_usd",0)))
PY
)
if [[ -n "$line" ]]; then
echo "💰 ${line} | ${model}"
else
echo "${model}"
fi