Auto-warns you at 50%, 75%, and 85% context window usage. 2-minute setup. Works in every Claude Code session automatically.
~/.claude/scripts/usage-check.py โ create the folder if it doesn't exist.#!/usr/bin/env python3 # Claude Context Monitor โ clayparker-fullstackmarketer.vercel.app/claude-monitor # Auto-detects model from session transcript. Warns at 50/75/85% context usage. import json, sys # Context limits by model family โ covers all Claude plans and versions MODEL_LIMITS = { # Claude 4.x (all plans) "claude-opus-4": 200_000, "claude-sonnet-4": 200_000, "claude-haiku-4": 200_000, # Claude 3.5 "claude-3-5-sonnet": 200_000, "claude-3-5-haiku": 200_000, # Claude 3 "claude-3-opus": 200_000, "claude-3-sonnet": 200_000, "claude-3-haiku": 200_000, # Claude 2 "claude-2.1": 200_000, "claude-2.0": 100_000, "claude-2": 100_000, # Claude Instant / 1.x "claude-instant": 100_000, "claude-1": 100_000, } DEFAULT_LIMIT = 200_000 def get_limit(model_id): if not model_id: return DEFAULT_LIMIT m = model_id.lower() for prefix, limit in MODEL_LIMITS.items(): if m.startswith(prefix): return limit return DEFAULT_LIMIT def main(): try: payload = json.loads(sys.stdin.read()) transcript_path = payload.get("transcript_path") except Exception: sys.exit(0) if not transcript_path: sys.exit(0) latest_usage, latest_model = None, None try: with open(transcript_path) as f: for line in f: line = line.strip() if not line: continue obj = json.loads(line) msg = obj.get("message", {}) if isinstance(msg, dict) and "usage" in msg: latest_usage = msg["usage"] if msg.get("model"): latest_model = msg["model"] except Exception: sys.exit(0) if not latest_usage: sys.exit(0) limit = get_limit(latest_model) tokens = ( latest_usage.get("input_tokens", 0) + latest_usage.get("cache_creation_input_tokens", 0) + latest_usage.get("cache_read_input_tokens", 0) ) pct = (tokens / limit) * 100 if pct >= 85: print(f"\n๐ด CONTEXT WINDOW: {pct:.0f}% used ({tokens:,} / {limit:,} tokens) โ run /compact NOW or switch to a new session.\n") elif pct >= 75: print(f"\n๐ก CONTEXT WINDOW: {pct:.0f}% used ({tokens:,} / {limit:,} tokens) โ consider running /compact soon.\n") elif pct >= 50: print(f"\n๐ CONTEXT WINDOW: {pct:.0f}% used ({tokens:,} / {limit:,} tokens) โ halfway there, keep an eye on it.\n") if __name__ == "__main__": main()
Model is read from the transcript automatically โ no manual config required.
| Model | Context Window | Plans |
|---|---|---|
| claude-opus-4 / sonnet-4 / haiku-4 | 200K | Pro, Team, Enterprise, API |
| claude-3-5-sonnet / 3-5-haiku | 200K | Pro, Team, Enterprise, API |
| claude-3-opus / 3-sonnet / 3-haiku | 200K | Pro, Team, Enterprise, API |
| claude-2.1 | 200K | Legacy API |
| claude-2.0 / claude-instant / claude-1 | 100K | Legacy API |
~/.claude/settings.json to run the script after every response. If the file already exists, merge the hooks block in.{
"hooks": {
"Stop": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "python3 ~/.claude/scripts/usage-check.py"
}
]
}
]
}
}
The Stop hook fires after every Claude response โ silent unless a threshold is crossed.
# Context Window Monitoring A Stop hook auto-runs usage-check.py after every response. Follow these rules when thresholds are hit: - **At 50%**: Mention once: "๐ Context at ~50% โ heads up." - **At 75%**: Warn clearly: "๐ก Context at ~75% โ suggest /compact before the next big task." - **At 85%**: Stop and warn hard: "๐ด Context at 85%+ โ run /compact now or open a new session."