SLOPSHOPPER

token-weather

A live forecast of the context window, drawn as one line above the prompt: a weather icon and word, the fill percentage, and the tokens used of the window…

bandprompt
v0.1.6Apache-2.0updated 2026-10-21joaopasbento/claude-mods/token-weather
A shopper browsing a rack in a slop shop
Preview · a replayed session in a sandbox
claude · ~/work/app · token-weather
› fix the failing auth test and add an audit log call ⏺ Read(src/auth.ts) ⎿ Read 6 lines ⏺ Update(src/auth.ts) ⎿ Added 2 lines, removed 1 line ⏺ Bash(bun test) ⎿ 3 pass, 1 fail ● Done. refresh now rejects expired claims and logs an audit event. ✻ Worked for 42s · done 4:20 PM ☀ Clear 49% of context 97.4k / 200k · Opus 5.5 ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── › ? for shortcuts

Draws

Band
☀ Clear 49% of context 97.4k / 200k · Opus 5.5
README

<!-- Modified by joaopasbento in 2026 from the token-weather example in anthropics/claude-code-playground (commit 569c5283d9a0): see "Origin" below for what changed. -->

Token Weather

A Claude Code mod that draws a live forecast of your context window in the band above the prompt, with the session's model, effort and ultracode beside it: one hooks module that reads real usage figures and session state and draws one line of UI, on top of whatever the mods after it draw there.

What it shows

☂  Showers  80% of context  796.9k / 1M  ·  Opus 5.5 · high

The band shows:

  • a weather icon and word for how full the window is, and
  • the percentage used, and the tokens used out of the window.

And right after the tokens, past a grey · , the main session's:

  • model, by its short name: Opus 5.5 for claude-opus-5-5; any other id without its claude- prefix and its [...] suffix (the same rule as savvy-progress's modelName);
  • effort, with the names of the app's effort menu: low, medium, high, extra (for xhigh) and max; an effort given as a number shows as that number; a model without effort shows none;
  • ultracode, only while it is on for the session.

Each part is left out when there is nothing to say, and the · separators are grey. When the session's part does not fit beside the tokens, it moves to the line beneath, with no · before it, starting under the forecast word (column 3 in the terminal):

☀  Clear  7% of context  70k / 1M
   Opus 5.5 · extra · ultracode

Whether it fits is worked out from the band's width (bodyColumns) and the length of the texts, with a margin: the line's characters times 1.25, plus 2 columns, must fit. The terminal draws one character per column, but the app draws the band in a proportional font, where letters and symbols can run wider than its column metric, so the margin keeps the line from breaking there on its own. The context part is never cut; the session's part alone, if too long for the line beneath, is cut at its end.

UsedForecastColor
under 50%☀ Cleargreen: the theme's success
50–69%☁ Cloudynone: the plain text color
70–79%☂ Showersamber: the theme's warning
80–89%☇ Stormorange: #cc5a14, fixed
90% up↯ Compact soonred: the theme's error

The limits compare the exact share of the window (tokens / window), not the rounded percentage: at 899,999 of 1M the band reads 90% but stays ☇ Storm, and ↯ shows from 900,000. The theme keys follow Claude Code's light and dark themes. No theme key is an orange that reads well on both, so Storm uses one fixed tone between the themes' amber and red.

The numbers are real, not estimated. The mod calls $.session.usage() and reads context:

  • tokens: the input tokens the last response was answered over (uncached, cache-written and cache-read together),
  • window: the context window of the session's model, and
  • percent: tokens over window.

These are the same figures the status line shows (total_input_tokens, context_window_size, used_percentage). The call is free: the mod doesn't ask for a breakdown, so it sends no token-count request.

The session's part comes from the main session alone; subagents' requests, turns and events (which carry an agent id) are left out:

  • Model: the model that answered each request (usage.model in the turn.step result, or the request's e.model). On a switch, to_model of classic.PostModelSwitch. At the start, model of classic.SessionStart, or $.session.model(). A value that names no version (an alias such as opus) waits for the first request, which names the id.
  • Effort: e.effort of each main-session turn.step. A model switch clears it until the next request says it again.
  • Ultracode: the engine's own reminders to the model. Claude Code sends ultra_effort_enter while ultracode is in effect for the session (turned on in the menu or with /effort ultracode, on a model that supports it) and ultra_effort_exit once it is off; the mod reads them as they go out (prompt.attachment). The ultracode keyword at the start of a prompt is a different attachment and does not count.

Nothing is read on a timer: what no event catches between responses shows at the next request. The band is redrawn only when a value it shows changes.

HookWhat it does
session.startTakes a first reading, so the band shows before the first turn, and reads the model from $.session.model().
classic.SessionStartTakes the model the session starts on, when the event names one.
turn.completeTakes a reading after each main-loop turn. Subagent turns are skipped.
turn.stepAfter each model request of a main-loop turn (so after each tool use too), updates the icon, percentage and tokens from that request's usage, and the model and effort from the request. Subagent requests are skipped.
classic.PostModelSwitchTakes the new model and clears the effort. A subagent's switch is skipped.
prompt.attachment with ultra_effort_enter and ultra_effort_exitTurns ultracode on and off as the engine tells the model. Subagents' reminders are skipped. The attachment goes out unchanged.
ui.render with {component: "AbovePrompt"}Draws the line on top of whatever the mods beneath drew in the band (await next(e)). Alone, the line is the whole band. It gives way to a survey.

Install

Requires Claude Code 2.1.287 or later, where mods load by default. The band is drawn above the prompt in the terminal and in the desktop app's Code tab.

In Claude Code:

/plugin marketplace add joaopasbento/claude-mods
/plugin install token-weather@claude-mods

Then run /reload-plugins, or start a new session. No environment variables or configuration.

Test it

From a clone of this repository:

claude plugin validate ./token-weather
claude plugin test ./token-weather

Notes and limitations

  • The percentage is of the full window. Claude Code's own "context used" notice counts against the auto-compact point, which is lower, so the two can differ.
  • The line updates during a turn, after each model request of the main loop, and again when the turn ends.
  • The reading resets when the session starts, or when the plugin reloads.
  • On a 1M-token window, ordinary work stays at ☀ for a long time. That's accurate.
  • The band is shared. Claude Code has one band above the prompt for every mod, and each mod's hook runs before those of the mods after it. Token Weather passes the band on (await next(e)) and puts its line on top of what it gets back, so the mods after it (Claude Code's bundled mods, such as you-should-know, always come after the ones you install) draw under the line. A mod that runs before Token Weather and puts its own drawing on top, as savvy-progress does with its bar (it lists token-weather as a dependency, which places it first), sits above the line. A mod that draws without passing the band on hides what the mods after it would draw.
  • A band taller than its room shows its top. When the mods' drawings together pass the band's rows (maxRows), Claude Code shows the top of the band and an ↓ n more row. The line is near the top, so it stays in view and only what is drawn under it is cut.
  • Before the first response, the band reads 0%, because no response has reported usage yet.
  • The effort shows from the first request on. Claude Code tells a mod the effort only with each request, so before the first one, and after a model switch until the next one, there is none to show.
  • A change between responses can show only at the next request. Nothing is read on a timer: an effort changed in the menu shows with the next request; ultracode turned on or off shows when the next prompt is sent, since that is when Claude Code tells the model.
  • Ultracode after a restart or resume shows once Claude Code sends its reminder again, at a following prompt.
  • Where Claude Code's built-in guard sec-default@builtin loads, the classic.* and prompt.attachment events pass over the plugins a person installs. It loads in two cases: on a computer with managed settings, and in a session started on a Team or Enterprise account. There, the model follows requests and $.session.model() alone, and ultracode does not show.

Dependencies

None.

Origin

This mod started from the token-weather example in anthropics/claude-code-playground, folder claude-code/mods/token-weather, at commit 569c5283d9a0, licensed under the Apache License 2.0. What changed from that example:

  • Updates mid-response. A turn.step hook updates the icon, percentage and tokens after each model request of the main loop, from that request's own usage. The example only updated at session start and at the end of each turn.
  • New limits and colors. Clear under 50%, Cloudy 50–69%, Showers 70–79%, Storm 80–89%, Compact soon from 90%, compared on the exact share of the window. Colors are Claude Code theme keys (success, warning, error), the plain text color for Cloudy, and a fixed orange for Storm. The example used fixed ANSI colors and limits at 25/50/75/90% of the rounded percentage.
  • No chart and no last-turn change. The line keeps the icon, the forecast word, the percentage and the tokens. The example also drew a chart of the last turns and how much the last turn added.
  • A shared band. The mod passes the band on and puts its line on top of what the mods beneath drew. The example drew its line in place of anything else.
  • No left padding. The line starts at the band's left edge, so the icon lines up with the dot of the savvy-progress bar above it and the forecast word with its title. The example padded the line by one column on each side.
  • Fixed props. The mod reads hasSurvey from e.props, where Claude Code puts it. The example read it from the event itself, so the band never gave way to surveys.
  • The session after the tokens. The line also shows the main session's model, effort and ultracode, after the tokens and a grey · , moving to the line beneath, under the forecast word, when the band is too narrow. The example showed only the context.
  • Tests. tests/token-weather.test.ts is new and runs under claude plugin test.
  • Packaging. A new author and marketplace, this README rewritten, and the example's screenshots removed, since they showed the old colors.

License

Apache License 2.0. See LICENSE.

Source 1 files
hooks/token-weather.mjs 326 lines
1// Copyright 2026 Anthropic PBC
2// SPDX-License-Identifier: Apache-2.0
3//
4// Modified by joaopasbento in 2026 from the token-weather example in
5// anthropics/claude-code-playground (commit 569c5283d9a0): updates mid-response,
6// new limits and colors, props read from e.props, the chart and the last-turn
7// change removed, the band shared with the mods drawn beneath, the line
8// drawn from the band's left edge, and the session's model, effort and
9// ultracode after the tokens.
10//
11// Token Weather: a live forecast of the context window, above the prompt, and
12// the main session's model, effort and ultracode beside it.
13//
14// turn.complete: after each main-loop turn, read the context window's fill
15// from $.session.usage() (the same figures the status line shows).
16// turn.step: after each model request of a main-loop turn (each tool the
17// model uses ends one request and starts the next), take a live reading from
18// that request's own usage (the same sum the status line's tokens are), with
19// the window from $.session.usage(), so the line follows it mid-response.
20// The same request names the model that answered (usage.model, or e.model)
21// and the effort it ran at (e.effort).
22// session.start: take a first reading, so the band shows before any turn, and
23// the model from $.session.model().
24// classic.SessionStart: the model the session starts on, when it says one.
25// classic.PostModelSwitch: the new model (to_model); the effort is cleared
26// until the next request says it again.
27// prompt.attachment: ultracode is on while the engine's ultra_effort_enter
28// reminder is the last it sent, off after ultra_effort_exit.
29// Subagents' turns, requests and events (agentId, agent_id) are left out.
30// ui.render (AbovePrompt): one line: icon, forecast word, percent, and tokens
31// used of the window, then, after a grey " · ", model, effort and ultracode;
32// when they do not fit beside the tokens, they go on the line beneath, from
33// the forecast word's column, with no " · " before them.
34// The band is one for every mod: the line goes on top of whatever the hooks
35// beneath drew (await next(e)), so when the band is taller than its rows and
36// shows its top, the line stays in view; alone, it is the whole band, as
37// before.
38//
39// The host reads on(...) and $.noun.method(...) from source, so they are
40// spelled literally, and helpers that take $ are top-level functions.
41
42// The stop: the share of the window where the session is meant to end
43// (900k of 1M). The last forecast starts there.
44const STOP = 0.9;
45
46// Forecast bands, by the exact share of the window used (tokens / window,
47// never the rounded percent). Colors are Claude Code theme keys, which follow
48// the light and dark themes, except Cloudy (the plain text color) and Storm:
49// no theme key is an orange that reads on both, so it is one fixed tone
50// between the themes' amber and red.
51const FORECAST = [
52// Single-width text symbols, not emoji: they line up in every terminal font.
53  { upTo: 0.5, icon: "☀", word: "Clear", color: "success" },
54  { upTo: 0.7, icon: "☁", word: "Cloudy", color: undefined },
55  { upTo: 0.8, icon: "☂", word: "Showers", color: "warning" },
56  { upTo: STOP, icon: "☇", word: "Storm", color: "#cc5a14" },
57  { upTo: Infinity, icon: "↯", word: "Compact soon", color: "error" },
58];
59
60// Whether the session's part fits beside the tokens: the line's characters,
61// times ROOM_SCALE, plus ROOM_SLACK columns, within the band's bodyColumns.
62// The terminal draws a character per column; the app draws the band in a
63// proportional font whose letters and symbols can run wider than its column
64// metric, so the margin keeps the line from breaking there on its own.
65const ROOM_SCALE = 1.25;
66const ROOM_SLACK = 2;
67
68// The column the forecast word starts in: the icon and two spaces.
69const WORD_COLUMN = 3;
70
71// Model aliases, which name no version: the model waits for a request's id.
72const ALIASES = /^(fable|mythos|opus|sonnet|haiku|best|default|opusplan)$/i;
73
74// The last turn's reading: { tokens, window, percent }; null before any.
75let reading = null;
76// The reading after the latest model request of the running turn; null
77// between turns, when the band shows the last turn's reading.
78let live = null;
79
80// The main session's model by short name ("Opus 5.5"); null until known.
81let model = null;
82// The effort of the main session's latest request: a level or a number;
83// undefined before the first request, after a model switch, and on a model
84// without effort.
85let effort = undefined;
86// Ultracode in effect for the session.
87let ultracode = false;
88
89export function register(on) {
90  on("session.start", async ($, e, next) => {
91    const result = await next(e);
92    reading = null;
93    live = null;
94    model = null;
95    effort = undefined;
96    ultracode = false;
97    await takeReading($);
98    await readModel($);
99    return result;
100  });
101
102  on("classic.SessionStart", async ($, e, next) => {
103    const result = await next(e);
104    if (!e.agent_id && e.model) {
105      setShown($, () => {
106        model = shortModel(e.model) ?? model;
107      });
108    }
109    return result;
110  });
111
112  on("turn.complete", async ($, e, next) => {
113    const result = await next(e);
114    if (e.agentId) {
115      return result;
116    }
117    await takeReading($);
118    return result;
119  });
120
121  on("turn.step", async function* ($, e, next) {
122    const result = yield* next(e);
123    if (!e.agentId) {
124      setShown($, () => {
125        model = shortModel((result && result.usage && result.usage.model) || e.model) ?? model;
126        effort = e.effort;
127      });
128      await takeLiveReading($, result && result.usage);
129    }
130    return result;
131  });
132
133  on("classic.PostModelSwitch", async ($, e, next) => {
134    const result = await next(e);
135    if (!e.agent_id) {
136      // An alias names no version: the next request's id will.
137      setShown($, () => {
138        model = shortModel(e.to_model);
139        effort = undefined;
140      });
141    }
142    return result;
143  });
144
145  // The engine's own ultracode reminders, on main: not the "ultracode"
146  // keyword at the start of a prompt, which is another attachment.
147  on("prompt.attachment", { type: "ultra_effort_enter" }, async ($, e, next) => {
148    const result = await next(e);
149    if (!e.agentId) {
150      setShown($, () => {
151        ultracode = true;
152      });
153    }
154    return result;
155  });
156
157  on("prompt.attachment", { type: "ultra_effort_exit" }, async ($, e, next) => {
158    const result = await next(e);
159    if (!e.agentId) {
160      setShown($, () => {
161        ultracode = false;
162      });
163    }
164    return result;
165  });
166
167  on("ui.render", { component: "AbovePrompt" }, async ($, e, next) => {
168    if (e.props.hasSurvey || (!reading && !live)) {
169      return next(e);
170    }
171    const below = await next(e);
172    const { Box, Text } = $.ui.resolve(e);
173    const line = band(Box, Text, e.props.bodyColumns);
174    // Nobody beneath drew: the engine's own band, empty without a survey.
175    if (!below || below.type === "engine") {
176      return line;
177    }
178    return Box({ flexDirection: "column", children: [line, below] });
179  });
180}
181
182async function readModel($) {
183  try {
184    const id = await $.session.model();
185    setShown($, () => {
186      model = shortModel(id) ?? model;
187    });
188  } catch {
189    // No model yet; the first request will name it.
190  }
191}
192
193// Runs change, and redraws the band only when what the line shows changed.
194function setShown($, change) {
195  const before = sessionParts().join("|");
196  change();
197  if (sessionParts().join("|") !== before && (reading || live)) {
198    $.ui.invalidate("ui.render");
199  }
200}
201
202async function takeReading($) {
203  try {
204    const { context } = await $.session.usage();
205    if (!context || !context.window) {
206      return;
207    }
208    const tokens = context.tokens ?? 0;
209    const percent = Math.round(context.percent ?? (tokens / context.window) * 100);
210    reading = { tokens, window: context.window, percent };
211    live = null;
212    $.ui.invalidate("ui.render");
213  } catch {
214    // No reading this turn; the band keeps the last one.
215  }
216}
217
218// usage: the request's own, as the API reported it; without it, the figures
219// $.session.usage() holds.
220async function takeLiveReading($, usage) {
221  try {
222    const { context } = await $.session.usage();
223    if (!context || !context.window) {
224      return;
225    }
226    let tokens = context.tokens ?? 0;
227    let percent = Math.round(context.percent ?? (tokens / context.window) * 100);
228    if (usage) {
229      tokens = (usage.input_tokens ?? 0) + (usage.cache_creation_input_tokens ?? 0) + (usage.cache_read_input_tokens ?? 0);
230      percent = Math.round((tokens / context.window) * 100);
231    }
232    live = { tokens, window: context.window, percent };
233    $.ui.invalidate("ui.render");
234  } catch {
235    // No reading this step; the band keeps the last one.
236  }
237}
238
239function band(Box, Text, columns) {
240  const now = live ?? reading;
241  const f = forecastFor(now.tokens / now.window);
242  const words = [`${f.icon}  ${f.word}`, `  ${now.percent}% of context`, `  ${short(now.tokens)} / ${short(now.window)}`];
243  // No left padding: the line starts at the band's left edge, as the bar of
244  // savvy-progress above it does, so their icons and words line up.
245  const context = Box({
246    flexDirection: "row",
247    flexShrink: 0,
248    children: [
249      Text({ ...colored(f), bold: true, children: words[0] }),
250      Text({ children: words[1] }),
251      Text({ dimColor: true, children: words[2] }),
252    ],
253  });
254  const parts = sessionParts();
255  if (!parts.length) {
256    return Box({ flexDirection: "row", children: [context] });
257  }
258  // The session's part: model, effort and ultracode, with grey " · " between.
259  const children = [];
260  for (const part of parts) {
261    if (children.length) {
262      children.push(Text({ dimColor: true, children: " · " }));
263    }
264    children.push(Text({ children: part }));
265  }
266  const session = Text({ wrap: "truncate-end", children });
267  const lead = "  ·  ";
268  if (fits([...words, lead, parts.join(" · ")].join(""), columns)) {
269    return Box({ flexDirection: "row", children: [context, Text({ dimColor: true, children: lead }), session] });
270  }
271  // Too wide for one line: the session's part goes beneath, from the forecast
272  // word's column, with no " · " before it; the context stays whole.
273  return Box({ flexDirection: "column", children: [context, Box({ paddingLeft: WORD_COLUMN, children: [session] })] });
274}
275
276// Whether text fits in the band's columns, with the app's margin.
277function fits(text, columns) {
278  return typeof columns === "number" && Math.ceil([...text].length * ROOM_SCALE) + ROOM_SLACK <= columns;
279}
280
281// Model, effort and ultracode, in that order, each left out when there is
282// nothing to say.
283function sessionParts() {
284  const parts = [];
285  if (model) parts.push(model);
286  if (effort !== undefined && effort !== null) parts.push(effortName(effort));
287  if (ultracode) parts.push("ultracode");
288  return parts;
289}
290
291// The effort as the app's effort menu names it: xhigh is "extra" there; a
292// number shows as it is.
293function effortName(value) {
294  if (typeof value === "number") return String(value);
295  return value === "xhigh" ? "extra" : String(value);
296}
297
298// The short name, by savvy-progress's modelName rule: "Opus 5.5" for
299// claude-opus-5-5, any other id without its claude- prefix and its [..]
300// suffix; null for an alias, which names no version, or nothing.
301function shortModel(id) {
302  if (typeof id !== "string" || !id) return null;
303  const m = /(fable|mythos|opus|sonnet|haiku)-(\d+)(?:-(\d{1,2})(?!\d))?/i.exec(id);
304  const [, family = "", major = "", minor] = m ?? [];
305  if (!family) {
306    const name = id.replace(/^claude-/, "").replace(/\[.*\]$/, "");
307    return !name || ALIASES.test(name) ? null : name;
308  }
309  return `${family.charAt(0).toUpperCase()}${family.slice(1).toLowerCase()} ${major}${minor ? "." + minor : ""}`;
310}
311
312function forecastFor(share) {
313  return FORECAST.find((band) => share < band.upTo) ?? FORECAST[FORECAST.length - 1];
314}
315
316// The color prop, left out for a band drawn in the plain text color.
317function colored(f) {
318  return f.color ? { color: f.color } : {};
319}
320
321function short(n) {
322  if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(n % 1_000_000 === 0 ? 0 : 1)}M`;
323  if (n >= 1_000) return `${(n / 1_000).toFixed(n % 1_000 === 0 ? 0 : 1)}k`;
324  return String(n);
325}
326