This integration solves a critical problem in AI-assisted development: context loss during long development sessions. By leveraging Claude Code's new PreCompact and Stop hooks, we ensure that Context Forge projects maintain their context even after conversation compaction.
When Claude Code's context window fills up (during multi-hour coding sessions), it performs "compaction" to continue. During this process:
- Project-specific rules are forgotten
- Current implementation stage is lost
- PRP guidelines are no longer followed
- Bug tracking history disappears
This forces developers to repeatedly remind Claude about the project context, breaking flow and reducing productivity.
Our hook integration:
- Detects Context Forge Projects - Automatically identifies projects with CLAUDE.md, Docs/, and PRPs/
- Captures State Before Compaction - PreCompact hook records current stage and active tasks
- Enforces Context Refresh - Stop hook ensures Claude re-reads critical files after compaction
- Maintains Continuity - Preserves awareness of implementation progress and guidelines
PreCompact Hook → Detects CF Project → Creates Marker → Prepares Instructions
↓
Stop Hook → Checks Marker → Blocks Claude → Forces Context Refresh
-
precompact-context-refresh.py
- Detects Context Forge projects
- Extracts current implementation stage
- Creates marker for Stop hook
- Returns refresh instructions
-
stop-context-refresh.py
- Checks for compaction marker
- Generates detailed refresh instructions
- Blocks Claude until context is restored
-
context-forge-utils.py
- Analyzes project structure
- Detects tech stack
- Tracks implementation progress
- Provides project summaries
- Context lost every ~2 hours
- Manual reminders needed
- Quality degrades over time
- Progress tracking lost
- Context automatically maintained
- No manual intervention needed
- Consistent quality throughout
- Progress seamlessly tracked
Consider a typical 8-hour development session:
Without Hooks: 3-4 compactions × 10 minutes to restore context = 30-40 minutes lost
With Hooks: Automatic recovery, 0 minutes lost, better compliance with project standards
# Quick install
./install-context-forge-hooks.sh
# Or manual setup
cp *.py ~/.claude/hooks/context-forge/
# Add hooks to ~/.claude/settings.json- Smarter Stage Detection - ML-based analysis of current work
- Incremental Context - Only refresh changed sections
- Multi-Project Support - Handle multiple Context Forge projects
- Performance Metrics - Track context retention effectiveness
- Integration with Context Forge CLI - Automatic hook installation
- PreCompact: <100ms overhead
- Stop: <50ms overhead
- No impact on normal operation
- Works with all Context Forge project types
- Python 3.6+ required
- No external dependencies
- Runs with user permissions only
- No network access
- Logs to user directory only
This integration represents a significant advancement in AI-assisted development workflows. By solving the context loss problem, we enable developers to maintain flow state and productivity during extended coding sessions.
The combination of Context Forge's structured project scaffolding and Claude Code's hook system creates a powerful synergy that makes multi-hour AI-assisted development not just possible, but highly effective.
- Test with your Context Forge projects
- Report issues or suggestions
- Contribute improvements
- Share your success stories
Together, we're building the future of AI-assisted software development!