SLOPSHOPPER

token-weather

A live forecast of the context window, shown above the prompt

band
v0.2.0no licenseupdated 2026-10-22vuon9/cc-mods/plugins/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 ☁️ Cloudy 49% · 97.4k / 200k ██ ▲ +0k last turn ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── › ? for shortcuts

Draws

Band
☁️ Cloudy 49% · 97.4k / 200k ██ ▲ +0k last turn
README

token-weather

token-weather band above the prompt

<sub>Drawn by the mod from sample data.</sub>

A one-line forecast of the context window, shown above the prompt and updated after every turn:

☁️ Cloudy  30% · 60k / 200k  ▂▃▅▆  ▲ +23.9k last turn  │  Opus 5.5 (high)
  • The forecast follows how full the window is: Clear under 25%, Cloudy under 50%, Showers under 75%, Storm under 90%, then Compact soon.
  • The sparkline is the context size over the last 12 turns. The delta is how much the last turn added or freed.
  • Right after a compaction it shows ↺ Compacted until your next message brings back a real size.
  • The end shows the model and effort of the latest request, as it was sent, so a fallback model or a lowered effort shows there. It appears after the first request, and a /model or /effort change shows from the next one.

Only the main conversation counts; subagent turns don't move it. The mod makes no model calls of its own.

Install

claude plugin marketplace add vuon9/cc-mods
claude plugin install token-weather@cc-mods

Update with claude plugin update token-weather.

Develop

From the repo root:

claude --plugin-dir plugins/token-weather
claude plugin test plugins/token-weather
Source 2 files
hooks/register.tsx 137 lines
1import { atom, read, update } from 'claude-code'
2import type { EngineInterface, Register } from 'claude-code'
3
4const history = atom({ plugin: 'token-weather', key: 'history' } as const, [])
5const contextWindow = atom({ plugin: 'token-weather', key: 'window' } as const, 0)
6const isCompacted = atom({ plugin: 'token-weather', key: 'isCompacted' } as const, false)
7const modelInUse = atom({ plugin: 'token-weather', key: 'model' } as const, null)
8
9const BARS = '▁▂▃▄▅▆▇█'
10const SPAN = 12
11
12// U+FE0F asks for the color emoji form. Without it a terminal draws some of these from the text font
13// and borrows the rest from the emoji font, so they come out at different sizes and widths.
14const EMOJI = '\u{FE0F}'
15
16const FORECASTS = [
17  { below: 25, icon: `☀${EMOJI}`, word: 'Clear', color: '#FFA500' },
18  { below: 50, icon: `☁${EMOJI}`, word: 'Cloudy', color: 'cyan' },
19  { below: 75, icon: `☂${EMOJI}`, word: 'Showers', color: 'blue' },
20  { below: 90, icon: '☇', word: 'Storm', color: 'magenta' },
21  { below: Infinity, icon: '↯', word: 'Compact soon', color: 'red' },
22]
23
24function short(n: number) {
25  const [value, unit] = n >= 1e6 ? [n / 1e6, 'M'] : [n / 1e3, 'k']
26  return `${value.toFixed(1).replace(/\.0$/, '')}${unit}`
27}
28
29function sparkline(samples: number[]) {
30  const top = Math.max(...samples)
31  return samples
32    .map(n => BARS[top === 0 ? 0 : Math.min(BARS.length - 1, Math.floor((n / top) * BARS.length))])
33    .join('')
34}
35
36// Reads 'claude-opus-4-5-20251101' and provider ids like 'us.anthropic.claude-opus-4-5-20251101-v1:0'
37// as 'Opus 4.5'. A [1m] tag is dropped since the band already shows the window. Anything else stays as is.
38function modelName(id: string) {
39  return id.replace(
40    /^.*claude-([a-z]+)-(\d+)(?:-(\d{1,2}))?(?!\d).*$/,
41    (_, family: string, major: string, minor?: string) =>
42      `${family.charAt(0).toUpperCase()}${family.slice(1)} ${minor ? `${major}.${minor}` : major}`,
43  )
44}
45
46async function sample($: EngineInterface) {
47  const { context } = await $.session.usage()
48  if (context.tokens === undefined) return
49  await update($, contextWindow, () => context.window)
50  await update($, history, h => [...h, context.tokens!].slice(-SPAN))
51  await update($, isCompacted, () => false)
52}
53
54export const register: Register = on => {
55  on('session.start', async ($, e, next) => {
56    const result = await next(e)
57    if ((await read($, history)).length === 0) await sample($)
58    return result
59  })
60
61  on('turn.complete', async ($, e, next) => {
62    const result = await next(e)
63    if (e.agentId !== undefined) return result
64    await sample($)
65    return result
66  })
67
68  // A step is one model request, sent with the model and effort in force after any fallback or downgrade.
69  on('turn.step', async function* ($, e, next) {
70    if (e.agentId === undefined)
71      await update($, modelInUse, () => ({ id: e.model, effort: e.effort }))
72    return yield* next(e)
73  })
74
75  // Right after a compaction the engine has no real context size until the next API response.
76  on('session.compact', async ($, e, next) => {
77    const result = await next(e)
78    if (e.agentId === undefined && e.trigger !== 'precompute' && result.messages) {
79      await update($, isCompacted, () => true)
80    }
81    return result
82  })
83
84  on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
85    const samples = await read($, history)
86    const window = await read($, contextWindow)
87    const inUse = await read($, modelInUse)
88    const compacted = await read($, isCompacted)
89    if (e.props.hasSurvey || samples.length === 0 || window === 0) return next(e)
90
91    const tokens = samples[samples.length - 1]
92    const percent = Math.round((tokens / window) * 100)
93    const forecast = FORECASTS.find(f => percent < f.below)!
94    const delta = samples.length > 1 ? tokens - samples[samples.length - 2] : undefined
95    const { Box, Text } = $.ui.resolve(e)
96
97    return (
98      <Box>
99        {compacted ? (
100          <Box>
101            <Text color="green" bold>
102              ↺ Compacted
103            </Text>
104            <Text dimColor>{'  new size after your next message  '}</Text>
105          </Box>
106        ) : (
107          <Box>
108            <Text color={forecast.color} bold>
109              {forecast.icon} {forecast.word}
110            </Text>
111            <Text>
112              {'  '}
113              {percent}% · {short(tokens)} / {short(window)}
114              {'  '}
115            </Text>
116          </Box>
117        )}
118        <Text color={compacted ? 'gray' : forecast.color}>{sparkline(samples)}</Text>
119        {!compacted && delta !== undefined && (
120          <Text dimColor>
121            {'  '}
122            {delta >= 0 ? '▲ +' : '▼ -'}
123            {short(Math.abs(delta))} last turn
124          </Text>
125        )}
126        {inUse && (
127          <Box>
128            <Text dimColor>{'  │  '}</Text>
129            <Text bold>{modelName(inUse.id)}</Text>
130            {inUse.effort !== undefined && <Text> ({inUse.effort})</Text>}
131          </Box>
132        )}
133      </Box>
134    )
135  })
136}
137
types/index.d.ts 13 lines
1export type ModelInUse = { id: string; effort?: string | number }
2
3declare module 'claude-code' {
4  interface PluginState {
5    'token-weather': {
6      history: number[]
7      window: number
8      isCompacted: boolean
9      model: ModelInUse | null
10    }
11  }
12}
13