Keeping Claude in the Context Smart Zone

May 3, 2026

I added a line under my Claude prompt because I wanted context size to feel like a live system metric, not something I only notice after the session starts getting weird.

The starting point was Claude Code's /statusline slash command. It is a useful bootstrap: Claude wires up a status line command in the local settings and gives you a script to iterate on. I treated that generated version as scaffolding, then changed it until it showed the exact metadata I wanted every time I looked at the prompt.

The layout is intentionally small:

claude status line
current-project (feature/statusline) · 102.6k/200k tok · Opus 4.7 (1M context)

The first part is where I am. The bare name is the current directory, and the green text in parentheses is the Git branch. I spend a lot of time in worktrees, so this gives me a constant gut check that I am talking to the model from the right checkout.

The middle segment is the part I care about most: 102.6k/200k tok. That is not the model's full context window. It is my working budget. My goal is to keep active sessions at 200k tokens or less when I am on Opus 4.7 with its 1M context window. If I am not on that class of model, I default the budget to 100k.

That distinction matters. A huge context window is useful, but I do not treat it as an invitation to fill the whole thing.

The Smart Zone

The point of the status line is to stay in what I think of as the "smart zone" of the context window.

Once a conversation gets too large, the model can technically still hold the tokens, but the quality of its attention may get worse. It has more old decisions, stale plans, dead branches, and half-relevant details to sort through. The failure mode is not always a hard error. Sometimes it is subtler: slower turns, worse prioritization, missed constraints, or answers that feel less grounded in the current task.

So I use the context window like RAM, not like archival storage. More room is great, but pressure still matters.

The Claude Setting

Claude Code exposes a status line hook. My global ~/.claude/settings.json points that hook at a shell script:

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

Claude passes session metadata to the command as JSON on stdin. The script reads that JSON, extracts the workspace, Git branch, model name, and token usage, then prints one compact terminal line.

The budget rule is deliberately simple:

raw_model=$(echo "$input" | jq -r '.model.display_name // .model.id // ""')

if echo "$raw_model" | grep -qi '1M'; then
  smart_label="200k"
else
  smart_label="100k"
fi

In practice, Opus 4.7 with 1M context gets the 200k label. Everything else gets 100k.

What Counts as Tokens

The token count comes from the context window metadata Claude gives the status line command:

tokens=$(echo "$input" | jq -r '
  ((.context_window.total_input_tokens // 0)
  + (.context_window.total_output_tokens // 0)
  + (.context_window.current_usage.cache_read_input_tokens // 0)
  + (.context_window.current_usage.cache_creation_input_tokens // 0))')

I add four numbers:

  • total_input_tokens
  • total_output_tokens
  • cache_read_input_tokens
  • cache_creation_input_tokens

That gives me a single number that behaves like context pressure. It is not trying to be a perfect theory of cognition. It is just a useful operational gauge: "how full does this session feel?"

The script formats that number into a small terminal-friendly label:

fmt_tokens() {
  awk -v n="$1" 'BEGIN {
    if (n >= 1000000) printf "%.2fM", n/1000000;
    else if (n >= 1000) printf "%.1fk", n/1000;
    else printf "%d", n;
  }'
}

So 102600 becomes 102.6k, which is easy to scan between turns.

Why Metadata Belongs in the Prompt Area

I like this information directly under the prompt because it changes behavior without adding friction.

If I see 38k/200k, I know the session still has room for exploration. If I see 180k/200k, I start tightening up: summarize decisions, avoid dragging in giant files, make a fresh worktree, or start a new thread with a clean brief. If I see the warning flag, I stop pretending the old context is free.

Directory. Branch. Token pressure. Model. Warning.

That is the whole layout.

The Habit It Creates

The important part is not the shell script. The important part is that the metadata creates a habit.

I do not want to maximize context usage. I want to maximize useful attention. Keeping sessions under 200k tokens on Opus 4.7, and under 100k elsewhere, gives me a simple rule of thumb. It lets me enjoy large-context models while still respecting the fact that too much history can turn into drag.

The status line is just a tiny dashboard for that belief: stay aware of the working set, keep the model in the smart zone, and reset before the context starts working against the task.

The General Script

Here is the whole pattern as a generic script. It does not depend on any specific project name or machine path. It expects jq, git, and Claude's status line JSON on stdin.

#!/usr/bin/env bash

input=$(cat)

cwd=$(echo "$input" | jq -r '.workspace.current_dir // .cwd // "."')
dir=$(basename "$cwd")
branch=$(git --no-optional-locks -C "$cwd" branch 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/')

raw_model=$(echo "$input" | jq -r '.model.display_name // .model.id // "unknown model"')
tokens=$(echo "$input" | jq -r '
  ((.context_window.total_input_tokens // 0)
  + (.context_window.total_output_tokens // 0)
  + (.context_window.current_usage.cache_read_input_tokens // 0)
  + (.context_window.current_usage.cache_creation_input_tokens // 0))')
over=$(echo "$input" | jq -r '.exceeds_200k_tokens // false')

if echo "$raw_model" | grep -qi '1M'; then
  smart_label="200k"
else
  smart_label="100k"
fi

fmt_tokens() {
  awk -v n="$1" 'BEGIN {
    if (n >= 1000000) printf "%.2fM", n/1000000;
    else if (n >= 1000) printf "%.1fk", n/1000;
    else printf "%d", n;
  }'
}

tokens_fmt=$(fmt_tokens "$tokens")
warn=""

if [ "$over" = "true" ]; then
  warn=" \033[31m>200k\033[00m"
fi

printf "%s\033[32m%s\033[00m \033[90m.\033[00m \033[33m%s/%s tok\033[00m \033[90m.\033[00m \033[36m%s\033[00m%b" \
  "$dir" "$branch" "$tokens_fmt" "$smart_label" "$raw_model" "$warn"

Pro Tip

If you are using the Codex macOS app, the /status command opens a status widget you can leave visible while you work. It is not the same custom terminal line, but it gives you a similar ambient read on the session without needing to wire up your own script.