Skip to content

Instantly share code, notes, and snippets.

@xavierskip
Created April 10, 2026 09:07
Show Gist options
  • Select an option

  • Save xavierskip/4cbfc8557d9ed33a4ca36600c3e2f85f to your computer and use it in GitHub Desktop.

Select an option

Save xavierskip/4cbfc8557d9ed33a4ca36600c3e2f85f to your computer and use it in GitHub Desktop.
claude code /statusline multi-line status line powershell script
#!/usr/bin/env pwsh
<#
"statusLine": {
"type": "command",
"command": "pwsh -NoProfile -File ~/.claude/statuslines.ps1"
}
#>
# Set UTF-8 output encoding to properly display Unicode characters
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$PSDefaultParameterValues['Out-File:Encoding'] = 'utf8'
$input_data = $input | ConvertFrom-Json
$MODEL = $input_data.model.display_name
$DIR = $input_data.workspace.current_dir
$COST = if ($input_data.cost.total_cost_usd) { $input_data.cost.total_cost_usd } else { 0 }
$PCT = if ($input_data.context_window.used_percentage) { [int]$input_data.context_window.used_percentage } else { 0 }
$DURATION_MS = if ($input_data.cost.total_duration_ms) { $input_data.cost.total_duration_ms } else { 0 }
# ANSI 颜色
$CYAN = "`e[36m"
$GREEN = "`e[32m"
$YELLOW = "`e[33m"
$RED = "`e[31m"
$RESET = "`e[0m"
# 根据上下文使用率选择颜色
$BAR_COLOR = if ($PCT -ge 90) { $RED }
elseif ($PCT -ge 70) { $YELLOW }
else { $GREEN }
# 进度条
$FILLED = [int]($PCT / 10)
$EMPTY = 10 - $FILLED
$BAR = ("█" * $FILLED) + ("░" * $EMPTY)
# 时间格式化
$MINS = [int]($DURATION_MS / 60000)
$SECS = [int](($DURATION_MS % 60000) / 1000)
# Git 分支
$BRANCH = ""
try {
git rev-parse --git-dir 2>$null | Out-Null
if ($LASTEXITCODE -eq 0) {
$GIT_BRANCH = git branch --show-current 2>$null
if ($GIT_BRANCH) { $BRANCH = " | 🌿 $GIT_BRANCH" }
}
} catch {}
# 目录名(取最后一段)
$DIR_NAME = Split-Path $DIR -Leaf
# 费用格式化
$COST_FMT = "`$" + ("{0:F2}" -f [double]$COST)
# 输出
Write-Host "${CYAN}[$MODEL]${RESET} 📁 ${DIR_NAME}${BRANCH}"
Write-Host "${BAR_COLOR}${BAR}${RESET} ${PCT}% | ${YELLOW}${COST_FMT}${RESET} | ⏱️ ${MINS}m ${SECS}s"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment