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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

DEV Community

93 Agents. 2.6 Billion Tokens. One Working OS. And a Bill Under $1,000. Stop Getting 'It Depends' Answers About RAG Architecture Wrapping Hermes Agent with agent-stack: six tiny libs for the boring parts Templating got me to 33,620 pages. Indexing them was the hard part. EML Attachments Not Opening? Here’s How to Fix the Issue Easily in 2026 WordPress client onboarding: the exact process I use to start every maintenance contract right Models shouldn't have execution authority. Why we built a deterministic FSM runtime for AI agents. AI makes building faster, but semantic distribution is now the hard part How I Created My First Solana Token from Scratch (SPL Token Basics Explained) How I use WP-CLI to cut WordPress maintenance time from 6 hours to 20 minutes What Is Vibe Coding? And Does It Actually Work for Production Code? (I Tested 10 Tools) WordPress staging environments: the 15-minute setup that prevents client emergencies Reading Log #2 — Sapiens Imagined Communities: An Organization Is Made of Shared Fiction I Built a Branded Token on Solana in 5 Minutes (No Smart Contract Needed) The Confidence Gap: How AI Introduces Silent Errors on Production Sites Day 7 - Dense Embedding - RAG Why teachers need explainable AI, not just accurate AI — building the KC dashboard Closing the feedback loop: how mistake classification drives adaptive problem selection in NumPath Amazon Quick: AWS's Agentic Workspace, Explained for Engineers "My Coding Agent Remembered Sessions, Not Work. That Was the Bug" Reading Log #0 — Manga Was a Democratization Device for Cultural Capital SecOps Salary Guide 2025: GRC CTC Ranges in Indian GCCs vs Product Companies 🐍 python global vs nonlocal keyword — when to use each? 6 Free Online Video Cutters That Don’t Completely Ruin Your Footage (2026) Engineering Around Bitcoin's Traditional Platform Lockdowns AI 2026 ⚖️ Case File 4.1: The Efficiency Extortion Client-Side AI: The Next Era of Consumer E-Commerce? Why I'm building an AI math tutor for dyscalculia — and grounding it in 30 years of ITS research "My DingTalk Coding Bot Said It Started the Task. Then It Never Sent the Result" Your trycatch sucks - lets fix it I Built a Globally Distributed Blog Platform for ~$1/Month Awesome-Claude-Skills I built 135 Claude Skills with real formulas. Here's what "production-grade" actually means. How I engineered a Non-Euclidean AI framework for massive data reduction Automated 25 Minutes of My Morning With a Prompt (Not a Script) أدوات API ذاتية الاستضافة: هل يجب أن تترك السحابة؟ Never Use Service Classes in Rails How Markus Builds AI Teams That Actually Ship — Not Just Chat Pricing logic feels boring until it's wrong. Software Engineer Skills Companies Want in 2026: 48K-Posting Analysis Data Races Reproduced: Harnesses That Catch Heisenbugs Demystifying AI Agents: Building an Agentic Pipeline From Scratch in Pure Python Coding Agents Are Becoming Remote Workers. Enterprises Need an Agent Harness. How I Let an AI Refactor My Whole Codebase (Using Gemini 3.5) Flutter 3.44 Highlights From Google I/O 2026: What's New and What Matters The Hidden Cleanup Cost Behind AI Coding Velocity Promises A beginner's guide to the Image-Background-Remove model by Zf-Kbot on Replicate A beginner's guide to the Invsr model by Zf-Kbot on Replicate How to Automate Canadian T4 Slip Parsing with an API (No OCR Setup Required) حماية مفاتيح API من إضافة VS Code ضارة Agetor Review: An Open-Source Kanban Board for Orchestrating Claude Code Why most Marketo audits start at the wrong layer RevOps alignment is an operating-model problem, not a tooling problem Why Some Developers Are Moving Away From Tailwind CSS in 2026 API 키 보호: 악성 VS 코드 확장으로부터 안전하게 VS Code拡張機能によるAPIキー漏洩を防ぐ方法 Temporal Cloud Serverless: Durable Execution Without the Ops Overhead Why Freshers Must Build Real AI Products Instead of Endless App Clones I Built a Dynamic llms.txt for Next.js. Then Google Said Don't Bother. AWS Summit Seoul 2026: Korean Enterprises And Agentic AI Does AI Know How Many Tokens It Is Burning Selling Software in Countries PayPal Can't Reach - A Cautionary Tale of Crypto and Custom Solutions My Old MacBook Air Couldn't Handle It — So I Used Google Colab to Train an AI#1 The Discord.js gotchas that cost me a week each (so they don't have to cost you one) Leetcode QOTD:- 3043. Find the Length of the Longest Common Prefix MPT DEX Performance Test Report I shipped a working landing page in 14 KB. Here is every byte. Zero-Secret CI/CD: GitHub Actions + OIDC on AWS (Part 6) Building the React Frontend: Document Library and Chat UI (Part 5) Runtime Governance Evidence Anchors in 2026: A Public Ledger for Budget and Accountability Decisions RAG and Vector Search with pgvector and Amazon Bedrock (Part 4) Serverless Document Pipelines with AWS Step Functions (Part 3) Multi-Tenant Auth with Cognito and PostgreSQL Row-Level Security (Part 2) Building a Multi-Tenant AI Document Platform on AWS (Part 1: Architecture) Building a Nutrition Calculator in JavaScript: filter, map, and reduce on Objects Shipping an MCP server: parallel search, JSON output, and what broke along the way Runtime Governance Evidence Anchors in 2026: A Public Ledger for Budget and Accountability Decisions A 3-step agent cost me $4.20. agenttrace showed me the O(n ) tool call hiding in plain sight. Beyond WebView: The Next Evolution of Hybrid App Architecture Our retry loop made an outage worse. The circuit breaker stopped the cascade. Claude returned ```json blocks 14% of the time. Here is the Rust crate I wish I had earlier. I burned my Anthropic org cap and waited 3 days. Then I built llmfleet. One Open Source Project a Day (No. 71): CodeGraph — Pre-Index Your Codebase for AI Agents, Save 35% Cost and 70% Tool Calls The prompt your SDK sends is not the prompt you wrote The Context Tax: Why Every Cursor Session Costs You 15 Minutes Prompt Physics: Building a Cognitive Steering Layer for Gemma 4 Pain Points Will Always Outlive Platforms 92. BERT: The Model That Reads in Both Directions QAOA vs. 75,000 Nodes: Building a Hybrid Architecture to Solve NP-Hard Problems When Quantum Simulators Hit a Wall E2B? E4B? 26B A4B? The Gemma 4 Model Names Finally Explained One Tool That Cuts Token Costs 40-80% for Claude Code, Codex, opencode, and openclaw Building a 32-URL economy microsite on top of a 754,000-row SQLite dataset Coordinating 100+ AI Agents in the Field: Practical Patterns for Robotic Swarms Static site search for Astro in 2026: why I picked Pagefind over Algolia and Lunr How I built pairwise AI model compare pages with Claude Haiku and a budget cap Three post-deploy checks I run after every Cloudflare Pages build Why I'm betting on AI-curated directories when Google AI Overviews answer the same queries When boto3 doesn't have it (yet), you write it: a realtime speech-to-speech story in Python Zero-Trust RAG: Defeating the Shared Private Link Deadlock in Azure Terraform You Can't Co-Design What You Don't Operate
I Replaced /usage and /context in Claude Code With a Single Statusline
Vientapps · 2026-04-18 · via DEV Community

You already run /usage and /context all day. This bash statusline puts both, plus your 5h reset time and working directory, at the bottom of every Claude Code prompt as colored progress bars. Exact script inside.

I'm on Claude Code Max 5x. It's a generous plan. It is also not infinite.

Three things kept catching me off guard. The 5-hour session window would fill up in the middle of a long chain of edits and suddenly I was on a cooldown I hadn't seen coming. The 7-day rolling limit was a slower version of the same problem. And the context window would creep toward full during a deep session and I'd only notice when the responses got weirdly slow.

I knew all three numbers existed somewhere. You can already get the rate limits by running /usage in Claude Code, and the context window by running /context. I was running both commands several times an hour, which is exactly the friction I was trying to avoid in the first place.

It turns out Claude Code has a statusline feature that very few people seem to know about. It runs a shell command before every prompt and prints whatever that command returns at the bottom of your terminal. That's the whole primitive. You get to decide what goes in it. So instead of typing /usage and /context on demand, I put both of them plus my working directory and my 5h reset time in the statusline and never have to ask again.

I asked Claude to build mine. It took four rounds of back-and-forth to land it where I wanted. Here's what I ended up with and why.

What the statusline actually is

A statusLine entry in your ~/.claude/settings.json that points at a script. Every time you hit enter on a Claude Code prompt, the harness pipes a JSON blob to that script over stdin and prints whatever your script writes to stdout.

The JSON blob contains useful fields. For my purposes:

  • cwd, the current working directory
  • rate_limits.five_hour.used_percentage and resets_at
  • rate_limits.seven_day.used_percentage
  • context_window.used_percentage

That is all I needed.

How I worked with Claude on this one

This was the statusline-setup agent end to end. I'd tell the agent what I wanted, it would write the script, I'd look at the output in my terminal, then come back and say "now change this." Four rounds total:

  1. First pass: show 5h, 7d, context, cwd as percentages.
  2. "Shorter. Show just the folder, not the full path. Can we use bars instead of percentages?"
  3. "Move the folder to the front. Color the bars by severity."
  4. "Add the reset time for the 5-hour bar."

I didn't hand-edit the script at any point. Every change went through the agent. Not because I was trying to be pure about it, just because the iterations were fast enough that writing prose was quicker than diffing bash.

The stack

bash + jq + ANSI escape codes. That's it.

The script lives at ~/.claude/statusline-command.sh. The settings.json entry points at it:

"statusLine": {
  "type": "command",
  "command": "bash /Users/YOURNAME/.claude/statusline-command.sh"
}

No install step, no build, no dependencies beyond jq (which most dev machines already have).

The bars

I wanted the progress bars to be visually distinct from each other so I could spot trouble at a glance. Claude's first pass had them all in the same dim color, which was technically working but useless for scanning. That was round three of corrections.

The fix was severity coloring. The filled portion of each bar gets green, yellow, or red depending on how full it is. The empty portion stays dim gray.

bar_color() {
  pct="$1"
  int_pct=$(printf '%.0f' "$pct" 2>/dev/null || echo 0)
  if [ "$int_pct" -ge 81 ] 2>/dev/null; then
    printf '\033[0;31m'   # red
  elif [ "$int_pct" -ge 50 ] 2>/dev/null; then
    printf '\033[0;33m'   # yellow
  else
    printf '\033[0;32m'   # green
  fi
}

Green below 50, yellow 50 to 80, red above 80. So when I glance down and see two greens and a yellow, I'm fine. Two yellows and a red, I wrap up the current task before I lose the session.

Drawing a 10-slot bar in pure shell

The bar itself is 10 Unicode blocks, some filled, some empty. This function computes how many slots to fill, then paints them with ANSI colors:

make_bar() {
  pct="$1"
  filled=$(printf '%.0f' "$(echo "$pct * 10 / 100" | bc -l 2>/dev/null || echo 0)")
  [ "$filled" -gt 10 ] 2>/dev/null && filled=10
  [ "$filled" -lt 0 ] 2>/dev/null && filled=0
  color=$(bar_color "$pct")
  reset='\033[0m'
  dim='\033[2;37m'
  bar=""
  i=0
  while [ "$i" -lt "$filled" ]; do
    bar="${bar}${color}\xe2\x96\x88${reset}"
    i=$((i + 1))
  done
  while [ "$i" -lt 10 ]; do
    bar="${bar}${dim}\xe2\x96\x91${reset}"
    i=$((i + 1))
  done
  printf '['; printf "$bar"; printf ']'
}

\xe2\x96\x88 is the full block character, \xe2\x96\x91 is the light shade. Escape color, character, reset, repeat. The trailing reset on every character matters. If you skip them, a tmux resize or scrollback can bleed color into adjacent text.

The reset timestamp

The nice detail I didn't realize I wanted until I saw the finished version: the 5-hour bar shows when it resets, not just how full it is.

The JSON gives you resets_at as a Unix timestamp. On macOS, date -r takes a timestamp directly:

five_reset_str=$(date -r "$five_resets" "+%-I:%M%p" 2>/dev/null \
  | tr '[:upper:]' '[:lower:]')
[ -n "$five_reset_str" ] && five_reset_str=" rst:${five_reset_str}"

%-I strips the leading zero so 03:45pm renders as 3:45pm. tr lowercases it so it reads closer to how I'd write the time in a note: 3:45pm rather than 3:45PM.

Now the 5h segment looks like 5h:[████████░░]82% rst:3:45pm. I can see both the cost and the clock.

Where Claude surprised me

The severity coloring was me saying "make the bars not all gray, use any colors that make sense" and the agent came back with the green/yellow/red thresholds on its own. I was expecting I'd have to define the ranges. Not complicated logic, but it picked reasonable cutoffs without me specifying them and I didn't need to adjust after.

Where Claude fell short

The first version wrote out full paths for the working directory. I told it I wanted just the folder name. That was a one-line basename fix. Easy, but it's the kind of thing "good default" might have caught without me asking.

The first version also had ASCII bars all in the same dim gray. Functional but not useful. I had to explicitly ask for color differentiation. On re-read, my original prompt did ask for visual bars but didn't say anything about severity, so that's fair. Still, "make the bars informative" would have been my one-shot prompt if I were writing it now.

It also wrote the code to extract rate_limits.five_hour.resets_at before confirming the field actually existed in the JSON payload. It was a plausible path, and it happened to be correct, but it was a guess. For a less obvious field I'd have wasted a round on a hallucinated schema.

The fastest way to get this setup

If you want the exact statusline I have without hand-editing bash, paste this into any Claude Code session and let it do the work:

Set up my Claude Code statusline to show my working directory folder name, my 5-hour usage as a severity-colored progress bar with the reset time next to it, my 7-day usage as a severity-colored progress bar, and my context window as a severity-colored progress bar. Green under 50%, yellow 50 to 80%, red above 80%. Write a bash script at ~/.claude/statusline-command.sh and register it in ~/.claude/settings.json.

Claude Code ships with a statusline-setup agent that's purpose-built for this. That prompt will trigger it and you'll have the same setup in a minute or two. If it picks defaults you don't like, say "now change this" and iterate.

The whole script, if you want mine

If you'd rather read the bash yourself, save this as ~/.claude/statusline-command.sh:

#!/bin/sh
input=$(cat)

cwd=$(echo "$input" | jq -r '.cwd // .workspace.current_dir // empty')
ctx_used=$(echo "$input" | jq -r '.context_window.used_percentage // empty')
five_pct=$(echo "$input" | jq -r '.rate_limits.five_hour.used_percentage // empty')
five_resets=$(echo "$input" | jq -r '.rate_limits.five_hour.resets_at // empty')
week_pct=$(echo "$input" | jq -r '.rate_limits.seven_day.used_percentage // empty')

bar_color() {
  pct="$1"
  int_pct=$(printf '%.0f' "$pct" 2>/dev/null || echo 0)
  if [ "$int_pct" -ge 81 ] 2>/dev/null; then
    printf '\033[0;31m'
  elif [ "$int_pct" -ge 50 ] 2>/dev/null; then
    printf '\033[0;33m'
  else
    printf '\033[0;32m'
  fi
}

make_bar() {
  pct="$1"
  filled=$(printf '%.0f' "$(echo "$pct * 10 / 100" | bc -l 2>/dev/null || echo 0)")
  [ "$filled" -gt 10 ] 2>/dev/null && filled=10
  [ "$filled" -lt 0 ] 2>/dev/null && filled=0
  color=$(bar_color "$pct")
  reset='\033[0m'
  dim='\033[2;37m'
  bar=""
  i=0
  while [ "$i" -lt "$filled" ]; do
    bar="${bar}${color}\xe2\x96\x88${reset}"
    i=$((i + 1))
  done
  while [ "$i" -lt 10 ]; do
    bar="${bar}${dim}\xe2\x96\x91${reset}"
    i=$((i + 1))
  done
  printf '['; printf "$bar"; printf ']'
}

parts=""

if [ -n "$cwd" ]; then
  folder=$(basename "$cwd")
  parts="${parts}$(printf '\033[0;36m%s\033[0m ' "$folder")"
fi

if [ -n "$five_pct" ]; then
  bar=$(make_bar "$five_pct")
  five_reset_str=""
  if [ -n "$five_resets" ]; then
    five_reset_str=$(date -r "$five_resets" "+%-I:%M%p" 2>/dev/null \
      | tr '[:upper:]' '[:lower:]')
    [ -n "$five_reset_str" ] && five_reset_str=" rst:${five_reset_str}"
  fi
  parts="${parts}$(printf '\033[0;33m5h:\033[0m%s%.0f%%%s ' "$bar" "$five_pct" "$five_reset_str")"
fi

if [ -n "$week_pct" ]; then
  bar=$(make_bar "$week_pct")
  parts="${parts}$(printf '\033[0;33m7d:\033[0m%s%.0f%% ' "$bar" "$week_pct")"
fi

if [ -n "$ctx_used" ]; then
  bar=$(make_bar "$ctx_used")
  parts="${parts}$(printf '\033[0;35mctx:\033[0m%s%.0f%%' "$bar" "$ctx_used")"
fi

printf '%s' "$parts"

Make it executable (chmod +x ~/.claude/statusline-command.sh), then add this to ~/.claude/settings.json:

"statusLine": {
  "type": "command",
  "command": "bash /Users/YOURNAME/.claude/statusline-command.sh"
}

Replace YOURNAME with your actual home directory. Restart Claude Code. Run a prompt. The statusline shows up after the first response, which is when the JSON starts carrying real usage numbers.

The output looks like this on my machine:

Folder first, then 5h with its reset time, then 7d, then context. The bars shift from green to yellow to red as the meters fill up, so I can scan the line without reading numbers.

Styling tips

A few things I learned by iterating on this:

Label colors matter more than bar colors. I used cyan for the cwd, yellow for 5h and 7d labels, purple for ctx. When I glance down, the label colors are what tell me which segment I'm looking at. The bar colors just tell me severity.

Keep segments narrow. Ten-slot bars are small enough to fit four segments on one line in a typical terminal. I tried 20-slot bars at one point and they wrapped on my laptop screen.

Always reset after every ANSI escape. I've been burned by color bleeding into the rest of the terminal after a process crashes mid-write. The ${reset} after every character is paranoid but cheap.

Hide segments when the data isn't there yet. The rate-limit numbers aren't populated until Claude Code has made at least one API call in the session. If you print them unconditionally you get an ugly 5h:[░░░░░░░░░░] on a fresh start. The if [ -n ... ] guards handle that.

Where it is now

Running on my machine. I see it every prompt. It has already saved me from one 5h wall I didn't notice coming. Low stakes, nice feature, took about an hour of back-and-forth to land.

What I'd do differently

Tell Claude the severity thresholds up front. I let the agent pick them and it happened to get it right, but on a different day I might have wanted different cutoffs and wasted a round correcting. Specifying "green under 50, yellow 50-80, red over 80" in the first prompt costs nothing.

Ask the agent to verify fields in the JSON before writing code. The resets_at field happened to exist. For a feature you're actually shipping, the "does this field exist" check should happen before the "format it as a time" code. A one-line jq against a sample payload would have caught it.

Don't wait to try it. I almost didn't build this because it felt like yak-shaving. It took under an hour and changed how I pace work inside Claude Code. If you've never opened the statusLine key in your settings.json, that's where to start.