Free Claude Code Skill

Never get cut off
mid-session again.

Auto-warns you at 50%, 75%, and 85% context window usage. 2-minute setup. Works in every Claude Code session automatically.

๐ŸŸ  50% โ€” heads up ๐ŸŸก 75% โ€” run /compact ๐Ÿ”ด 85% โ€” switch sessions now
How it works
A Python script reads your session transcript after each Claude response, checks the latest token usage against your model's context limit, and prints a warning if you're approaching the edge. The hook runs silently in the background โ€” you only see output when thresholds are hit.
๐ŸŸ  CONTEXT WINDOW: 52% used (104,231 / 200,000 tokens) โ€” halfway there, keep an eye on it.
๐ŸŸก CONTEXT WINDOW: 76% used (152,044 / 200,000 tokens) โ€” consider running /compact soon.
๐Ÿ”ด CONTEXT WINDOW: 87% used (174,512 / 200,000 tokens) โ€” run /compact NOW or switch to a new session.
Setup โ€” 3 steps
Step 1
Create the monitoring script
Save this file to ~/.claude/scripts/usage-check.py โ€” create the folder if it doesn't exist.
โœฆ Auto-detects your model โ€” no config needed
PYTHON ยท ~/.claude/scripts/usage-check.py
#!/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.

ModelContext WindowPlans
claude-opus-4 / sonnet-4 / haiku-4200KPro, Team, Enterprise, API
claude-3-5-sonnet / 3-5-haiku200KPro, Team, Enterprise, API
claude-3-opus / 3-sonnet / 3-haiku200KPro, Team, Enterprise, API
claude-2.1200KLegacy API
claude-2.0 / claude-instant / claude-1100KLegacy API
Step 2
Register the hook
Create or update ~/.claude/settings.json to run the script after every response. If the file already exists, merge the hooks block in.
JSON ยท ~/.claude/settings.json
{
  "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.

Step 3 (optional)
Add to your CLAUDE.md
Tell Claude how to respond when thresholds hit. Paste into any CLAUDE.md file for consistent behavior across projects.
MARKDOWN ยท CLAUDE.md
# 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."

Restart Claude Code
Hooks load at startup. After saving both files, restart Claude Code. The monitor is active immediately โ€” no output until you hit 50%.

Built by
โ—ˆ
Clay Parker
Sr. Demand Gen & Lifecycle, Zapier ยท GTM & Revenue Marketing ยท AI-native builder

More free skills
⚡
Auto-Apply
Pre-fill job application forms
✍
Cover Letter Writer
Generate tailored cover letters