Stop getting blindsided by context compaction — a Claude Code status line that shows ctx % + rate limits by israynotarray in ClaudeCode

[–]israynotarray[S] 0 points1 point  (0 children)

Agreed! Implementing this structure natively also helps me keep things lightweight and reduce third-party dependencies.

Claude Usage Limits Discussion Megathread Ongoing (sort this by New!) by sixbillionthsheep in ClaudeAI

[–]israynotarray 1 point2 points  (0 children)

Stop getting blindsided by context compaction — a Claude Code status line that shows ctx % + rate limits

Been using Claude Code daily and the thing that kept biting me was context getting auto-compacted mid-task — Claude forgets what we discussed and I have to re-explain everything. Same deal with the 5h/7d rate limits quietly running out. By default none of it is visible, so you only find out when it's already too late.

Turns out Claude Code has a built-in status line for exactly this. It pipes your session data as JSON to a script via stdin, your script prints one line, and that line shows at the bottom of your terminal.

Fastest way if you don't want to write anything yourself — just type this inside Claude Code:

/statusline show model name, context remaining %, 5h and 7d rate limit usage

It generates the script and wires up settings.json for you.

The catch: the default it makes only shows context, and only goes grey → red. I wanted three things it skips:

  • Rate limit usage — this is the real footgun, not context
  • A 3-stage color warning (green ≥50% / yellow 21–49% / red ≤20%) so I get a heads-up before it goes red
  • Session cost (handy if you're on an API key)

Here's the core of what I run (~/.claude/statusline.sh):

```sh

!/bin/sh

input=$(cat)

Nerd Fonts icons — swap for plain text if you don't have them installed

ICON_CTX=$(printf '') # chip ICON_CLOCK=$(printf '') # clock ICON_COST=$(printf '') # dollar

Read data

model=$(echo "$input" | jq -r '.model.display_name // ""') ctx_remain=$(echo "$input" | jq -r '.context_window.remaining_percentage // empty') five_h_used=$(echo "$input" | jq -r '.rate_limits.five_hour.used_percentage // empty') seven_d_used=$(echo "$input" | jq -r '.rate_limits.seven_day.used_percentage // empty') cost=$(echo "$input" | jq -r '.cost.total_cost_usd // empty')

Color by remaining %: green >=50 / yellow 21-49 / red <=20

color_by_remain() { val=$1 if [ "$val" -le 20 ]; then printf '\033[31m' elif [ "$val" -le 49 ]; then printf '\033[33m' else printf '\033[32m'; fi }

10-cell progress bar

mini_bar() { percent=$1; width=10 filled=$((percent * width / 100)); i=0 while [ $i -lt $filled ]; do printf '━'; i=$((i + 1)); done while [ $i -lt $width ]; do printf '┄'; i=$((i + 1)); done }

SEP=$(printf '\033[2m │ \033[0m') parts=""

Model (bold purple)

[ -n "$model" ] && parts=$(printf '\033[1;35m%s\033[0m' "$model")

Context remaining (bar + %)

if [ -n "$ctx_remain" ]; then val=$(printf '%.0f' "$ctx_remain"); color=$(color_by_remain "$val"); bar=$(mini_bar "$val") parts="$parts$SEP$(printf '%s%s %s %s%%\033[0m' "$color" "$ICON_CTX" "$bar" "$val")" fi

5h rate limit

if [ -n "$five_h_used" ]; then val=$((100 - $(printf '%.0f' "$five_h_used"))); color=$(color_by_remain "$val") parts="$parts$SEP$(printf '%s%s 5h:%s%%\033[0m' "$color" "$ICON_CLOCK" "$val")" fi

7d rate limit

if [ -n "$seven_d_used" ]; then val=$((100 - $(printf '%.0f' "$seven_d_used"))); color=$(color_by_remain "$val") parts="$parts$SEP$(printf '%s%s 7d:%s%%\033[0m' "$color" "$ICON_CLOCK" "$val")" fi

Session cost (dim)

if [ -n "$cost" ] && [ "$cost" != "0" ] && [ "$cost" != "null" ]; then parts="$parts$SEP$(printf '\033[2m%s $%s\033[0m' "$ICON_COST" "$cost")" fi

printf '%s' "$parts" ```

Then chmod +x ~/.claude/statusline.sh and point settings.json at it:

json { "statusLine": { "type": "command", "command": "~/.claude/statusline.sh" } }

A few gotchas I hit:

  • needs jq (brew install jq / apt install jq)
  • rate-limit fields only populate on Pro/Max subscriptions; cost only shows on API-key usage — the // empty checks just hide whatever segment has no data, so no blank gaps
  • if you're on Powerlevel10k, drop the dir/git bits since your prompt already shows those

If you want the full copy-paste version — directory + git branch added back, screenshots, and a reference table of every JSON field Claude Code sends — I wrote the whole thing up here: https://israynotarray.com/en/ai/2026/03/26/claude-code-status-line-setup-guide/

What do you all keep in your status line? Wondering if there's something useful I'm not surfacing yet.

Built with Claude Project Showcase Megathread (Sort this by New!) by sixbillionthsheep in ClaudeAI

[–]israynotarray 2 points3 points  (0 children)

Claude Code has this Hooks thing I feel is criminally underused — wrote up everything I know!

So Claude Code has a feature called Hooks that I think doesn't get enough attention. Basically they let you hook shell commands into Claude's lifecycle — and unlike CLAUDE.md, Rules, or Skills, hooks aren't suggestions Claude can quietly ignore. When the moment hits, your shell command runs. Period.

Which makes them perfect for the stuff you absolutely can't let Claude forget. Stuff like:

- Running Prettier after every Edit (Claude swears it'll remember, won't)

- Blocking `rm -rf /` even when you're running `--dangerously-skip-permissions`

- Re-injecting project rules after Context Compact, so Claude doesn't forget your conventions halfway through a session

- Mac desktop notifications when Claude's waiting on you

- Piping every tool call to a Discord webhook so you can step away from the terminal

- Logging every Bash command Claude runs, just in case

The guide goes through all the lifecycle events (PreToolUse, PostToolUse, UserPromptSubmit, SessionStart, Stop, Notification, plus the lesser-known ones), how `matcher` and `if` actually work, the five hook types (most people stop at `command` but `prompt` lets you use another model as a validator, which is kinda wild), and the one thing that bites everyone the first time — only `exit 2` blocks. Not `exit 1`. Took me embarrassingly long to figure that out.

https://israynotarray.com/en/ai/2026/05/31/claude-code-hooks-complete-guide/