A Claude Code plugin that watches your context window in real-time, predicts when you'll hit the limit, and tells you before it's too late.
> /plugin marketplace add fomyio/claude-context-monitor> /plugin install context-monitor@claude-context-monitor
Repo: fomyio/claude-context-monitor
What's inside
A Claude Code plugin that watches your context window in real time, predicts when you'll hit the limit, and warns you before it's too late โ then makes your /compact actually remember what matters.
Quick start ยท Features ยท How it works ยท Configuration ยท Cost ยท Privacy ยท Contributing
Claude Code's context window fills up โ and when it does, your session ends abruptly, mid-refactor or mid-debug. You get no warning. You just hit a wall.
Three problems, one plugin:
| Problem | What it feels like | How this plugin fixes it |
|---|---|---|
| No warning | The session dies with no heads-up | A live token bar + desktop alerts at 70 / 85 / 95% |
| Bad timing | Compact too early and waste a session; too late and lose context | A semantic score tells you when โ and why |
| Cumulative amnesia | Each /compact summarizes the last summary, so after 2โ3 rounds key decisions vanish | Carry-forward memory injected into the compact prompt |
The amnesia problem is well documented โ see anthropics/claude-code#33212, #28721, and #3288.
# 1. Add this repo as a plugin marketplace
/plugin marketplace add fomyio/claude-context-monitor
# 2. Install the plugin
/plugin install context-monitor@claude-context-monitor
# 3. Reload, then start a new session โ the token bar appears immediately
/reload-plugins
That's it โ the five hooks register automatically. For the semantic compact scoring, the plugin uses your existing ANTHROPIC_API_KEY (see API key); everything else works with no key.
Tip: prefer manual setup or want to disable the API eval entirely? See Installation and SETUP.md.
Every message, the plugin injects a status line into Claude's context:
[CTX] ๐ข [โโโโโโโโโโโโโโโโโโโโ] 22.1% | 44K/200K | ~124 turns left
As the session grows, the color shifts ๐ข โ ๐ก โ ๐ด so you always know where you stand.
Above 45% usage, the plugin sends a lightweight fingerprint of your recent conversation to Claude Haiku (~$0.0005/call) and asks: is this prompt a continuation, or a new topic? It then scores the situation and escalates:
[CTX] ๐ก Suggestion: You might want to /compact (Topic drift detected)
[CTX] โ ๏ธ Warning: Good time to /compact soon (Score 47)
[CTX] ๐จ URGENT: Strongly recommend running /compact now (Score 71)
When you run /compact, the plugin doesn't just tell you when โ it tells Claude what to keep and what to drop, and carries the previous summary forward verbatim. See Smart Compact Instructions.
Native alerts (macOS osascript / Linux notify-send) at 70%, 85%, and 95% usage โ so you're never caught off guard, even away from the terminal.
A real-time status bar in Claude Code's UI showing usage, turns left, cost, cache efficiency, and the active model:
๐ข [โโโโโโโโโโโโโโโโโโโโ] 22.1% ยท 44K/200K ยท ~124 turns ยท $0.012 ยท eff 74% ยท Opus 4.8
The model label tracks the live model and updates the moment you switch models mid-session โ the context-window size shown is always the limit for the model currently in use.
Every prompt is scored across four signals:
| Signal | Points | What it measures |
|---|---|---|
| Token pressure | 0โ40 | How full the context is right now |
| Task completion | 0โ20 | Whether Claude's last response signals the task is done |
| Relevance drift | 0โ30 | How related the new prompt is to the session (via Haiku) |
| Conversation age | 0โ10 | How long since the last compact |
The total drives the recommendation (all thresholds configurable):
| Score | Action |
|---|---|
| 0โ25 | ๐ข Silent token bar only |
| 26โ45 | ๐ก Suggestion |
| 46โ65 | โ ๏ธ Warning |
| 66โ79 | ๐จ Urgent |
| 80+ | ๐ Block prompt until compacted (opt-in via block_on_critical) |
Claude Code's native compaction summarizes the previous summary, not the original conversation โ so after a few rounds, key decisions and file paths are lost. This plugin injects dynamic, context-aware instructions into the compact prompt via the PreCompact hook.
The full summary from the previous compaction is preserved verbatim under a "Historical Context" section, creating a cumulative memory chain that prevents exponential fidelity loss.
--- PREVIOUS COMPACT SUMMARY (PRESERVE VERBATIM) ---
This is a summary from a previous compaction in this session.
You MUST include this content in your new summary under a
"Historical Context" section. Do NOT discard or paraphrase it.
Session involved refactoring authentication module. Key decisions:
switched from JWT to session-based auth, updated middleware in auth.ts.
The advisor's Haiku-based drift detection marks which topics are stale (summarize aggressively) vs active (preserve in full detail).
--- TOPIC HISTORY ---
Topic shifts detected during this session:
[1] Turn 5: auth refactor
[2] Turn 18: API rate limiting [drifted]
[3] Turn 34: deployment config
Active topic: deployment config (preserve in FULL detail)
Stale topics: auth refactor, API rate limiting
For stale topics: summarize AGGRESSIVELY โ keep only final decisions and outcomes.
The advisor detects whether your current task is complete, partial, or in progress:
After 3+ compactions, the prompt explicitly warns about cumulative quality degradation:
--- COMPACTION HISTORY ---
This session has been compacted 3 time(s) before.
WARNING: Multiple compactions cause cumulative context loss.
Be EXTRA thorough in preserving key decisions, file paths, and
user-stated constraints. Include the Historical Context section.
All data flows through a per-session state file โ no external services, no API calls beyond the existing Haiku eval.
SessionStart
โโโ session-init.sh
Creates per-session state file, checks CLAUDE.md bloat,
sets up the statusline wrapper
Every prompt (UserPromptSubmit)
โโโ check.sh (orchestrator)
โโโ analyze.js
โ Reads the JSONL transcript โ token counts
โ Burn rate, turns left, cache efficiency, cost
โ (prefers Claude Code's ground-truth context_window data)
โ
โโโ [if usage > 45%] advisor.js
โ fingerprint.js โ last 5 turns summary
โ โ Claude Haiku API (~$0.0005)
โ Scores: token_pressure + task_completion + drift + age
โ Persists: topic shifts, active_task to state
โ Returns: score, action, recommendation text
โ
โโโ stdout โ injected into Claude's context
osascript / notify-send โ desktop notification
After each response (Stop hook, background)
โโโ update-state.sh
Persists token history, burn rate to state (atomic write)
Writes tmux status file (if enabled)
/compact lifecycle
โโโ pre-compact.sh โ Smart Compact Instructions (carry-forward, topics, task, count)
โโโ post-compact.sh โ saves full summary for carry-forward, resets, notifies
Status line (real-time, from Claude Code UI)
โโโ statusline.sh
Reads Claude Code's native context_window data + live model
Augments with burn rate, turns left, cache efficiency
๐ข [โโโโโโโ] 22.1% ยท 44K/200K ยท ~124 turns ยท $0.012 ยท eff 74% ยท Opus 4.8
All writers read-fresh and write atomically (temp + rename), and pass every value to node via the environment โ never interpolated into script source.
osascript / notify-send; Windows is not yet supported)ANTHROPIC_API_KEY for the Haiku relevance evaluation/plugin marketplace add fomyio/claude-context-monitor
/plugin install context-monitor@claude-context-monitor
/reload-plugins
# Clone into your plugins directory
mkdir -p ~/.claude/plugins
git clone https://github.com/fomyio/claude-context-monitor.git ~/.claude/plugins/context-monitor
# Install dependencies
cd ~/.claude/plugins/context-monitor
npm install
# Register hooks โ merge hooks/settings-snippet.json into ~/.claude/settings.json
FAQ
context-monitor is a Claude Code plugin with hand-picked skills for development work, indexed on Flowy. Install it with the command on its page. Its skills do not fire on their own yet. Request auto-invocation to have Flowy route them as you prompt. Free and open source.
Is this plugin yours?
Claim it with GitHubSubmit a pluginPromote it