Autonomous context management for Claude Code through intelligent cleanup and memory migration
An intelligent system that enables Claude Code to autonomously manage its context window by:
- ๐ Monitoring prompt fill level continuously
- ๐งน Cleaning up irrelevant information automatically
- ๐ง Migrating important knowledge to persistent memory
- ๐ Optimizing performance without user intervention
Problem: As conversations grow, Claude Code's context fills up, leading to slower performance and eventually hitting token limits.
Solution: Claude autonomously detects when cleanup is needed and intelligently removes old, irrelevant information while preserving important knowledge in the MCP Memory Server.
Available in 7 languages! See the Documentation Center for:
| Language | Links |
|---|---|
| ๐ฌ๐ง English | README | Installation | Contributing |
| ๐ฉ๐ช Deutsch | README | Installation | Beitragen |
| ๐ช๐ธ Espaรฑol | README | Instalaciรณn | Contribuir |
| ๐ซ๐ท Franรงais | README | Installation | Contribuer |
| ๐จ๐ณ ไธญๆ | README | ๅฎ่ฃ | ่ดก็ฎ |
| ๐ฎ๐น Italiano | README | Installazione | Contribuire |
| ๐ท๐บ ะ ัััะบะธะน | README | ะฃััะฐะฝะพะฒะบะฐ | ะฃัะฐััะธะต |
- Self-monitoring: Claude checks context usage automatically
- Proactive cleanup: Acts before reaching limits
- Auto-approval: Executes cleanup without user intervention when safe
- Transparent: Always explains what's being done
- Relevance scoring: ML-based analysis of message importance
- Reference tracking: Preserves cross-referenced information
- Tool-specific rules: Different strategies for Read, Bash, Grep, etc.
- Context-aware: Understands current task and preserves related info
- Automatic migration: Important old info moved to MCP Memory Server
- Entity extraction: Converts context to structured knowledge graph
- Retrieval support: Can query memory when needed
- Dual scope: Project-local and user-global memory
- Never removes: Last 3 turns, errors, system prompts, recent edits
- Rollback support: Can undo any cleanup operation
- Dry-run mode: Preview cleanup before execution
- User override: Always respects explicit user instructions
# Install the package
pip install context-cleanup==0.2.0
# Verify installation
python3 -c "from context_cleanup.tools import context_status; print('โ
Installed')"# Check context status
python3 ~/.claude/local/bin/context-status --detailed
# Analyze cleanup candidates
~/.claude/local/bin/analyze-cleanup standard --json
# Perform cleanup (dry-run)
python3 ~/.claude/local/bin/cleanup-context standard --dry-run
# Execute cleanup
python3 ~/.claude/local/bin/cleanup-context standard --approveFor detailed installation instructions, see INSTALLATION.md
Check current context usage and get recommendations
Preview what would be removed (dry-run analysis)
Modes: conservative, standard, aggressive, emergency
Perform the actual context cleanup
Save important information to MCP Memory Server
claude-code-context-cleanup/
โโโ README.md # This file (English)
โโโ INSTALLATION.md # Installation guide (English)
โโโ CHANGELOG.md # Version history
โโโ CONTRIBUTING.md # Contributing guidelines (English)
โโโ docs/
โ โโโ README.md # Multi-language documentation center
โ โโโ en/ # English documentation
โ โโโ de/ # Deutsch documentation
โ โโโ es/ # Espaรฑol documentation
โ โโโ fr/ # Franรงais documentation
โ โโโ zh/ # ไธญๆ (Chinese) documentation
โ โโโ it/ # Italiano documentation
โ โโโ ru/ # ะ ัััะบะธะน (Russian) documentation
โโโ implementation/
โ โโโ context_cleanup/ # Main package
โ โโโ core/ # Core modules
โ โโโ analyzers/ # Analysis engines
โ โโโ tools/ # CLI tools
โ โโโ utils/ # Utilities
โโโ tests/ # Test suite
โโโ LICENSE # MIT License
- โ Old grep/glob searches (no follow-up)
- โ Exploratory file reads (no subsequent edits)
- โ Completed todo items
- โ Old bash command outputs
- โ Redundant information
- โ Last 3 turns (always kept)
- โ Error messages & traces
- โ Recently edited files
- โ Actively referenced messages
- โ System prompts
Released: October 18, 2025
- โ Core tools and analyzers (4 tools)
- โ CLI integration with all features
- โ Full test coverage (264 tests, 54% coverage)
- โ 100% type safety and documentation
- โ Multilingual documentation (7 languages)
- โ Production deployment ready
Planned Features:
- Real Claude Code API integration
- Advanced ML-based relevance scoring
- Production PostgreSQL database support
- Real-time context monitoring dashboard
- Performance optimizations
- Extended language support
Planned Features:
- Advanced configuration management
- Multi-user project support
- Custom cleanup policies
- Audit logging and compliance
- Team collaboration features
General Availability Release:
- Full production deployment
- Enterprise monitoring and observability
- Professional support program
- SLA guarantees
- Security certifications
- Installation Guide - Setup instructions (English)
- CHANGELOG - Version history
- Contributing - How to contribute (English)
- Documentation Center - Complete multilingual documentation hub
Contributions welcome! See CONTRIBUTING.md for guidelines.
MIT License - See LICENSE file for details
- GitHub: https://github.com/MarcoFPO/claude-code-context-cleanup
- Release: https://github.com/MarcoFPO/claude-code-context-cleanup/releases/tag/v0.2.0
- Issues: https://github.com/MarcoFPO/claude-code-context-cleanup/issues
Status: ๐ข Beta Phase - Production Ready Version: 0.2.0 Last Updated: 18. Oktober 2025
โญ Star this repo if you find it interesting!