Skip to content

Instantly share code, notes, and snippets.

@hashmaparraylist
Created May 19, 2026 15:52
Show Gist options
  • Select an option

  • Save hashmaparraylist/abcdaba458d50919945cf9926f1c189d to your computer and use it in GitHub Desktop.

Select an option

Save hashmaparraylist/abcdaba458d50919945cf9926f1c189d to your computer and use it in GitHub Desktop.
Claude Code Status Line
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$stdin = [System.Console]::OpenStandardInput()
$reader = [System.IO.StreamReader]::new($stdin)
$raw = $reader.ReadToEnd()
$reader.Dispose()
if ([string]::IsNullOrEmpty($raw)) {
Write-Output "Claude Code"
exit 0
}
# ่งฃๆž JSON
$d = $null
try {
$d = $raw | ConvertFrom-Json -ErrorAction Stop
} catch {
$d = $null
}
# ้ขœ่‰ฒๅฎšไน‰
<equation>r = "</equation>([char]27)[0m"
function C(<equation>c) { "</equation>([char]27)[$c" }
$CR = C("1;31m") # ็บข่‰ฒ
$CG = C("1;32m") # ็ปฟ่‰ฒ
$CY = C("1;33m") # ้ป„่‰ฒ
$CC = C("1;36m") # ้’่‰ฒ
$CM = C("1;35m") # ๆด‹็บข
$CW = C("1;37m") # ็™ฝ่‰ฒ
$CD = C("2m") # ็ฐ่‰ฒ
# ๆ•ฐๅญ—ๆ ผๅผๅŒ–
function Fmt($n) {
if ($null -eq $n) { return "0" }
if (<equation>n -ge 1000000) { return "</equation>([math]::Round($n / 1000000, 1))M" }
elseif (<equation>n -ge 1000) { return "</equation>([math]::Round($n / 1000))K" }
else { return "$n" }
}
# ๅฎ‰ๅ…จๅฑžๆ€ง่ฎฟ้—ฎ
function Get-Prop($obj, $prop) {
if ($null -eq $obj) { return $null }
if ($obj -is [hashtable]) { return $obj[$prop] }
return $obj.$prop
}
# ========== LINE 1: ๆจกๅž‹/ๆ—ถ้—ด/ไผš่ฏ ==========
$l1 = @()
if ($d) {
$modelName = Get-Prop $d "model"
if ($modelName) {
$mn = if ($modelName -is [hashtable]) { $modelName["display_name"] } else { $modelName.display_name }
if ($mn) { $l1 += "$CC$mn$r" }
}
}
$l1 += "<equation>CY</equation>(Get-Date -Format 'HH:mm')$r"
$sessionName = Get-Prop $d "session_name"
if ($sessionName) { $l1 += "$CM[$sessionName]$r" }
$agent = Get-Prop $d "agent"
if ($agent) {
$an = if ($agent -is [hashtable]) { $agent["name"] } else { $agent.name }
$at = if ($agent -is [hashtable]) { $agent["type"] } else { $agent.type }
if ($at) { $at = ":$at" } else { $at = "" }
if ($an) { $l1 += "$CG Agent:$an$at$r" }
}
$effort = Get-Prop $d "effort"
if ($effort) {
$el = if ($effort -is [hashtable]) { $effort["level"] } else { $effort.level }
if ($el) { <equation>l1 += "</equation>([char]27)[1;34m Effort:$el$r" }
}
$thinking = Get-Prop $d "thinking"
if ($thinking) {
$te = if ($thinking -is [hashtable]) { $thinking["enabled"] } else { $thinking.enabled }
if ($te) { $l1 += "$CY Thinking$r" }
}
# ========== LINE 2: ๅทฅไฝœ็›ฎๅฝ• ==========
$l2 = @()
$workspace = Get-Prop $d "workspace"
if ($workspace) {
$cwd = if ($workspace -is [hashtable]) { $workspace["current_dir"] } else { $workspace.current_dir }
if ($cwd) {
# ๆ›ฟๆขไธญๆ–‡็”จๆˆทๅไธบ่‹ฑๆ–‡
$cnName = ([char]0x738B) + ([char]0x4EAE)
$dispCwd = $cwd.Replace($cnName, 'Alan')
$l2 += "$CW$dispCwd$r"
}
if ($cwd) {
$branch = git -c core.quotepath=false -C "$cwd" rev-parse --abbrev-ref HEAD 2>$null
if ($branch) { $l2 += "$CG($branch)$r" }
}
}
# ========== LINE 3: ไธŠไธ‹ๆ–‡่ฟ›ๅบฆๆก ==========
$l3 = @()
$contextWindow = Get-Prop $d "context_window"
if ($contextWindow) {
$used = Get-Prop $contextWindow "used_percentage"
$rem = Get-Prop $contextWindow "remaining_percentage"
$size = Get-Prop $contextWindow "context_window_size"
$tIn = Get-Prop $contextWindow "total_input_tokens"
$tOut = Get-Prop $contextWindow "total_output_tokens"
if ($null -eq $used -and $null -ne $rem) { $used = 100 - $rem }
if ($null -eq $rem -and $null -ne $used) { $rem = 100 - $used }
if ($null -eq $used) { $used = 0 }
if ($null -eq $rem) { $rem = 0 }
if ($used -eq 0 -and $rem -eq 0) { $rem = 100 }
$used = [math]::Round($used)
$rem = [math]::Round($rem)
# Unicode ๆ–นๅ—่ฟ›ๅบฆๆก
$barW = 15
$uChars = [math]::Floor($used / 100 * $barW)
if ($uChars -lt 0) { $uChars = 0 }
if ($uChars -gt $barW) { $uChars = $barW }
$rChars = $barW - $uChars
$filledBlock = [string][char]0x2588
$emptyBlock = [string][char]0x2591
$filled = "$CG" + ($filledBlock * $uChars)
$empty = "$CD" + ($emptyBlock * $rChars)
$bar = "[$filled$empty$r]"
$l3 += "$CW[CTX]$r $bar <equation>CG</equation>{used}%$r <equation>CD</equation>{rem}%$r"
if ($size) { $l3 += "<equation>CC Size:</equation>(Fmt $size)$r" }
if ($tIn -or $tOut) {
$l3 += "<equation>CY In:</equation>(Fmt <equation>tIn) Out:</equation>(Fmt $tOut)$r"
}
}
# Rate limits
$rateLimits = Get-Prop $d "rate_limits"
if ($rateLimits) {
$rp = @()
$fiveHr = if ($rateLimits -is [hashtable]) { $rateLimits["five_hour"] } else { $rateLimits.five_hour }
$sevenDay = if ($rateLimits -is [hashtable]) { $rateLimits["seven_day"] } else { $rateLimits.seven_day }
if ($fiveHr) {
$v = if ($fiveHr -is [hashtable]) { $fiveHr["used_percentage"] } else { $fiveHr.used_percentage }
if ($v) {
$v = [math]::Round($v)
$c = if ($v -gt 80) { $CR } elseif ($v -gt 50) { $CY } else { $CG }
$rp += "<equation>c 5h:</equation>{v}%$r"
}
}
if ($sevenDay) {
$v = if ($sevenDay -is [hashtable]) { $sevenDay["used_percentage"] } else { $sevenDay.used_percentage }
if ($v) {
$v = [math]::Round($v)
$c = if ($v -gt 80) { $CR } elseif ($v -gt 50) { $CY } else { $CG }
$rp += "<equation>c 7d:</equation>{v}%$r"
}
}
if ($rp.Count -gt 0) {
$l3 += "$CW RL:$r $($rp -join ' ')"
}
}
# ========== LINE 4: ๅฝ“ๅ‰่ฏทๆฑ‚็”จ้‡ ==========
$l4 = @()
$contextWindow = Get-Prop $d "context_window"
if ($contextWindow) {
$currentUsage = if ($contextWindow -is [hashtable]) { $contextWindow["current_usage"] } else { $contextWindow.current_usage }
if ($currentUsage) {
$inTok = Get-Prop $currentUsage "input_tokens"
$outTok = Get-Prop $currentUsage "output_tokens"
$cacheCreate = Get-Prop $currentUsage "cache_creation_input_tokens"
$cacheRead = Get-Prop $currentUsage "cache_read_input_tokens"
if ($currentUsage) {
<equation>l4 += "</equation>{CW}Usage:$r"
<equation>l4 += "</equation>{CY}In:$(Fmt $inTok)$r"
<equation>l4 += "</equation>{CG}Out:$(Fmt $outTok)$r"
<equation>l4 += "</equation>{CC}Crt:$(Fmt $cacheCreate)$r"
<equation>l4 += "</equation>{CM}Rd:$(Fmt $cacheRead)$r"
}
}
}
# ========== OUTPUT ==========
[System.Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$out = @()
if ($l1.Count -gt 0) { $out += ($l1 -join " | ") }
if ($l2.Count -gt 0) { $out += ($l2 -join " ") }
if ($l3.Count -gt 0) { $out += ($l3 -join " | ") }
if ($l4.Count -gt 0) { $out += ($l4 -join " ") }
if ($out.Count -gt 0) {
$final = $out -join "`n"
Write-Output $final
} else {
Write-Output "Claude Code"
}
#!/bin/bash
set -e
# ========== ANSI Colors ==========
R=$'\e[0m'
CR=$'\e[1;31m'
CG=$'\e[1;32m'
CY=$'\e[1;33m'
CC=$'\e[1;36m'
CM=$'\e[1;35m'
CW=$'\e[1;37m'
CD=$'\e[2m'
# ========== Read stdin ==========
raw=$(cat)
if [[ -z "$raw" ]]; then
echo "Claude Code"
exit 0
fi
# ========== Array join helper ==========
join_with() {
local IFS="$1"; shift
local first=1
for item in "$@"; do
[[ $first -eq 1 ]] && first=0 || echo -n "$IFS"
echo -n "$item"
done
echo
}
# ========== Number formatter: 0, N.xM, NK ==========
fmt() {
local n="$1"
if [[ -z "$n" ]] || [[ "$n" == "null" ]]; then
echo "0"
return
fi
# Round to integer
n=$(printf "%.0f" "$n" 2>/dev/null || echo "$n")
if [[ "$n" -ge 1000000 ]]; then
# Use awk for float division (portable, no bc needed)
printf "%.1fM" "$(awk "BEGIN {printf \"%.1f\", $n/1000000}")"
elif [[ "$n" -ge 1000 ]]; then
printf "%.0fK" "$(awk "BEGIN {printf \"%.0f\", $n/1000}")"
else
echo "$n"
fi
}
# ========== LINE 1 ==========
l1_parts=()
# Model display name
model_obj=$(echo "$raw" | jq -r '.model // null')
if [[ "$model_obj" != "null" ]] && [[ -n "$model_obj" ]]; then
mn=$(echo "$model_obj" | jq -r '.display_name // empty')
if [[ -n "$mn" ]] && [[ "$mn" != "null" ]]; then
l1_parts+=("${CC}${mn}${R}")
fi
fi
# Time
l1_parts+=("${CY}$(date +%H:%M)${R}")
# Session name
sn=$(echo "$raw" | jq -r '.session_name // empty')
if [[ -n "$sn" ]] && [[ "$sn" != "null" ]]; then
l1_parts+=("${CM}[${sn}]${R}")
fi
# Agent
agent_obj=$(echo "$raw" | jq -r '.agent // null')
if [[ "$agent_obj" != "null" ]] && [[ -n "$agent_obj" ]]; then
an=$(echo "$agent_obj" | jq -r '.name // empty')
at=$(echo "$agent_obj" | jq -r '.type // empty')
if [[ -n "$an" ]] && [[ "$an" != "null" ]]; then
[[ -n "$at" ]] && at=":${at}" || at=""
l1_parts+=("${CG} Agent:${an}${at}${R}")
fi
fi
# Effort
effort_obj=$(echo "$raw" | jq -r '.effort // null')
if [[ "$effort_obj" != "null" ]] && [[ -n "$effort_obj" ]]; then
el=$(echo "$effort_obj" | jq -r '.level // empty')
if [[ -n "$el" ]] && [[ "$el" != "null" ]]; then
l1_parts+=("\e[1;34m Effort:${el}${R}")
fi
fi
# Thinking
thinking_obj=$(echo "$raw" | jq -r '.thinking // null')
if [[ "$thinking_obj" != "null" ]] && [[ -n "$thinking_obj" ]]; then
te=$(echo "$thinking_obj" | jq -r '.enabled // empty')
if [[ "$te" == "true" ]]; then
l1_parts+=("${CY} Thinking${R}")
fi
fi
# Version
ver=$(echo "$raw" | jq -r '.version // empty')
if [[ -n "$ver" ]] && [[ "$ver" != "null" ]]; then
l1_parts+=("${CD}[${ver}]${R}")
fi
# Join L1 with " | "
#l1=$(IFS=" | "; echo "${l1_parts[*]}")
l1=$(join_with " | " "${l1_parts[@]}")
# ========== LINE 2 ==========
l2_parts=()
workspace_obj=$(echo "$raw" | jq -r '.workspace // null')
if [[ "$workspace_obj" != "null" ]] && [[ -n "$workspace_obj" ]]; then
cwd=$(echo "$workspace_obj" | jq -r '.current_dir // empty')
if [[ -n "$cwd" ]] && [[ "$cwd" != "null" ]]; then
# Replace Chinese username ็Ž‹ไบฎ (U+738B=0xE7 0x8E 0x8B, U+4EAE=0xE4 0xBA 0xAE) with Alan
#disp_cwd=$(echo "$cwd" | sed 's/\xE7\x8E\x8B\xE4\xBA\xAE/Alan/g')
l2_parts+=("๐Ÿ“ ${CW}${cwd##*/}${R}")
#branch=$(git -C "$cwd" rev-parse --abbrev-ref HEAD 2>/dev/null || echo "")
BRANCH=""
git rev-parse --git-dir > /dev/null 2>&1 && BRANCH="๐ŸŒฟ $(git branch --show-current 2>/dev/null)"
if [[ -n "$BRANCH" ]]; then
l2_parts+=("${CG}(${BRANCH})${R}")
fi
fi
fi
# Join L2 with " " (space)
#l2=$(IFS=" "; echo "${l2_parts[*]}")
l2=$(join_with " " "${l2_parts[@]}")
# ========== LINE 3 ==========
l3_parts=()
context_obj=$(echo "$raw" | jq -r '.context_window // null')
if [[ "$context_obj" != "null" ]] && [[ -n "$context_obj" ]]; then
used=$(echo "$context_obj" | jq -r '.used_percentage // empty')
rem=$(echo "$context_obj" | jq -r '.remaining_percentage // empty')
size=$(echo "$context_obj" | jq -r '.context_window_size // empty')
t_in=$(echo "$context_obj" | jq -r '.total_input_tokens // empty')
t_out=$(echo "$context_obj" | jq -r '.total_output_tokens // empty')
#PCT=$(echo "$context_obj" | jq -r '.used_percentage // 0' | cut -d. -f1)
# Derive used from remaining if not set
if [[ -z "$used" ]] && [[ -n "$rem" ]] && [[ "$rem" != "null" ]]; then
used=$(awk "BEGIN {print 100 - $rem}")
elif [[ -z "$rem" ]] && [[ -n "$used" ]] && [[ "$used" != "null" ]]; then
rem=$(awk "BEGIN {print 100 - $used}")
fi
[[ -z "$used" ]] || [[ "$used" == "null" ]] && used=0
[[ -z "$rem" ]] || [[ "$rem" == "null" ]] && rem=0
if [[ $(awk "BEGIN {print ($used == 0 && $rem == 0)}") -eq 1 ]]; then
rem=100
fi
used_i=$(awk "BEGIN {printf \"%.0f\", $used}")
rem_i=$(awk "BEGIN {printf \"%.0f\", $rem}")
# Unicode block progress bar
bar_w=15
u_chars=$((used_i * bar_w / 100))
[[ $u_chars -lt 0 ]] && u_chars=0
[[ $u_chars -gt $bar_w ]] && u_chars=$bar_w
r_chars=$((bar_w - u_chars))
# \xe2\x96\x88 = โ–ˆ (U+2588), \xe2\x96\x91 = โ–‘ (U+2591)
#filled=$(printf "%${u_chars}s" | tr ' ' 'โ–ˆ')
#empty=$(printf "%${r_chars}s" | tr ' ' 'โ–‘')
filled=$((used / bar_w)); empty=$((bar_w - filled))
printf -v FILL "%${filled}s"; printf -v PAD "%${empty}s"
#bar="[${CG}${filled}${CD}${empty}${R}]"
bar="[${CG}${FILL// /โ–ˆ}${CD}${PAD// /โ–‘}${R}]"
l3_parts+=("${CW}[CTX]${R} ${bar} ${CG}${used_i}%${R} ${CD}${rem_i}%${R}")
if [[ -n "$size" ]] && [[ "$size" != "null" ]]; then
l3_parts+=("${CC}Size:$(fmt "$size")${R}")
fi
if [[ -n "$t_in" ]] || [[ -n "$t_out" ]]; then
l3_parts+=("${CY}In:$(fmt "$t_in") Out:$(fmt "$t_out")${R}")
fi
fi
# Rate limits
rate_obj=$(echo "$raw" | jq -r '.rate_limits // null')
if [[ "$rate_obj" != "null" ]] && [[ -n "$rate_obj" ]]; then
rl_extra=""
five_hr=$(echo "$rate_obj" | jq -r '.five_hour // null')
if [[ "$five_hr" != "null" ]] && [[ -n "$five_hr" ]]; then
v=$(echo "$five_hr" | jq -r '.used_percentage // empty')
if [[ -n "$v" ]] && [[ "$v" != "null" ]]; then
v_i=$(awk "BEGIN {printf \"%.0f\", $v}")
if [[ "$v_i" -gt 80 ]]; then
rl_color="$CR"
elif [[ "$v_i" -gt 50 ]]; then
rl_color="$CY"
else
rl_color="$CG"
fi
rl_extra="${rl_extra} ${rl_color}5h:${v_i}%${R}"
fi
fi
seven_day=$(echo "$rate_obj" | jq -r '.seven_day // null')
if [[ "$seven_day" != "null" ]] && [[ -n "$seven_day" ]]; then
v=$(echo "$seven_day" | jq -r '.used_percentage // empty')
if [[ -n "$v" ]] && [[ "$v" != "null" ]]; then
v_i=$(awk "BEGIN {printf \"%.0f\", $v}")
if [[ "$v_i" -gt 80 ]]; then
rl_color="$CR"
elif [[ "$v_i" -gt 50 ]]; then
rl_color="$CY"
else
rl_color="$CG"
fi
rl_extra="${rl_extra} ${rl_color}7d:${v_i}%${R}"
fi
fi
if [[ -n "$rl_extra" ]]; then
l3_parts+=("${CW} RL:${R}${rl_extra}")
fi
fi
# Join L3 with " | "
#l3=$(IFS=" | "; echo "${l3_parts[*]}")
l3=$(join_with " | " "${l3_parts[@]}")
# ========== LINE 4 ==========
l4_parts=()
context_obj=$(echo "$raw" | jq -r '.context_window // null')
if [[ "$context_obj" != "null" ]] && [[ -n "$context_obj" ]]; then
curr_usage=$(echo "$context_obj" | jq -r '.current_usage // null')
if [[ "$curr_usage" != "null" ]] && [[ -n "$curr_usage" ]]; then
in_tok=$(echo "$curr_usage" | jq -r '.input_tokens // empty')
out_tok=$(echo "$curr_usage" | jq -r '.output_tokens // empty')
cache_create=$(echo "$curr_usage" | jq -r '.cache_creation_input_tokens // empty')
cache_read=$(echo "$curr_usage" | jq -r '.cache_read_input_tokens // empty')
l4_parts+=("${CW}Usage:${R}")
l4_parts+=("${CY}In:$(fmt "$in_tok")${R}")
l4_parts+=("${CG}Out:$(fmt "$out_tok")${R}")
l4_parts+=("${CC}Crt:$(fmt "$cache_create")${R}")
l4_parts+=("${CM}Rd:$(fmt "$cache_read")${R}")
fi
fi
# Join L4 with " " (space)
#l4=$(IFS=" "; echo "${l4_parts[*]}")
l4=$(join_with " " "${l4_parts[@]}")
# ========== OUTPUT ==========
output=""
[[ -n "$l1" ]] && output="$l1"
[[ -n "$l2" ]] && output="${output}"$'\n'"$l2"
[[ -n "$l3" ]] && output="${output}"$'\n'"$l3"
[[ -n "$l4" ]] && output="${output}"$'\n'"$l4"
if [[ -n "$output" ]]; then
echo -e "$output"
else
echo "Claude Code"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment