One row above the prompt: how much of the 5-hour and weekly usage limits is used, in percent, with the time until each resets.

<h1 align="center">Claude Code Mods</h1>
<a href="https://github.com/T-AI-Labs/claude-code-mods/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/T-AI-Labs/claude-code-mods/ci.yml?branch=main&style=flat-square&label=ci" alt="CI"></a> <a href="https://github.com/T-AI-Labs/claude-code-mods/releases"><img src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2FT-AI-Labs%2Fclaude-code-mods%2Fmain%2Fcontext-usage%2F.claude-plugin%2Fplugin.json&query=%24.version&prefix=v&label=context-usage&style=flat-square" alt="context-usage version"></a> <a href="https://github.com/T-AI-Labs/claude-code-mods/releases"><img src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2FT-AI-Labs%2Fclaude-code-mods%2Fmain%2Fcache-meter%2F.claude-plugin%2Fplugin.json&query=%24.version&prefix=v&label=cache-meter&style=flat-square" alt="cache-meter version"></a> <a href="https://github.com/T-AI-Labs/claude-code-mods/releases"><img src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2FT-AI-Labs%2Fclaude-code-mods%2Fmain%2Fcatalog-pane%2F.claude-plugin%2Fplugin.json&query=%24.version&prefix=v&label=catalog-pane&style=flat-square" alt="catalog-pane version"></a> <a href="https://github.com/T-AI-Labs/claude-code-mods/releases"><img src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2FT-AI-Labs%2Fclaude-code-mods%2Fmain%2Fcontext-meter%2F.claude-plugin%2Fplugin.json&query=%24.version&prefix=v&label=context-meter&style=flat-square" alt="context-meter version"></a> <a href="https://github.com/T-AI-Labs/claude-code-mods/releases"><img src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2FT-AI-Labs%2Fclaude-code-mods%2Fmain%2Fusage-limits%2F.claude-plugin%2Fplugin.json&query=%24.version&prefix=v&label=usage-limits&style=flat-square" alt="usage-limits version"></a> <a href="LICENSE"><img src="https://img.shields.io/github/license/T-AI-Labs/claude-code-mods?style=flat-square" alt="License"></a>
Add the marketplace once, then install the mods you want with the first command in their row of the Mods table. To update, run the second lines: the marketplace first, then each mod. The commands work in any shell, or inside Claude Code with /plugin in place of claude plugin. New sessions load the changes.
claude plugin marketplace add T-AI-Labs/claude-code-mods
claude plugin marketplace update T-AI-Labs
The mods use Claude Code's function-hook plugin API, which is in early access and may change between releases. They are built and tested against Claude Code 2.1.295, the engine in the Claude desktop app 2.31226.1.
context-usage already contains context-meter and usage-limits: install either it or those two, not both.
<table> <tr><th>Mod</th><th>Description</th><th width="35%">Preview</th></tr> <tr><td><a href="#context-usage">context‑usage</a></td><td>
Start here. The context fill with the auto-compact threshold, Compact and Clear, and the 5-hour and weekly limits beneath it.
claude plugin install context-usage@T-AI-Labs
claude plugin update context-usage@T-AI-Labs
</td><td><img src=".docs/context-usage.svg" alt="The context-usage rows" width="320"></td></tr> <tr><td><a href="#context-meter">context‑meter</a></td><td>
The context row of context-usage on its own.
claude plugin install context-meter@T-AI-Labs
claude plugin update context-meter@T-AI-Labs
</td><td><img src=".docs/context-meter.svg" alt="The context-meter row" width="320"></td></tr> <tr><td><a href="#usage-limits">usage‑limits</a></td><td>
The usage row of context-usage on its own.
claude plugin install usage-limits@T-AI-Labs
claude plugin update usage-limits@T-AI-Labs
</td><td><img src=".docs/usage-limits.svg" alt="The usage-limits row" width="320"></td></tr> <tr><td><a href="#cache-meter">cache‑meter</a></td><td>
How much of each turn the prompt cache served and how long it stays warm, with a switch that keeps it warm while you are away.
claude plugin install cache-meter@T-AI-Labs
claude plugin update cache-meter@T-AI-Labs
</td><td><img src=".docs/cache-meter.svg" alt="The cache-meter row" width="320"></td></tr> <tr><td><a href="#catalog-pane">catalog‑pane</a></td><td>
A pane listing every skill, command, agent, mod, plugin, settings hook, MCP server and tool, with usage, token cost and buttons to use or manage each one.
claude plugin install catalog-pane@T-AI-Labs
claude plugin update catalog-pane@T-AI-Labs
</td><td><img src=".docs/catalog-pane.svg" alt="The catalog pane" width="320"></td></tr> </table>
context-meter and usage-limits in one mod: the context row and the usage row beneath it. Both work as described under context-meter and usage-limits. To switch from the two separate mods, install context-usage, uninstall context-meter and usage-limits, and pick the threshold again.
The rows sit in the band above the prompt and cost no tokens: they only read figures Claude Code already has. In the terminal, ctrl+x tab moves into the band: Tab walks the controls, Enter presses a button, the arrow keys pick a threshold. ctrl+x ctrl+a or the band's [-] mark collapses it.
| Option | Values | Default | Effect |
|---|---|---|---|
display | gauge, text | gauge | gauge draws a five-segment gauge before each percentage; text leaves it out. |
details | true, false | true | Shows the figures in parentheses. |
usagePosition | below, above | below | Puts the usage row under or on top of the context row. |
'{"display":"text","usagePosition":"above"}' | claude plugin configure context-usage@T-AI-Labs --values-stdin
That is PowerShell; in cmd, use echo {"display":"text"} | …. Options you leave out keep their value, the command without --values-stdin shows what is set, and a new session picks up the change. --config display=text sets an option while installing, and in a terminal session the options are rows of the /config menu.
| Element | What it shows |
|---|---|
| Context | Fill of the context window, with tokens used and window size. Yellow within 15 points of the threshold, red at it; with Auto off, the same against 100 %. |
| Auto | The fill at which the mod compacts on its own: Off, 97, 90, 70, 60 or 50 %. Off leaves it to you and to Claude Code's built-in auto-compaction. Kept across sessions. |
| Compact | Runs /compact now. |
| Clear | Runs /clear. |
The row sits in the band above the prompt and costs no tokens: it only reads figures Claude Code already has. In the desktop app it is two lines high so the app's taller buttons fit. In the terminal, ctrl+x tab moves into the band: Tab walks the controls, Enter presses a button, the arrow keys pick a threshold. ctrl+x ctrl+a or the band's [-] mark collapses it.
Until the first response of a session, and again after a clear, the fill reads 0%: the engine counts the system prompt and tools only once a response arrives.
| Option | Values | Default | Effect |
|---|---|---|---|
display | gauge, text | gauge | gauge draws a five-segment gauge before the percentage; text leaves it out. |
details | true, false | true | Shows the figures in parentheses. |
'{"display":"text","details":"false"}' | claude plugin configure context-meter@T-AI-Labs --values-stdin
Set them as for context-usage. The row needs about 62 columns with the defaults; on a narrower window the buttons wrap to a second line. details off saves about 11 columns, display set to text about 6:
After each turn the mod compares the fill with the threshold and runs /compact once it is reached. It fires again only after the fill has dropped below the threshold, so a compaction that lands above it does not loop. Claude Code's built-in auto-compaction still runs at its own limit, so a threshold above that limit never fires.
Every compaction costs tokens, whether you press Compact or the threshold triggers it: /compact is a model request that summarizes the conversation, and the next turn starts on a cold cache. To keep usage down, leave the threshold high and compact by hand when it suits you.
A gauge for each rate-limit window, with the percentage used and the time until it resets: 5h for the 5-hour limit, Week for the weekly one. Yellow from 75 %, red from 90 %.
The row sits in the band above the prompt and costs no tokens. ctrl+x ctrl+a or the band's [-] mark collapses it in the terminal.
Claude Code reports the limits only on a subscription plan, with each response. Until the first one, and right after a /clear, the row shows the last reading, with a window that has reset since at 0 %. A window that never had a reading shows –.
Sessions running side by side share their readings through a file on your machine, once a minute and at no token cost, so an idle session still shows what the others used. context-usage and usage-limits keep separate stores and do not share with each other.
| Option | Values | Default | Effect |
|---|---|---|---|
display | gauge, text | gauge | gauge draws a five-segment gauge before each percentage; text leaves it out. |
details | true, false | true | Shows the reset times in parentheses. |
'{"display":"text"}' | claude plugin configure usage-limits@T-AI-Labs --values-stdin
Set them as for context-usage. Give the row mods the same display and details to keep their columns aligned.
| Element | What it shows |
|---|---|
| Cache | Share of the last turn's input tokens served from the prompt cache, with tokens read and total input. Yellow below 40 %; – until the first response and after a clear. |
| warm / cold | How long the cache stays valid: five minutes after the last request starts, or an hour once the session has used the hour-long cache. cold means the next turn writes the whole context again at full price, the cheapest moment to compact or clear. |
| Keep warm | Off by default. Refreshes the cache shortly before it lapses, for up to keepWarmMinutes after the last turn, and counts the refreshes. Stops when a refresh finds the cache already gone. |
The row sits in the band above the prompt and costs no tokens; only Keep warm's refreshes are model requests. Keep warm is a text link in the desktop app and a button elsewhere. In the terminal, ctrl+x tab moves into the band, Tab walks the controls and Enter presses one. ctrl+x ctrl+a or the band's [-] mark collapses it.
Before 0.4.0 cache-meter also showed the context fill, threshold, Compact and Clear. They moved to context-meter, which an update does not install: install it and pick the threshold again.
| Option | Values | Default | Effect |
|---|---|---|---|
display | gauge, text | gauge | gauge draws a five-segment gauge before the percentage; text leaves it out. |
details | true, false | true | Shows the figures in parentheses. |
keepWarmMinutes | 15, 30, 60, 120 | 60 | How long after the last turn Keep warm goes on refreshing. |
'{"keepWarmMinutes":"120"}' | claude plugin configure cache-meter@T-AI-Labs --values-stdin
Set them as for context-usage.
Every turn sends the whole conversation again. Cached tokens cost about a tenth of the input price, a twentieth on Claude Opus 5.5; writing them to the cache costs 1.25 times the input price. The cache lapses after a pause, on a model switch, and when something early in the context changes, such as CLAUDE.md or the tools.
Each refresh reads the cached context once at the cache price, plus a one-word reply. With 200k tokens on Claude Opus 5.5 that is about $0.04, against about $1.00 for writing the context again after it went cold. At one refresh every four and a half minutes, an hour costs about half a rewrite: worth it if you come back, lost if you don't. On a subscription the refreshes count against the usage limits.
A pane with one tab per category: Skills, Commands, Agents, Mods, Plugins, Hooks (from the settings files), MCP servers and built-in Tools.
/catalog opens the pane, in the desktop app and in the terminal; /catalog mods opens a category, /catalog <text> a search. Each row shows the entry's origin, how often it was used in total and in the last 30 days, and for plugin parts the tokens it adds to every session. Usage is counted from the install of the mod on. On the desktop you can filter by text and origin and sort:
| Sort | Order |
|---|---|
| Most used, Recently used, Name | By usage, or alphabetically. |
| Clean-up | Costly and unused entries first. |
| GitHub stars, Trending, GitHub forks, Latest GitHub push | By the plugin's repository; Trending is stars gained per month. |
| Installs, Newest installed | By the official directory's install count, or by install date. |
Pressing an entry opens its detail: usage over 7 and 30 days, token cost, version and install dates, what a mod hooks and calls, the repository and the full description. Explain with Haiku sums up in three sentences what the entry is for. The buttons depend on the kind: insert or run a skill or command, insert an agent, MCP server or tool into the prompt, update, disable or uninstall a plugin or mod, remove a local MCP server. Uninstalling and removing ask first.
| Option | Values | Default | Effect |
|---|---|---|---|
language | any language name | English | The language Explain with Haiku answers in. |
githubStats | true, false | true | Fetches the GitHub stats of each plugin's repository once a day. |
'{"language":"German"}' | claude plugin configure catalog-pane@T-AI-Labs --values-stdin
Set them as for context-usage.
githubStats.claude plugin details once per plugin version for its token cost, claude plugin validate once per mod version, and update, disable, enable or uninstall when you press those buttons.Everything else comes from Claude Code and the configuration files, and is kept in the mod's own store.
hooks/register.tsx 250 lines1import { atom, read, update } from 'claude-code'
2import type { Color, Elements, EngineInterface, Register } from 'claude-code'
3
4import type { Reading, UsageWindow } from '../types'
5
6const LABELS: Record<string, string> = {
7 // Padded so the hours line up with a two-digit window such as 24h.
8 five_hour: ' 5h',
9 seven_day: 'Week',
10 spend_limit: 'Spend',
11}
12const ORDER = ['five_hour', 'seven_day', 'spend_limit']
13const ALWAYS = ['five_hour', 'seven_day']
14const MINUTE = 60_000
15const HOUR = 60 * MINUTE
16const DAY = 24 * HOUR
17const STORE_KEY = 'reading'
18
19// Shared with cache-meter, context-meter and usage-limits so the gauges of all rows line up.
20const LABEL_WIDTH = 7
21const SEGMENTS = 5
22const PERCENT_WIDTH = 4
23const DETAIL_WIDTH = 10
24
25type Tags = Pick<Elements['terminal'], 'Box' | 'Text'>
26type Layout = { hasGauge: boolean; hasDetails: boolean }
27type Cell = {
28 label: string
29 percent: number | null
30 tone: Color | undefined
31 detail: string
32}
33
34const windows = atom({ plugin: 'usage-limits', key: 'windows' } as const, [])
35const now = atom({ plugin: 'usage-limits', key: 'now' } as const, 0)
36
37const labelOf = (kind: string) => LABELS[kind] ?? kind.replaceAll('_', ' ')
38
39const rankOf = (kind: string) => {
40 const rank = ORDER.indexOf(kind)
41
42 return rank === -1 ? ORDER.length : rank
43}
44
45const toneOf = (percent: number): Color | undefined =>
46 percent >= 90 ? 'error' : percent >= 75 ? 'warning' : undefined
47
48const span = (duration: number) => {
49 const days = Math.floor(duration / DAY)
50 const hours = Math.floor((duration % DAY) / HOUR)
51 const minutes = Math.max(1, Math.floor((duration % HOUR) / MINUTE))
52
53 if (days > 0) {
54 return `${days}d ${hours}h`
55 }
56
57 return hours > 0 ? `${hours}h ${minutes}m` : `${minutes}m`
58}
59
60const untilReset = (resetsAt: string | undefined, at: number) => {
61 const left = resetsAt === undefined ? Number.NaN : Date.parse(resetsAt) - at
62
63 return Number.isNaN(left) ? '' : `(${span(left)})`
64}
65
66const hasReset = (one: UsageWindow, at: number) =>
67 one.resetsAt !== undefined && Date.parse(one.resetsAt) <= at
68
69// The next window starts no earlier than this one resets, so it resets at least a whole window later.
70const SAME_WINDOW = HOUR
71
72const newer = (first: UsageWindow, second: UsageWindow) => {
73 const gap = Date.parse(first.resetsAt ?? '') - Date.parse(second.resetsAt ?? '')
74
75 // Without a reset time there is no telling which is newer, so the session's own reading stays.
76 if (Number.isNaN(gap)) {
77 return first
78 }
79
80 if (Math.abs(gap) > SAME_WINDOW) {
81 return gap > 0 ? first : second
82 }
83
84 return second.percentUsed > first.percentUsed ? second : first
85}
86
87// Every session writes the same store, so the readings of all of them meet there.
88const merge = (...lists: (readonly UsageWindow[])[]) => {
89 const byKind = new Map<string, UsageWindow>()
90
91 for (const one of lists.flat()) {
92 const held = byKind.get(one.kind)
93 byKind.set(one.kind, held === undefined ? one : newer(held, one))
94 }
95
96 return [...byKind.values()].sort((a, b) => rankOf(a.kind) - rankOf(b.kind))
97}
98
99const cellsOf = (list: readonly UsageWindow[], at: number): Cell[] =>
100 [...new Set([...ALWAYS, ...list.map(one => one.kind)])]
101 .sort((a, b) => rankOf(a) - rankOf(b))
102 .map(kind => {
103 const one = list.find(held => held.kind === kind)
104
105 if (one === undefined) {
106 return { label: labelOf(kind), percent: null, tone: undefined, detail: '' }
107 }
108
109 // A window past its reset has started over, but the engine reports that only with the next response.
110 if (hasReset(one, at)) {
111 return { label: labelOf(kind), percent: 0, tone: undefined, detail: '' }
112 }
113
114 return {
115 label: labelOf(kind),
116 percent: one.percentUsed,
117 tone: toneOf(one.percentUsed),
118 detail: untilReset(one.resetsAt, at),
119 }
120 })
121
122const meter = ({ Box, Text }: Tags, layout: Layout, one: Cell) => {
123 const filled =
124 one.percent === null
125 ? 0
126 : Math.max(
127 0,
128 Math.min(SEGMENTS, Math.round((one.percent / 100) * SEGMENTS)),
129 )
130
131 return (
132 <Box flexDirection="row" flexShrink={0}>
133 <Box
134 minWidth={LABEL_WIDTH}
135 marginRight={1}
136 flexShrink={0}
137 >
138 <Text dimColor>{one.label}</Text>
139 </Box>
140 {layout.hasGauge && (
141 <Box minWidth={SEGMENTS} marginRight={1} flexShrink={0}>
142 <Text color={one.tone}>{'▮'.repeat(filled)}</Text>
143 <Text dimColor>{'▯'.repeat(SEGMENTS - filled)}</Text>
144 </Box>
145 )}
146 <Box
147 minWidth={PERCENT_WIDTH}
148 marginRight={1}
149 flexShrink={0}
150 justifyContent="flex-end"
151 >
152 <Text color={one.percent === null ? 'inactive' : one.tone}>
153 {one.percent === null ? '–' : `${Math.round(one.percent)}%`}
154 </Text>
155 </Box>
156 {layout.hasDetails && (
157 <Box minWidth={DETAIL_WIDTH} marginRight={1} flexShrink={0}>
158 <Text dimColor>{one.detail}</Text>
159 </Box>
160 )}
161 </Box>
162 )
163}
164
165const restore = async ($: EngineInterface) => {
166 const at = await $.clock.now()
167 const stored = (await $.store.get(STORE_KEY)) as Reading | undefined
168 await update($, now, () => at)
169
170 if (stored !== undefined) {
171 await update($, windows, () => stored.windows)
172 }
173}
174
175const refresh = async ($: EngineInterface, list?: readonly UsageWindow[]) => {
176 // The engine has no reading before the first response of a session.
177 if (list !== undefined && list.length === 0) {
178 return restore($)
179 }
180
181 const at = await $.clock.now()
182 const stored = (await $.store.get(STORE_KEY)) as Reading | undefined
183 await update($, now, () => at)
184
185 // Without a measurement this only takes in what other sessions stored since.
186 if (list === undefined) {
187 await update($, windows, held => merge(held, stored?.windows ?? []))
188
189 return
190 }
191
192 // A measurement can leave a window out, which then keeps its last reading.
193 const merged = merge(list, stored?.windows ?? [])
194 await update($, windows, () => merged)
195 await $.store.set(STORE_KEY, { windows: merged })
196}
197
198export const register: Register = (on, options) => {
199 const layout: Layout = {
200 hasGauge: options.display !== 'text',
201 hasDetails: options.details !== false,
202 }
203
204 on('session.start', async ($, e, next) => {
205 const usage = await $.session.usage()
206 await refresh($, usage.rateLimits)
207
208 $.clock.every(MINUTE, () => void refresh($))
209
210 return next(e)
211 })
212
213 // A /clear wipes every plugin's state after session.end and raises no session.start, only this.
214 on('classic.SessionStart', async ($, e, next) => {
215 if (e.source === 'clear') {
216 await restore($).catch(() => undefined)
217 }
218
219 return next(e)
220 })
221
222 on('session.measure', async ($, e, next) => {
223 await refresh($, e.rateLimits)
224
225 return next(e)
226 })
227
228 on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
229 const below = await next(e)
230
231 if (e.props.hasSurvey) {
232 return below
233 }
234
235 const { Box, Text } = $.ui.resolve(e)
236 const list = await read($, windows)
237 const at = await read($, now)
238
239 // Drawn under the rows beneath it in the chain, so the context row stays on top whatever the install order.
240 return (
241 <Box flexDirection="column">
242 {below}
243 <Box flexDirection="row" flexWrap="wrap">
244 {cellsOf(list, at).map(one => meter({ Box, Text }, layout, one))}
245 </Box>
246 </Box>
247 )
248 })
249}
250types/index.d.ts 17 lines1export type UsageWindow = {
2 kind: string
3 percentUsed: number
4 resetsAt?: string
5}
6
7export type Reading = { windows: UsageWindow[] }
8
9declare module 'claude-code' {
10 interface PluginState {
11 'usage-limits': {
12 windows: UsageWindow[]
13 now: number
14 }
15 }
16}
17