Feature Request: Automatic Context Restoration After Autocompaction

Resolved 💬 11 comments Opened Aug 18, 2025 by SDS-Mike Closed Aug 22, 2025

Summary

Add functionality to automatically restore context after autocompaction by re-reading CLAUDE.md and the latest JSONL conversation history file.

Problem Statement

When Claude Code performs autocompaction to manage conversation length, valuable context is lost including:

  • Project goals and requirements from CLAUDE.md
  • Recent conversation history and decisions made
  • Work progress and current state

This forces users to manually re-explain project context and recent work, reducing productivity in long coding sessions.

Use Case

During extended development sessions, developers often hit conversation length limits. Currently, after autocompaction:

  1. Claude loses awareness of project-specific instructions in CLAUDE.md
  2. Recent work context disappears
  3. Users must manually re-establish context
  4. Productivity is disrupted

Proposed Solution

Implement a post-compaction hook that automatically:

  1. Re-reads CLAUDE.md to restore project-level context
  2. Loads latest JSONL conversation history from ~/.claude/projects/
  3. Restores conversation context by providing a summary of recent interactions
  4. Maintains conversation continuity without manual intervention

Implementation Details

Core Components

Context Restorer Class

  • Handles reading CLAUDE.md from project directory
  • Finds and parses latest JSONL conversation file
  • Generates context restoration summary

Autocompaction Hook

  • Triggers automatically after compaction occurs
  • Integrates with existing compaction workflow
  • Provides fallback handling if restoration fails

Integration Points

  • Modify existing compaction function to call post-compaction hook
  • Add configuration option to enable/disable feature
  • Include restoration status in compaction logging

Benefits

  • Improved Developer Experience: Seamless continuation of work after compaction
  • Reduced Friction: No need to manually re-explain context
  • Better Continuity: Maintains project awareness across compaction boundaries
  • Time Savings: Eliminates repetitive context re-establishment

Alternatives Considered

  1. Manual context reload command: Requires user intervention
  2. Larger context windows: Hardware/cost limitations
  3. More aggressive summarization: May lose important details

Additional Context

This feature would be particularly valuable for:

  • Long debugging sessions
  • Complex refactoring work
  • Multi-file feature implementations
  • Extended pair programming sessions

Acceptance Criteria

  • [ ] Context automatically restored after autocompaction
  • [ ] CLAUDE.md contents available post-compaction
  • [ ] Recent conversation summary provided
  • [ ] Feature can be enabled/disabled via settings
  • [ ] Restoration failures handled gracefully
  • [ ] Performance impact minimal (<1 second)

Related Issues

  • Related to context management improvements
  • Complements existing autocompaction feature

View original on GitHub ↗

This issue has 11 comments on GitHub. Read the full discussion on GitHub ↗