Skip to main content

Advanced context monitoring and management for Claude Code

Project description

Claude Context Monitor

License: MIT Claude Code PyPI version

Advanced context monitoring and adaptive threshold learning for Claude Code

🚀 Features

  • Real-time status line showing context usage in all projects
  • Intelligent plan detection using P90 analysis - no manual configuration needed!
  • Automatic handoff generation when approaching context limits
  • Claude Max/Pro support with appropriate token limits
  • Global /handoff command available everywhere
  • Git integration showing branch and status
  • Zero configuration for new projects

📺 Demo

Your Claude Code status line will show:

💻 user:project │ 🔵 16.3% (98K) │ 🌿main ± │ 🎯MAX

⚡ Installation

🚀 Recommended: UV + UVX (Modern Python)

# Install with uvx (no global installation needed)
uvx claude-context-monitor status

# Or install globally
uv tool install claude-context-monitor

# Use commands anywhere
claude-context status
ccm handoff --record

📦 Traditional pip

pip install claude-context-monitor
claude-context install

🔧 Legacy Shell Install

curl -fsSL https://raw.githubusercontent.com/XiaoConstantine/claude-context-monitor/main/install.sh | bash

Development Install

git clone https://github.com/XiaoConstantine/claude-context-monitor.git
cd claude-context-monitor
./install.sh

🎯 Usage

CLI Commands

# Status monitoring
claude-context status              # Current context status  
claude-context status -f json      # JSON output
ccm status -f compact             # Compact format (short alias)

# Plan detection
claude-context plan               # Detect Claude plan automatically
claude-context plan --json       # JSON output

# Handoff tracking & adaptive learning  
claude-context handoff --record  # Record handoff for threshold learning
claude-context handoff --stats   # Show historical handoff statistics
claude-context handoff --summary # Get summary for documents

# Configuration
claude-context config --show     # Show current config
claude-context config --set CLAUDE_PLAN=max  # Set values
claude-context config --get CONTEXT_THRESHOLD

# Installation (legacy compatibility)
claude-context install           # Install to ~/.claude
claude-context install --force   # Force reinstall

Global Claude Commands

/handoff          # Generate handoff document (auto-records context %)
/handoff --force  # Force generation

Automatic Features

  • Real-time status: Shows in Claude Code status line
  • Adaptive thresholds: Learns from your handoff patterns
  • Plan detection: Automatically detects Pro/Max plans
  • Git integration: Shows branch and dirty status

Manual plan override (optional - auto-detection is recommended)

export CLAUDE_PLAN=max # Force Claude Max (600K tokens) export CLAUDE_PLAN=pro # Force Claude Pro (200K tokens)

Leave unset for intelligent auto-detection


## 🧠 Intelligent Plan Detection

The monitor automatically detects your Claude plan using **P90 analysis** of your usage history:

- **Analyzes** your last 8 days of token usage patterns
- **Calculates** 90th percentile usage from recent sessions  
- **Detects** if you're on Pro (200K) or Max (600K) plan with 85% confidence
- **Falls back** to conservative Pro limits if insufficient data

No manual configuration needed! The system learns from your actual usage patterns.

```json
{
  "detected_plan": "max",
  "confidence": 0.85,
  "method": "p90_analysis", 
  "p90_limit": 160000,
  "token_limit": 600000,
  "sessions_analyzed": 8
}

🔧 How It Works

  1. Real-time monitoring: Reads token usage from Claude Code's session files (~/.claude/projects/)
  2. Intelligent detection: Uses P90 analysis to automatically detect your Claude plan
  3. Smart limits: Adjusts thresholds for Claude Max (600K) vs Pro (200K) tokens
  4. Auto-handoff: Generates detailed handoff documents at 90% usage
  5. Git integration: Shows current branch and dirty status

📊 Status Indicators

Context Usage Colors

  • 🔵 Low (0-49%): Plenty of context remaining
  • 🟢 OK (50-74%): Context usage moderate
  • 🟡 High (75-89%): Approaching context limit
  • 🔴 Critical (90%+): Handoff generation triggered

Git Status

  • 📁 Clean: No uncommitted changes
  • Dirty: Uncommitted changes present

📋 Requirements

  • Claude Code: Latest version with statusLine support
  • Python 3.8+: For status monitoring scripts
  • jq: For JSON configuration management
  • Git: For project status detection (optional)

📖 Documentation

🤝 Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

📄 License

MIT License - see LICENSE file for details.

🙏 Acknowledgments


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

claude_context_monitor-1.1.0.tar.gz (29.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

claude_context_monitor-1.1.0-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

Details for the file claude_context_monitor-1.1.0.tar.gz.

File metadata

File hashes

Hashes for claude_context_monitor-1.1.0.tar.gz
Algorithm Hash digest
SHA256 beb4320f7bfd9fe359ce811846b029a1ca0673c6d11f32f771990f9449322c4f
MD5 0b1a5a331e9eef350808fbf07240ef27
BLAKE2b-256 6ed1bc65323cca869755a51e7fd3fc0054fac45d46f267cdd099f2859f4888ad

See more details on using hashes here.

File details

Details for the file claude_context_monitor-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for claude_context_monitor-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3de2582d52c595054cf04a55a48bb560a0c726e803d196d91a3d32f6e7aaab55
MD5 fba4374f9b4ad4b2d84d4c0a8e584067
BLAKE2b-256 f9d9fa380b23689f2e963382a3ec3a999c818c1a3e2a917a9db3d234dcd86cdc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page