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.
What's inside
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.
> /plugin marketplace add fomyio/claude-context-monitor> /plugin install context-monitor@claude-context-monitor
Repo: fomyio/claude-context-monitor
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
The plugin uses ANTHROPIC_API_KEY from your Claude Code session automatically. If it's not in your environment:
echo "sk-ant-..." > ~/.anthropic_key
chmod 600 ~/.anthropic_key
The token bar, notifications, and status line work without a key โ only the topic-drift scoring needs one. See SETUP.md for alternatives (custom key command, or disabling the eval entirely).
All settings live in config.json. The defaults work well out of the box.
{
// Toggle the Haiku relevance evaluation (disable to save API calls)
"relevance_eval_enabled": true,
// Only run the eval above this usage percentage (saves cost at low usage)
"relevance_eval_threshold_pct": 45,
// Shell command that prints your API key (fallback when ANTHROPIC_API_KEY is unset)
"anthropic_api_key_cmd": "cat ~/.anthropic_key",
// Desktop notification thresholds (percentage)
"notify_thresholds": { "info": 70, "warning": 85, "critical": 95 },
// Compact score thresholds
"compact_score_thresholds": {
"suggest": 26, // ๐ก soft suggestion
"warn": 46, // โ ๏ธ warning
"urgent": 66, // ๐จ urgent
"block": 80 // ๐ block the prompt (requires block_on_critical: true)
},
// Set to true to hard-block prompts when score >= block threshold
"block_on_critical": false,
// How many recent turns to include in the relevance fingerprint
"fingerprint_max_turns": 5,
// Number of recent turns used for burn-rate calculation
"burn_rate_window_turns": 4,
// Warn if CLAUDE.md exceeds this % of the context limit
"claude_md_bloat_threshold_pct": 15,
// Status line integration
"statusline_enabled": true,
// Write context status to a file for a tmux status bar (opt-in)
"tmux_status_enabled": false,
"tmux_status_file": "/tmp/claude-ctx-status",
// Where per-session state is stored
"state_dir": "~/.claude/plugins/context-monitor/state",
// Per-model context limits (tokens). Claude Code's live value overrides these.
"context_limits": {
"claude-opus-4-7": 200000,
"claude-opus-4-6": 200000,
"claude-opus-4-5": 200000,
"claude-opus-4": 200000,
"claude-sonnet-4-6": 200000,
"claude-sonnet-4-5": 200000,
"claude-haiku-4-5": 200000
},
// Per-model pricing (USD per million input tokens)
"model_prices_per_million_input": {
"claude-opus-4-7": 15.00,
"claude-opus-4-6": 15.00,
"claude-opus-4-5": 15.00,
"claude-opus-4": 15.00,
"claude-sonnet-4-6": 3.00,
"claude-sonnet-4-5": 3.00,
"claude-haiku-4-5": 0.80
}
}
The static
context_limitstable is only a fallback โ when Claude Code reports a livelimit_tokens(e.g. a 1M-token model), the plugin uses that instead, so the bar always reflects the model actually in use.
See a summary of your current session at any time:
context-monitor report # or: node src/dashboard.js
Session: 34 turns | 47 min | Sonnet 4.6
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Context: [โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ] 51.3% (103K / 200K)
Cost: ~$0.041 this session | Cache eff: 74%
Burn: ~8200 tokens/turn | ~12 turns remaining
Topics: [auth refactor โ API rate limiting]
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Recommendation: โ ๏ธ Warning โ Context threshold high. Consider /compact.
The plugin registers five Claude Code hooks (hooks/hooks.json):
| Hook | Script | Purpose |
|---|---|---|
SessionStart | hooks/session-init.sh | Initialize per-session state, check CLAUDE.md bloat, set up statusline |
UserPromptSubmit | hooks/check.sh | Run token analysis + advisor scoring, inject the status line |
Stop | hooks/update-state.sh | Persist token history and stats after each response (background) |
PreCompact | hooks/pre-compact.sh | Inject Smart Compact Instructions before summarization |
PostCompact | hooks/post-compact.sh | Save the compact summary for carry-forward, reset state, notify |
The Haiku eval only activates above 45% context usage.
| Usage pattern | Estimated monthly cost |
|---|---|
| Normal use | ~$0.05 โ $0.15 |
| Heavy use (โ1000 turns/mo) | ~$0.50 |
Each eval is a single Haiku call over a ~400โ600 token conversation fingerprint (โ$0.0005). With the eval disabled (relevance_eval_enabled: false), the plugin costs $0 to run.
The plugin runs entirely on your machine. The only outbound network call is the optional Haiku relevance eval, which sends a short fingerprint of your recent turns to the Anthropic API โ and only above 45% usage, only if enabled. No telemetry, no third-party services. Full details in PRIVACY.md.
claude-context-monitor/
โโโ .claude-plugin/
โ โโโ plugin.json # Plugin manifest (name, version, author)
โ โโโ marketplace.json # Marketplace manifest for /plugin install
โโโ hooks/
โ โโโ hooks.json # Hook registrations (${CLAUDE_PLUGIN_ROOT} paths)
โ โโโ settings-snippet.json # Manual install: merge into settings.json
โ โโโ session-init.sh # SessionStart โ initialize session state
โ โโโ check.sh # UserPromptSubmit โ main orchestrator
โ โโโ update-state.sh # Stop โ persist stats after each response
โ โโโ pre-compact.sh # PreCompact โ smart compact instructions
โ โโโ post-compact.sh # PostCompact โ save summary, reset state
โโโ src/
โ โโโ analyze.js # Token analyzer: reads the JSONL transcript
โ โโโ advisor.js # Scoring engine: Haiku eval + compact score
โ โโโ fingerprint.js # Context summarizer: builds the Haiku input
โ โโโ statusline.sh # Claude Code status line integration
โ โโโ notify.sh # Desktop notifications (macOS + Linux)
โ โโโ dashboard.js # CLI report (bin: context-monitor)
โ โโโ uninstall.sh # Clean uninstall script
โโโ docs/
โ โโโ HOMEPAGE.md # Plugin homepage
โ โโโ PLAN.md # Implementation plan / roadmap
โ โโโ PRIVACY.md # Privacy details
โ โโโ MARKETPLACE_SUBMISSION.md
โโโ config.json # User-configurable thresholds + settings
โโโ SETUP.md # API key setup guide
โโโ PRIVACY.md # Privacy policy
โโโ LICENSE # MIT
โโโ package.json
Per-session state lives outside the repo, under ~/.claude/plugins/context-monitor/state/ (configurable via state_dir).
Contributions are welcome!
git clone https://github.com/fomyio/claude-context-monitor.git
cd claude-context-monitor
npm install
Branch naming
| Prefix | Purpose |
|---|---|
feature/ | New features |
fix/ | Bug fixes |
refactor/ | Code restructuring |
docs/ | Documentation |
chore/ | Maintenance, dependencies |
Always branch off main:
git checkout main && git pull origin main
git checkout -b feature/your-feature-name
Before submitting a PR
npm install succeedsnode --check src/*.js and bash -n hooks/*.sh src/*.sh passnode src/analyze.js <transcript> <model> <session_id> returns valid JSON.env files, or API keys committedtype(scope): descriptionIn scope: hook improvements, platform support (e.g. Windows notifications), opt-in config features, richer dashboard output, tests for analyze.js / advisor.js.
Out of scope: breaking config.json key renames, requiring internet for core functionality, runtime deps beyond the Anthropic SDK.
Reporting issues โ include your OS + Claude Code version, sample analyze.js output (redacted), your config.json (redact keys), and the exact hook output. Open an issue here.
/plugin uninstall context-monitor@claude-context-monitor
Or manually:
bash ${CLAUDE_PLUGIN_ROOT}/src/uninstall.sh
This removes the statusline entry from settings.json, cleans up the statusline wrapper, and removes orphaned cache directories.
.claude-plugin/
marketplace.json
plugin.json
.github/
labeler.yml
workflows/
labeler.yml
.gitignore
config.json
docs/
HOMEPAGE.md
MARKETPLACE_SUBMISSION.md
PLAN.md
PRIVACY.md
hooks/
check.sh
hooks.json
post-compact.sh
pre-compact.sh
session-init.sh
settings-snippet.json
update-state.sh
LICENSE
package-lock.json
package.json
PRIVACY.md
README.md
SETUP.md
src/
advisor.js
analyze.js
context-limit.js
dashboard.js
fingerprint.js
notify.sh
statusline.sh
uninstall.shยฉ 2026 Flowy ยท Free and open source
Built for Claude Code ยท Not affiliated with Anthropic