惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

IT之家
IT之家
Y
Y Combinator Blog
月光博客
月光博客
Blog — PlanetScale
Blog — PlanetScale
GbyAI
GbyAI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
美团技术团队
雷峰网
雷峰网
酷 壳 – CoolShell
酷 壳 – CoolShell
Last Week in AI
Last Week in AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
有赞技术团队
有赞技术团队
博客园 - 司徒正美
V
Visual Studio Blog
小众软件
小众软件
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
Tailwind CSS Blog
Apple Machine Learning Research
Apple Machine Learning Research
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
A
About on SuperTechFans
The Cloudflare Blog

V2EX

我用 AI 写代码,但终端管理反而成了累赘——于是我做了 codux [调研] 各位在公司都用什么 ide 和 agent 写代码? 老运维 share 一个运维平台 看到有公司考核 token 指标,很好奇大家上个月的 AI 账单是多少 GLM-Coding 调用持续报错: z.ai 的 Lite 套餐几乎无法使用,官方 Pro/Max 是否稳定? 现在还有什么渠道可以稳定安全地使用 Claude 吗? 上海漕河泾内推,本组有 2 个 hc,一个后端,一个前端,预算都是 20k 左右,不打卡,氛围好 如果 V2EX 上有一组不永久保存聊天记录(比如只保存 7 天或者 24 小时)的聊天室,那么会开启哪些有用或者有趣的可能? gemini cli 貌似挂了,一直返回 403 第一次在自媒体上赚到钱 收集了最近在使用的低价 GPT, Gemini,邮箱等 AI 会员的小店合集 讨论个大实话:现在企业还在说 AI 编程提效 20%, 30%的,真的太落后,没用懂 AI。因为包括很多前沿公司,已经狂奔到提效 200%-500%的情况 [招聘][远程][币安] 前端/后端/QA/iOS/Android 至少 3 年以上经验 目前有大量 HC 欢迎投递 Chatgpt Pro 用量用不完的可以开这些设置 面试的时候好像遇到钓鱼了,给各位避个坑 cursor 年续费 22 号到期, 自动续费是否还是老的计次套餐呢 被两件破事毁掉的一下午,琐碎的内耗消磨人的精力 使用 Planet 存储 Codex 的会话或者重要信息 如果业务部门领导不要你开发功能,而是要求你教会它用 claude code 开发功能,你会怎么做? 分享一个 MacOS 接绿联 CM818 USB 转 DP 转接器使用感受 我的 HR 朋友 10 年老 Java ,非全大专,大家帮忙看看简历 开源了一个 AI 口语练习工具,音素级发音评分,完全免费可自部署 V2EX 上有哪些你觉得很有趣、印象深刻的妹纸? 字节为啥不出个国内版 Vercel? 有在大马的朋友吗? 问个运营商问题 你们在有领导的公司大群发过的最大胆的消息是什么 公司裁员,目前没有工作。想试试摆摊,做一个移动鲜啤打酒车 我的硬盘 Memblaze Pblaze 5 Linux 下不识别,给 Linux 内核提交了补丁, AI 说有望被合并 只有我一个人觉得 codex 不好用?
搓了个适用于 Claude Code + GLM 的 Status Line
zivn · 2026-04-09 · via V2EX

效果如图,没做其他适配,需要适配可以让 cc 继续搓,请先安装 Nerd Font 并作为终端字体😄

从左到右依次是:

  • 当前工作目录
  • 当前模型
  • 上下文窗口当前用量和上限(单位:K 、M )
  • 套餐 5 小时用量百分比和重置时间(时间:一小时内显示分钟 *m 、一天内显示小时 *h 、一天以上显示天数 *d )
  • 套餐周用量百分比和重置时间
  • 套餐月工具调用用量百分比和重置时间

GLM Status Line

  1. 在 ~/.cluade/settings.json 中添加配置:
{
  "statusLine": {
    "type": "command",
    "command": "~/.claude/statusline.sh",
    "padding": 0
  }
}
  1. 创建 ~/.claude/statusline.sh
#!/bin/bash

input=$(cat)

# Extract fields from stdin JSON
model=$(echo "$input" | jq -r '.model.id // "unknown"')
curr_dir=$(echo "$input" | jq -r '.workspace.current_dir // "~"')
curr_dir="${curr_dir/#$HOME/~}"
ctx_pct=$(echo "$input" | jq -r '.context_window.used_percentage // 0')
ctx_int=$(echo "$ctx_pct" | awk '{if ($1 <= 1) printf "%.0f", $1*100; else printf "%.0f", $1}')
# Calculate context total
ctx_total=$(echo "$input" | jq -r '.context_window.context_window_size // 0' 2>/dev/null)
ctx_total=${ctx_total:-0}
# Format context total as xk or xm
if (( ctx_total >= 1000000 )); then
  ctx_total_str="$(( (ctx_total + 50000) / 100000 ))M"
elif (( ctx_total >= 1000 )); then
  ctx_total_str="$(( (ctx_total + 500) / 1000 ))K"
else
  ctx_total_str="${ctx_total}"
fi

# Cache + API call for usage data
cache_file="/tmp/.claude-statusline-usage-cache"
cache_ttl=60
now=$(date +%s)
api_body=""

if [[ -f "$cache_file" ]]; then
  cache_time=$(head -1 "$cache_file")
  if (( now - cache_time < cache_ttl )); then
    api_body=$(tail -n +2 "$cache_file")
  fi
fi

if [[ -z "$api_body" ]]; then
  base_url=$(echo "$ANTHROPIC_BASE_URL" | sed -E 's|^( https?://[^/]+).*|\1|')
  quota_url="${base_url}/api/monitor/usage/quota/limit"
  api_body=$(curl -sf --max-time 5 \
    -H "Authorization: ${ANTHROPIC_AUTH_TOKEN}" \
    -H "Content-Type: application/json" \
    "$quota_url" 2>/dev/null)
  if [[ -n "$api_body" ]]; then
    printf '%s\n%s' "$now" "$api_body" > "$cache_file"
  elif [[ -f "$cache_file" ]]; then
    api_body=$(tail -n +2 "$cache_file")
  fi
fi

# Extract usage percentages
usage_5h=0
usage_weekly=0
tool_usage=0
if [[ -n "$api_body" ]]; then
  usage_5h=$(echo "$api_body" | jq -r '[.data.limits[] | select(.type=="TOKENS_LIMIT" and .unit==3)][0].percentage // 0' 2>/dev/null)
  usage_weekly=$(echo "$api_body" | jq -r '[.data.limits[] | select(.type=="TOKENS_LIMIT" and .unit==6)][0].percentage // 0' 2>/dev/null)
  tool_usage=$(echo "$api_body" | jq -r '[.data.limits[] | select(.type=="TIME_LIMIT")][0].percentage // 0' 2>/dev/null)
  reset_5h=$(echo "$api_body" | jq -r '[.data.limits[] | select(.type=="TOKENS_LIMIT" and .unit==3)][0].nextResetTime // 0' 2>/dev/null)
  reset_weekly=$(echo "$api_body" | jq -r '[.data.limits[] | select(.type=="TOKENS_LIMIT" and .unit==6)][0].nextResetTime // 0' 2>/dev/null)
  reset_tool=$(echo "$api_body" | jq -r '[.data.limits[] | select(.type=="TIME_LIMIT")][0].nextResetTime // 0' 2>/dev/null)
fi
usage_5h_int=$(printf '%.0f' "$usage_5h")
usage_weekly_int=$(printf '%.0f' "$usage_weekly")
tool_usage_int=$(printf '%.0f' "$tool_usage")

# Calculate time until reset, format as xd, xh or xm
now_ms=$(( now * 1000 ))
format_reset() {
  local diff=$(( ($1 - now_ms) / 1000 ))
  (( diff < 0 )) && diff=0
  if (( diff >= 86400 )); then
    printf '%dd' $(( (diff + 43200) / 86400 ))
  elif (( diff >= 3600 )); then
    printf '%dh' $(( (diff + 1800) / 3600 ))
  else
    printf '%dm' $(( (diff + 30) / 60 ))
  fi
}
reset_5h_str=$(format_reset "$reset_5h")
reset_weekly_str=$(format_reset "$reset_weekly")
reset_tool_str=$(format_reset "$reset_tool")

# Progress bar: outputs bar then restores badge context colors
make_bar() {
  local pct=$1 width=6 ctx="$2"
  local filled empty i filled_str="" empty_str=""
  filled=$(( (pct * width + 50) / 100 ))
  (( filled > width )) && filled=$width
  (( filled < 0 )) && filled=0
  empty=$(( width - filled ))
  for ((i=0; i<filled; i++)); do filled_str+="█"; done
  for ((i=0; i<empty; i++)); do empty_str+="░"; done
  printf '\033[32m%s\033[0m\033[2;32m%s\033[0m%b' "$filled_str" "$empty_str" "$ctx"
}

# Badge style
BGC=24
BG="\033[48;5;${BGC}m"
FG='\033[38;5;252m'
CTX="${BG}${FG}"
RST='\033[0m'

# Powerline rounded caps (UTF-8 bytes)
LEFT=$(printf '\xee\x82\xb6')   # U+E0B6
RIGHT=$(printf '\xee\x82\xb4')  # U+E0B4

# Nerd Font icons (UTF-8 bytes)
I_DIR=$(printf '\xef\x81\xbb')    # U+F07B Folder
I_MODEL=$(printf '\xef\x8b\x9b')  # U+F2DB Microchip
I_CTX=$(printf '\xf3\xb1\x94\x98')  # Context icon
I_5H=$(printf '\xef\x80\x97')     # U+F017 Clock
I_WEEK=$(printf '\xef\x81\xb3')   # U+F073 Calendar
I_TOOL=$(printf '\xef\x82\xad')   # U+F0AD Wrench

# Output - each badge: LEFT_CAP[icon]content RIGHT_CAP space
# Folder
printf "\033[38;5;${BGC}m%s${CTX}%s %s" "$LEFT" "$I_DIR" "$curr_dir"
printf "\033[38;5;${BGC}m\033[49m%s${RST} " "$RIGHT"

# Model (bold green name)
printf "\033[38;5;${BGC}m%s${CTX}%s \033[1;32m%s" "$LEFT" "$I_MODEL" "$model"
printf "\033[22m\033[38;5;${BGC}m\033[49m%s${RST} " "$RIGHT"

# Context
printf "\033[38;5;${BGC}m%s${CTX}%s " "$LEFT" "$I_CTX"
make_bar "$ctx_int" "$CTX"
printf " %d%% %s\033[38;5;${BGC}m\033[49m%s${RST} " "$ctx_int" "$ctx_total_str" "$RIGHT"

# 5h usage
printf "\033[38;5;${BGC}m%s${CTX}%s " "$LEFT" "$I_5H"
make_bar "$usage_5h_int" "$CTX"
printf " %d%% %s\033[38;5;${BGC}m\033[49m%s${RST} " "$usage_5h_int" "$reset_5h_str" "$RIGHT"

# Weekly usage
printf "\033[38;5;${BGC}m%s${CTX}%s " "$LEFT" "$I_WEEK"
make_bar "$usage_weekly_int" "$CTX"
printf " %d%% %s\033[38;5;${BGC}m\033[49m%s${RST} " "$usage_weekly_int" "$reset_weekly_str" "$RIGHT"

# Tool usage
printf "\033[38;5;${BGC}m%s${CTX}%s " "$LEFT" "$I_TOOL"
make_bar "$tool_usage_int" "$CTX"
printf " %d%% %s\033[38;5;${BGC}m\033[49m%s${RST}\n" "$tool_usage_int" "$reset_tool_str" "$RIGHT"