Shows context-window usage and five-hour and weekly limit usage in the prompt footer

Three Claude Code mods for keeping long sessions healthy and readable:
| Mod | What it does |
|---|---|
| context-meter | Shows context-window usage in the prompt footer (207k / 1.0M (21%)), followed by five-hour and weekly limit usage when your plan reports it (· 5h 34% · 7d 12%), and shows a notice once when context usage passes 80%. |
| context-handoff | When context is 60–70% full, Claude picks a natural stopping point and writes itself a handoff note. The mod then cuts the note-writing out of the transcript (a rewind), runs /compact, and has Claude read the note and carry on. What binds the work (your rules and rulings, other sessions' specs) is kept in a ledger the mod carries across the handoff unchanged. The note is deleted once Claude has read it back. |
| prompt-timestamp | Puts the local date and time at the front of every prompt you type ([10-02 14:03 EDT] fix the bug), so the transcript and Claude both see when it was sent. |
All three are function-hook mods (plugins written as TypeScript hook modules). That API is early access, so it can change between Claude Code releases. context-meter was built and tested on Claude Code 2.1.289; context-handoff 0.2.0 needs 2.1.302 or later, since it relies on behavior confirmed there (a typed prompt reaching prompt.submit at typing time, the sending session's wrapper on a delivery); prompt-timestamp needs 2.1.287 or later.
Inside Claude Code:
/plugin marketplace add Vibe-Commit/claude-context-mods
/plugin install context-meter@claude-context-mods
/plugin install context-handoff@claude-context-mods
/plugin install prompt-timestamp@claude-context-mods
Or from a shell:
claude plugin marketplace add Vibe-Commit/claude-context-mods
claude plugin install context-meter@claude-context-mods
claude plugin install context-handoff@claude-context-mods
claude plugin install prompt-timestamp@claude-context-mods
Restart Claude Code afterwards (or run /reload-plugins). Install any or all of them; they work independently.
claude plugin marketplace update claude-context-mods
claude plugin update context-handoff@claude-context-mods # restart to apply
claude plugin uninstall context-handoff@claude-context-mods
Handoff tool with two inputs. content is the state, as a markdown note with fixed sections: status (verified or not, with proof), the next action, pending work (citing the ledger items that bind it), failed approaches, open issues, git and environment state, and commands to verify. ledger is a list of changes to the ledger: add, amend or retire an item. The note is saved to ~/.claude/handoffs/<session-id>/handoff-N.md, numbered past every note already in the folder so a restart or a retry never overwrites one. After Claude's state it carries two sections the mod writes itself: the ledger as it will stand once this handoff completes, and the messages since the last handoff that no ledger item cites (your typed prompts up to 600 characters in full, everything else as a line with its first 100 characters; the list is capped at about 8,000 characters, with the rest left in ledger.json). The Handoff call is never refused over the ledger: an op that cannot be applied, a source that cannot be found or a quote that is not in the record is reported in the result and in the note, and the call goes through. Claude is then held to ending its turn./compact for this, and the summary only covers the transcript up to the Handoff call, so writing the note never ends up in context. A Handoff call that was refused earlier in the same turn is cut out too./compact, a background task finishing), Claude still reads the note before it acts.Handoff call until the note is read back, messages from other sessions, teammates, relays and Remote Control are held instead of queued, so none starts or joins a turn ahead of the note. Each held message shows as a notice row, and the status line counts them. Claude gets each one exactly once: quoted on the resume prompt, or attached to its read of the note. If the handoff ends any other way, or after 10 minutes, they are sent in one prompt of their own. A prompt you type during the handoff turn is quoted on the resume prompt.The ledger and the record. Rules and rulings decay when each note and summary re-says them shorter, so the mod keeps them itself. ~/.claude/handoffs/<session-id>/ledger.json holds the ledger (your intent and every rule, ruling, spec and decision in force, each with its conditions, who decided and the messages it cites) and the record (every prompt you type, every message from another session and every answer you give to a question, as received and dated; a text over 20,000 characters is cut). Relay events, scheduled tasks, subagents and the mod's own prompts are not recorded. Claude edits the ledger only by add, amend and retire; items it does not mention are carried byte for byte, and the result tells it when the ledger passes 12,000 characters so it can retire or merge items. The /compact summary is told to write only the story, so the note and the summary no longer repeat or contradict each other.
Handoff call are staged and only take effect once the note is read back; an interrupt or a failed compaction discards them./handoff off. A message from another session is recorded when it arrives but stays out of the note, and cannot be cited, until the engine has let it through (if you declined it, it never reaches Claude). A write failure never blocks a prompt, a message or the handoff: the mod keeps the ledger in memory, retries on the next write, and says so in the Handoff result or with a notice.~/.claude/handoffs/<session-id>/) now persists after a handoff and holds ledger.json. Delete it to forget a session's record.Safeguards:
Command: /handoff [status|on|off|now]. status shows the phase, the thresholds, how many handoffs this session has completed, and how many ledger items are in force and messages recorded. now asks for a handoff right away, which is the quickest way to try the mod.
Thresholds (60 / 70 / 75 by default) can be changed per user. You can use /plugin configure context-handoff@claude-context-mods inside Claude Code, or a shell:
echo '{"bandLow":"55","bandHigh":"65","overshoot":"75"}' \
| claude plugin configure context-handoff@claude-context-mods --values-stdin
When you install, Claude Code reports "3 userConfig options not yet set". That's expected: unset options use the defaults.
Each mod has tests:
claude plugin validate plugins/context-handoff
claude plugin test plugins/context-handoff
To work on a mod with hot reload, load it from your checkout with claude --plugin-dir ./plugins/context-handoff, or list the folder in CLAUDE_CODE_PLUGIN_DIRS. Uninstall the marketplace copy first so it doesn't load twice. Bump version in the mod's plugin.json and in .claude-plugin/marketplace.json together. claude plugin validate . checks that they agree.
hooks/register.ts 110 lines1import { atom, read, update } from 'claude-code'
2import type {
3 EngineInterface,
4 Register,
5 SessionContextUsage,
6 SessionRateLimit,
7} from 'claude-code'
8
9import type { Label } from '../types'
10
11const WARN_AT = 80
12
13const label = atom({ plugin: 'context-meter', key: 'label' } as const, null as Label)
14
15let isWarned = false
16
17function fmt(n: number): string {
18 if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(1)}M`
19 if (n >= 1_000) return `${Math.round(n / 1_000)}k`
20 return String(n)
21}
22
23const LIMITS = [
24 { kind: 'five_hour', short: '5h' },
25 { kind: 'seven_day', short: '7d' },
26] as const
27
28function formatContext(context: SessionContextUsage): string {
29 if (context.tokens === undefined || context.percent === undefined) {
30 return `— / ${fmt(context.window)}`
31 }
32
33 return `${fmt(context.tokens)} / ${fmt(context.window)} (${context.percent}%)`
34}
35
36// Only the five-hour and weekly windows; the engine leaves out any it has no reading for.
37function formatLimits(rateLimits: readonly SessionRateLimit[]): string[] {
38 return LIMITS.flatMap(({ kind, short }) => {
39 const limit = rateLimits.find(l => l.kind === kind)
40
41 return limit === undefined ? [] : [`${short} ${Math.round(limit.percentUsed)}%`]
42 })
43}
44
45async function refresh($: EngineInterface): Promise<void> {
46 try {
47 const { context, rateLimits } = await $.session.usage()
48 const text = [formatContext(context), ...formatLimits(rateLimits)].join(' · ')
49 await update($, label, () => text)
50
51 if (context.percent === undefined) {
52 return
53 }
54
55 if (context.percent >= WARN_AT && !isWarned) {
56 isWarned = true
57 $.ui.toast(`Context at ${context.percent}% — consider /compact`)
58 } else if (context.percent < WARN_AT) {
59 isWarned = false
60 }
61 } catch {
62 // A failed usage read leaves the last figure up; it never breaks a turn.
63 }
64}
65
66export const register: Register = on => {
67 // The footer's mode labels draw text as given, with no plugin-name prefix.
68 on('ui.render', { component: 'SessionMode' }, async ($, e, next) => {
69 const text = await read($, label)
70
71 return text === null
72 ? next(e)
73 : next({ ...e, props: { ...e.props, modes: [...e.props.modes, text] } })
74 })
75
76 on('turn.step', async function* ($, e, next) {
77 const step = yield* next(e)
78
79 if (e.agentId === undefined) {
80 await refresh($)
81 }
82
83 return step
84 })
85
86 on('turn.complete', async ($, e, next) => {
87 const done = await next(e)
88 await refresh($)
89
90 return done
91 })
92
93 on('session.start', async ($, e, next) => {
94 const started = await next(e)
95 await refresh($)
96
97 return started
98 })
99
100 on('session.compact', async ($, e, next) => {
101 const compacted = await next(e)
102
103 if (e.agentId === undefined) {
104 await refresh($)
105 }
106
107 return compacted
108 })
109}
110types/index.d.ts 8 lines1export type Label = string | null
2
3declare module 'claude-code' {
4 interface PluginState {
5 'context-meter': { label: Label }
6 }
7}
8