Skip to content

Instantly share code, notes, and snippets.

@interaminense
Last active June 19, 2026 18:40
Show Gist options
  • Select an option

  • Save interaminense/6a4665f933da85a387b2cdccc1355502 to your computer and use it in GitHub Desktop.

Select an option

Save interaminense/6a4665f933da85a387b2cdccc1355502 to your computer and use it in GitHub Desktop.
My claude code statusline.sh
#!/usr/bin/env bash
# Claude Code status line. Recebe o JSON da sessΓ£o via stdin.
#
# Segmentos: πŸ“Œ sessΓ£o (/rename) Β· 🌿 branch Β· 🌳 worktree β€Ί caminho relativo Β·
# barra de contexto (0–100%) Β· ⏳ uso da janela de 5h (% + horΓ‘rio de reset) Β· modelo.
# ─── Tema ──────────────────────────────────────────────────────────────────
# Troque o valor abaixo para mudar o visual (ou defina CC_STATUSLINE_THEME):
# adaptativo Β· separadores cinza, barra colorida, modelo esmaecido (padrΓ£o)
# minimalista Β· sem emoji, monocromΓ‘tico, separador "Β·"
# colorido Β· cada segmento com uma cor prΓ³pria
# duas-linhas Β· identidade em cima, mΓ©tricas embaixo
# powerline Β· blocos com fundo + setas (precisa de fonte Nerd/Powerline)
# usage Β· barras separadas para contexto e janela de 5h
THEME="${CC_STATUSLINE_THEME:-colorido}"
# ─────────────────────────────────────────────────────────────────────────────
input=$(cat)
name=$(printf '%s' "$input" | jq -r '.session_name // empty')
dir=$(printf '%s' "$input" | jq -r '.workspace.current_dir // empty')
model=$(printf '%s' "$input" | jq -r '.model.display_name // empty')
pct=$(printf '%s' "$input" | jq -r '.context_window.used_percentage // empty')
h5=$(printf '%s' "$input" | jq -r '.rate_limits.five_hour.used_percentage // empty')
h5reset=$(printf '%s' "$input" | jq -r '.rate_limits.five_hour.resets_at // empty')
branch=$(git -C "$dir" branch --show-current 2>/dev/null)
top=$(git -C "$dir" rev-parse --show-toplevel 2>/dev/null)
host=$(hostname 2>/dev/null)
# ─── Paleta e helpers ────────────────────────────────────────────────────────
e=$'\033'
reset="${e}[0m"; gray="${e}[90m"; dim="${e}[2m"; bold="${e}[1m"
green="${e}[32m"; yellow="${e}[33m"; red="${e}[31m"
cyan="${e}[36m"; blue="${e}[34m"; magenta="${e}[35m"
clamp() { local v=$1; [ "$v" -gt 100 ] && v=100; [ "$v" -lt 0 ] && v=0; printf '%s' "$v"; }
clr() { # cor por faixa de uso
if [ "$1" -ge 80 ]; then printf '%s' "$red"
elif [ "$1" -ge 50 ]; then printf '%s' "$yellow"
else printf '%s' "$green"; fi; }
mkbar() { # barra de 10 blocos (ou $2)
local p=$1 t=${2:-10} f i b=""; f=$((p * t / 100))
for ((i = 0; i < f; i++)); do b+="β–ˆ"; done
for ((i = 0; i < t - f; i++)); do b+="β–‘"; done
printf '%s' "$b"; }
join_segs() { local sep="$1"; shift; local out="" s
for s in "$@"; do [ -z "$out" ] && out="$s" || out="${out}${sep}${s}"; done
printf '%s' "$out"; }
hyperlink() { # $1=uri $2=texto β†’ hyperlink OSC 8 (ctrl+clique no Ghostty)
printf '\033]8;;%s\033\\%s\033]8;;\033\\' "$1" "$2"; }
# ─── Valores derivados ───────────────────────────────────────────────────────
p=$(printf '%.0f' "$pct" 2>/dev/null); p=$(clamp "${p:-0}")
# Worktree (raiz do working tree) e caminho atual relativo a ela.
wticon="🌳"
if [ -n "$top" ]; then
wt=$(basename "$top")
rel=${dir#"$top"}; rel=${rel#/}
if [ -n "$rel" ]; then
IFS='/' read -r -a parts <<< "$rel"
n=${#parts[@]}
[ "$n" -gt 2 ] && rel="${parts[0]}/.../${parts[$((n - 1))]}"
pathfull="${wt} β€Ί ${rel}"; pathshort="${rel}"
else
pathfull="${wt}"; pathshort="${wt}"
fi
# Hyperlink: ctrl+clique abre uma nova janela do Ghostty na raiz do worktree.
link="ghosttycd://${top}"
pathfull=$(hyperlink "$link" "$pathfull")
pathshort=$(hyperlink "$link" "$pathshort")
elif [ -n "$dir" ]; then
wticon="πŸ“"; pathfull=$(basename "$dir"); pathshort="$pathfull"
fi
ctxbar=$(mkbar "$p"); cctx=$(clr "$p")
# Janela de 5h: porcentagem (colorida por faixa) + horΓ‘rio de reset.
if [ -n "$h5" ]; then
h5n=$(printf '%.0f' "$h5" 2>/dev/null); h5n=$(clamp "${h5n:-0}")
c5=$(clr "$h5n")
[ -n "$h5reset" ] && h5hm=$(date -d "@${h5reset}" +%H:%M 2>/dev/null)
fi
SEP=" ${gray}β”‚${reset} "
DOT=" ${dim}Β·${reset} "
# ─── ConstruΓ§Γ£o por tema ─────────────────────────────────────────────────────
line=""
case "$THEME" in
minimalista)
segs=("${name:-(sem nome)}")
[ -n "$branch" ] && segs+=("$branch")
[ -n "$pathshort" ] && segs+=("$pathshort")
segs+=("${dim}ctx${reset} ${p}%")
if [ -n "$h5n" ]; then
u="${h5n}%"; [ -n "$h5hm" ] && u="${u} ${dim}Β· ${h5hm}${reset}"
segs+=("$u")
fi
[ -n "$model" ] && segs+=("${dim}${model}${reset}")
line=$(join_segs "$DOT" "${segs[@]}")
;;
colorido)
segs=("${cyan}πŸ“Œ ${name:-(sem nome)}${reset}")
[ -n "$branch" ] && segs+=("${green}🌿 ${branch}${reset}")
[ -n "$pathfull" ] && segs+=("${blue}${wticon} ${pathfull}${reset}")
segs+=("${cctx}${ctxbar}${reset} ${p}%")
if [ -n "$h5n" ]; then
u="⏳ ${c5}${h5n}%${reset}"; [ -n "$h5hm" ] && u="${u} ${dim}· reset ${h5hm}${reset}"
segs+=("$u")
fi
[ -n "$model" ] && segs+=("${magenta}${model}${reset}")
line=$(join_segs "$SEP" "${segs[@]}")
;;
duas-linhas | duas_linhas)
a=("πŸ“Œ ${bold}${name:-(sem nome)}${reset}")
[ -n "$branch" ] && a+=("🌿 ${branch}")
[ -n "$pathshort" ] && a+=("${wticon} ${pathshort}")
b=("${dim}↳${reset} ${cctx}${ctxbar}${reset} ${p}% ctx")
if [ -n "$h5n" ]; then
u="⏳ ${c5}${h5n}%${reset}"; [ -n "$h5hm" ] && u="${u} ${dim}· reset ${h5hm}${reset}"
b+=("$u")
fi
[ -n "$model" ] && b+=("${dim}${model}${reset}")
line="$(join_segs "$SEP" "${a[@]}")"$'\n'"$(join_segs "$SEP" "${b[@]}")"
;;
powerline)
A=$''
items=("πŸ“Œ ${name:-(sem nome)}"); bgs=(24)
[ -n "$pathshort" ] && { items+=("${wticon} ${pathshort}"); bgs+=(54); }
items+=("${ctxbar} ${p}%"); bgs+=(238)
if [ -n "$h5n" ]; then
u="⏳ ${h5n}%"; [ -n "$h5hm" ] && u="${u} · ${h5hm}"
items+=("$u"); bgs+=(240)
fi
prev=""
for i in "${!items[@]}"; do
bg=${bgs[i]}
if [ -z "$prev" ]; then
line+="${e}[48;5;${bg}m${e}[38;5;231m ${items[i]} ${reset}"
else
line+="${e}[38;5;${prev}m${e}[48;5;${bg}m${A}${e}[38;5;231m ${items[i]} ${reset}"
fi
prev=$bg
done
line+="${e}[38;5;${prev}m${A}${reset}"
;;
usage)
segs=("πŸ“Œ ${name:-(sem nome)}")
[ -n "$pathshort" ] && segs+=("${wticon} ${pathshort}")
segs+=("${dim}ctx${reset} ${cctx}${ctxbar}${reset} ${p}%")
if [ -n "$h5n" ]; then
u="⏳ ${c5}$(mkbar "$h5n")${reset} ${h5n}%"
[ -n "$h5hm" ] && u="${u} ${dim}Β· reset ${h5hm}${reset}"
segs+=("$u")
fi
line=$(join_segs "$SEP" "${segs[@]}")
;;
*) # adaptativo (padrΓ£o)
segs=("πŸ“Œ ${name:-(sem nome)}")
[ -n "$branch" ] && segs+=("🌿 ${branch}")
[ -n "$pathfull" ] && segs+=("${wticon} ${pathfull}")
segs+=("${cctx}${ctxbar}${reset} ${p}%")
if [ -n "$h5n" ]; then
u="⏳ ${c5}${h5n}%${reset}"; [ -n "$h5hm" ] && u="${u} ${dim}· reset ${h5hm}${reset}"
segs+=("$u")
fi
[ -n "$model" ] && segs+=("${dim}${model}${reset}")
line=$(join_segs "$SEP" "${segs[@]}")
;;
esac
# ConteΓΊdo + uma linha "vazia" abaixo para separar do indicador de modo/atalhos.
# O zero-width space (U+200B) nΓ£o Γ© removido pelo trim de espaΓ§os do Claude Code.
zwsp=$(printf '\xe2\x80\x8b')
printf '%s\n%s' "$line" "$zwsp"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment