A context-window pane: colour-coded bar and a colour legend for every category

Three Claude Code mods for keeping an eye on how much room you have left and what you spend: your context window, your plan usage limits, and a receipt for each turn. They work in the terminal and in the Claude desktop app's Code tab.

| Mod | Where it shows | What it shows |
|---|---|---|
context-window | A pane beside the conversation | A waffle chart of what fills the context window and a legend of every category (tokens and share), largest first, the autocompact buffer, and a warning at 50% |
plan-usage | A band above the prompt | 5-hour and weekly limit meters with a pace marker, time until reset, an ahead/under-pace label, and the session's cost |
turn-receipt | A card under each turn's answer | What the turn cost, its tokens by category, duration, model, the tools that ran, and how much tool output went back to the model |
context-window and plan-usage also add a short entry to the status line.
In a Claude Code terminal session:
/plugin install context-window --marketplace oakker-myo/claude-code-mods
/plugin install plan-usage --marketplace oakker-myo/claude-code-mods
/plugin install turn-receipt --marketplace oakker-myo/claude-code-mods
Answer y to add the marketplace, then pick a scope (the user scope loads them in every session). Installed at the user scope from a terminal, they also load in the desktop app's Code tab.
Or from a shell:
claude plugin marketplace add oakker-myo/claude-code-mods
claude plugin install context-window@claude-code-mods --scope user
claude plugin install plan-usage@claude-code-mods --scope user
claude plugin install turn-receipt@claude-code-mods --scope user
| Command | Effect |
|---|---|
/context-window | Open or close the context-window pane |
/plan-usage | Show or hide the plan-usage band |
/turn-receipt | Show or hide the receipts under each turn |
/compact.Context window · 11%.│: how much of the window's time has passed. Usage left of it is under pace.Plan meters appear on Pro and Max plans after the first reply of a session.
A small card under the answer that closes each turn:
Tools calls output fed back
Read 2 ██████████ ≈261
Bash 3 ███████ ≈182
+ 2 more (ExitPlanMode, ToolSearch) · 2 calls ≈457
─────────────────────────────────────────────
7 calls · ≈900 tokens fed back
The four tools with the most output get a row; the rest, and Claude's own bookkeeping tools (ToolSearch, plan mode, todo lists), fold into one "+ more" line. A turn with fewer than three calls and under 1k tokens of output shows one line instead, e.g. Tools Bash ×2 · ≈180 fed back.
A turn that ends on a tool call with no closing text has no answer to hang a receipt under, so it shows none.
Claude Code with plugin hooks modules (2.1.293 or later).
Each mod is a plugin folder: .claude-plugin/plugin.json, a hooks module in hooks/, and its state contract in types/. The repository root holds the marketplace file, .claude-plugin/marketplace.json.
claude plugin validate .
claude plugin validate context-window
claude plugin test context-window
claude plugin test plan-usage
claude plugin test turn-receipt
To try a change without installing, start a session with claude --plugin-dir ./context-window --plugin-dir ./plan-usage --plugin-dir ./turn-receipt. If you installed from a clone of this folder (claude plugin marketplace add <folder>), Claude Code installs from the clone's last commit, so a change reaches your sessions once it is committed:
git commit -am "…"
claude plugin update <mod>@claude-code-mods
then run /reload-plugins in a running session.
See CHANGELOG.md for release notes.
hooks/register.tsx 192 lines1import { atom, read, update } from 'claude-code'
2import type { EngineInterface, Register } from 'claude-code'
3
4import type { Category, Snapshot } from '../types'
5import { GLYPH, compact, crossed, pct, rows, tone, waffle } from './format'
6
7const PANE = 'context-window'
8const snapshot = atom({ plugin: 'context-window', key: 'snapshot' } as const, null)
9const paneOpen = atom({ plugin: 'context-window', key: 'paneOpen' } as const, false)
10
11const MARKS = [50]
12const ROW = 40
13const WAFFLE = { cols: 25, rows: 20 }
14const ORDER: Record<Category['kind'], number> = { used: 0, buffer: 1, free: 2, deferred: 3 }
15
16function title(snap: Snapshot | null): string {
17 return snap?.percent === undefined ? 'Context window' : `Context window · ${snap.percent}%`
18}
19
20// The engine's pane list can miss a pane a remote surface (the desktop app)
21// is showing, so the mod keeps its own record: set on open, cleared by ui.close.
22async function isOpen($: EngineInterface): Promise<boolean> {
23 return (await read($, paneOpen)) || (await $.ui.panes()).some(p => p.id === PANE)
24}
25
26async function openPane($: EngineInterface, snap: Snapshot | null): Promise<void> {
27 await update($, paneOpen, () => true)
28 await $.ui.open({ id: PANE, title: title(snap) })
29}
30
31async function measure($: EngineInterface): Promise<Snapshot> {
32 const usage = await $.session.usage({ breakdown: 'summary' })
33 const categories = (usage.context.breakdown?.categories ?? [])
34 .map(c => ({ name: c.name, tokens: c.tokens, color: c.color, kind: c.kind }))
35 .sort((a, b) => ORDER[a.kind] - ORDER[b.kind])
36 const fresh: Snapshot = {
37 tokens: usage.context.tokens,
38 window: usage.context.window,
39 percent: usage.context.percent,
40 categories,
41 }
42 await update($, snapshot, () => fresh)
43 $.ui.status(
44 fresh.percent === undefined
45 ? undefined
46 : `ctx ${fresh.percent}% ${compact(fresh.tokens ?? 0)}/${compact(fresh.window)}`,
47 )
48 // Opening an open pane retitles it; a closed one stays closed.
49 if (await read($, paneOpen)) await $.ui.open({ id: PANE, title: title(fresh) })
50
51 return fresh
52}
53
54export const register: Register = on => {
55 on('session.start', async ($, e, next) => {
56 const ran = await next(e)
57 await $.command.register({
58 name: 'context-window',
59 description: 'Open or close the context-window pane',
60 })
61 const fresh = await measure($)
62 await openPane($, fresh)
63
64 return ran
65 })
66
67 on('session.measure', async ($, e, next) => {
68 if (e.changed.includes('context')) {
69 const before = await read($, snapshot)
70 const fresh = await measure($)
71 if (crossed(before?.percent, fresh.percent, MARKS) !== undefined) {
72 $.ui.toast(`Context window ${fresh.percent}% full; /compact frees room`)
73 }
74 }
75
76 return next(e)
77 })
78
79 on('command.run', { command: 'context-window' }, async $ => {
80 if (await isOpen($)) {
81 await update($, paneOpen, () => false)
82 await $.ui.close({ id: PANE })
83 return { text: 'Context-window pane closed.' }
84 }
85 await openPane($, await read($, snapshot))
86
87 return { text: 'Context-window pane opened.' }
88 })
89
90 on('ui.close', { id: PANE }, async ($, e, next) => {
91 await update($, paneOpen, () => false)
92
93 return next(e)
94 })
95
96 on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
97 const { Box, Text } = $.ui.resolve(e)
98 const snap = await read($, snapshot)
99 if (snap === null) {
100 return <Text dimColor>Measuring…</Text>
101 }
102
103 const percent = snap.percent
104 const list = rows(snap.categories)
105 const deferred = snap.categories.filter(c => c.kind === 'deferred').reduce((s, c) => s + c.tokens, 0)
106 // Largest first; each keeps the colour rows() gave it, so a category's colour holds as the order shifts.
107 const used = list.filter(c => c.kind === 'used').sort((a, b) => b.tokens - a.tokens)
108 const rest = [...list.filter(c => c.kind === 'free'), ...list.filter(c => c.kind === 'buffer')]
109 const usedTokens = used.reduce((s, c) => s + c.tokens, 0)
110 const usedShare = used.reduce((s, c) => s + c.share, 0)
111
112 // The whole window as a fixed waffle, each cell 0.2% of it, in the legend's order.
113 const grid = (
114 <Box flexDirection="column">
115 {waffle(list, WAFFLE.cols, WAFFLE.rows).map((line, y) => (
116 <Text key={`w-${y}`}>
117 {line.map(sp => (
118 <Text color={sp.hex} dimColor={sp.dim}>
119 {sp.text}
120 </Text>
121 ))}
122 </Text>
123 ))}
124 <Box marginTop={1}>
125 <Text dimColor>each cell is {100 / (WAFFLE.cols * WAFFLE.rows)}% of the window</Text>
126 </Box>
127 </Box>
128 )
129
130 const entry = (c: (typeof list)[number]) => (
131 <Box key={c.name} width={ROW} flexDirection="row">
132 <Text color={c.hex} dimColor={c.kind === 'free'}>
133 {GLYPH[c.kind].repeat(2)}
134 {' '}
135 </Text>
136 <Box flexGrow={1}>
137 <Text dimColor={c.kind !== 'used'} wrap="truncate">
138 {c.name}
139 </Text>
140 </Box>
141 <Text bold={c.kind === 'used'} dimColor={c.kind !== 'used'}>
142 {compact(c.tokens).padStart(5)}
143 </Text>
144 <Text dimColor>{pct(c.share).padStart(7)}</Text>
145 </Box>
146 )
147
148 const legend = (
149 <Box flexDirection="column">
150 <Text>
151 <Text bold>Used</Text>
152 <Text dimColor>
153 {' '}
154 {compact(usedTokens)} · {pct(usedShare)}
155 </Text>
156 </Text>
157 <Box flexDirection="column" marginTop={1}>
158 {used.map(entry)}
159 </Box>
160 <Box flexDirection="column" marginTop={1}>
161 {rest.map(entry)}
162 </Box>
163 </Box>
164 )
165
166 return (
167 <Box flexDirection="column" paddingX={1}>
168 <Text>
169 <Text bold color={percent === undefined ? 'inactive' : tone(percent)}>
170 {percent === undefined ? 'Waiting for first reply' : `${percent}% used`}
171 </Text>
172 <Text dimColor>
173 {' '}
174 {snap.tokens === undefined ? '—' : compact(snap.tokens)} / {compact(snap.window)} tokens
175 </Text>
176 </Text>
177 <Box marginTop={1} flexDirection="row" flexWrap="wrap" columnGap={4} rowGap={1}>
178 {legend}
179 {grid}
180 </Box>
181 {deferred > 0 ? (
182 <Box marginTop={1}>
183 <Text dimColor italic>
184 + {compact(deferred)} of tool schemas load on demand and sit outside the window
185 </Text>
186 </Box>
187 ) : null}
188 </Box>
189 )
190 })
191}
192hooks/format.ts 102 lines1import type { Category } from '../types'
2
3/** Mid-tone categorical colours that read on light and dark backgrounds alike. */
4export const PALETTE = ['#d97757', '#6c8cf5', '#3fb3a8', '#b77ee0', '#9b7653', '#5fae5f', '#e06c8a', '#4aa3df']
5export const TRACK = '#8b949e'
6export const BUFFER = '#e0a43a'
7
8export const GLYPH: Record<Category['kind'], string> = {
9 used: '█',
10 buffer: '▒',
11 free: '░',
12 deferred: '·',
13}
14
15export type Row = Category & { hex: string; share: number }
16
17/** The in-window rows in drawing order, each with its colour and share of the window. */
18export function rows(categories: Category[]): Row[] {
19 const inWindow = categories.filter(c => c.kind !== 'deferred' && c.tokens > 0)
20 const total = inWindow.reduce((s, c) => s + c.tokens, 0) || 1
21 let used = 0
22 return inWindow.map(c => ({
23 ...c,
24 hex: c.kind === 'used' ? PALETTE[used++ % PALETTE.length]! : c.kind === 'buffer' ? BUFFER : TRACK,
25 share: (c.tokens / total) * 100,
26 }))
27}
28
29export function compact(n: number): string {
30 if (n >= 1_000_000) return `${+(n / 1_000_000).toFixed(1)}M`
31 if (n >= 1_000) return `${Math.round(n / 1_000)}k`
32 return String(n)
33}
34
35export function pct(share: number): string {
36 return share >= 10 ? `${Math.round(share)}%` : share >= 0.1 ? `${share.toFixed(1)}%` : '<0.1%'
37}
38
39export function tone(percent: number): 'success' | 'warning' | 'error' {
40 return percent >= 90 ? 'error' : percent >= 70 ? 'warning' : 'success'
41}
42
43/**
44 * Splits `width` units across `sizes` in proportion (largest remainder),
45 * giving each index in `atLeast` a floor of `min` so small rows stay visible.
46 */
47export function split(sizes: number[], width: number, atLeast: boolean[], min = 1): number[] {
48 const total = sizes.reduce((s, n) => s + n, 0)
49 if (total === 0 || width <= 0) return sizes.map(() => 0)
50
51 const exact = sizes.map(n => (n / total) * width)
52 const out = exact.map((x, i) => Math.max(atLeast[i] ? min : 0, Math.floor(x)))
53 let left = width - out.reduce((s, n) => s + n, 0)
54
55 const order = exact.map((x, i) => ({ i, rem: x - Math.floor(x) })).sort((a, b) => b.rem - a.rem)
56 for (let k = 0; left > 0 && k < order.length; k++, left--) out[order[k]!.i]! += 1
57
58 while (left < 0) {
59 const big = out.indexOf(Math.max(...out))
60 out[big]! -= 1
61 left += 1
62 }
63 return out
64}
65
66export function crossed(
67 before: number | undefined,
68 after: number | undefined,
69 marks: number[],
70): number | undefined {
71 if (after === undefined) return undefined
72 return [...marks].sort((a, b) => b - a).find(m => after >= m && (before ?? 0) < m)
73}
74
75/** A run of text in one style; a design is a list of lines, each a list of spans. */
76export type Span = { text: string; hex?: string; dim?: boolean }
77export type Lines = Span[][]
78
79const of = (list: Row[], kind: Row['kind']) => list.filter(r => r.kind === kind)
80
81/**
82 * The window as a waffle of `cols`×`rowsDown` one-character cells, each an equal
83 * share of it, in reading order and the legend's: the used categories largest
84 * first, then free space, then the autocompact buffer.
85 */
86export function waffle(list: Row[], cols = 25, rowsDown = 20): Lines {
87 const used = of(list, 'used').sort((a, b) => b.tokens - a.tokens)
88 const order = [...used, ...of(list, 'free'), ...of(list, 'buffer')]
89 const counts = split(order.map(r => r.tokens), cols * rowsDown, order.map(() => false))
90 const cells = order.flatMap((r, i) => Array.from({ length: counts[i]! }, () => r))
91 return Array.from({ length: rowsDown }, (_, y) => {
92 const line: Span[] = []
93 for (const r of cells.slice(y * cols, (y + 1) * cols)) {
94 const glyph = r.kind === 'used' ? '█' : GLYPH[r.kind]
95 const last = line[line.length - 1]
96 if (last && last.hex === r.hex && last.text[0] === glyph) last.text += glyph
97 else line.push({ text: glyph, hex: r.hex, dim: r.kind === 'free' })
98 }
99 return line
100 })
101}
102types/index.d.ts 20 lines1export type Category = {
2 name: string
3 tokens: number
4 color: string
5 kind: 'used' | 'free' | 'buffer' | 'deferred'
6}
7
8export type Snapshot = {
9 tokens?: number
10 window: number
11 percent?: number
12 categories: Category[]
13}
14
15declare module 'claude-code' {
16 interface PluginState {
17 'context-window': { snapshot: Snapshot | null; paneOpen: boolean }
18 }
19}
20