Skip to content

feat: implement selective memory management hooks/commands (pop/forget memory) #56

@lroolle

Description

@lroolle

Description

Add hooks and custom commands to enable selective memory management as an alternative to full conversation compacting.

Type

  • Bug fix
  • New feature
  • Enhancement
  • Documentation

Details

Currently Claude Code only supports full conversation compacting via /compact command. The main issue is that auto-compacting heavily impacts current working state - losing critical context about ongoing implementation, debugging sessions, and project decisions that are essential for the current task.

Current State:

  • /compact performs full conversation summarization, disrupting active work
  • /clear resets entire conversation
  • Auto-compact triggers interrupt current workflows and lose working context
  • PreCompact hook exists but limited to modifying full compaction

Community Evidence:
The community has built extensive workarounds due to this limitation:

  • mcp-memory-keeper - SQLite-based persistent context (most popular)
  • claude-memory-mcp - Advanced tiered memory architecture
  • memory-bank-mcp - Remote memory management
  • zen-mcp-server - Multi-model collaboration with persistence
  • Users report "62-agent systems" built to compensate for context loss
  • Multiple GitHub issues: #1345 (context management bugs), #1534 (memory loss after auto-compact)
  • Community describes current system as "nearly unusable for complex tasks"

Root Problem:
Auto-compacting destroys working state context that's critical for ongoing tasks. Users need granular control to preserve current work while removing irrelevant history.

Proposed Solution:
Implement selective memory management through:

  1. Selective Removal Commands:

    /forget          # Remove last interaction
    /forget 3        # Remove last 3 interactions  
    /forget <tag>    # Remove tagged conversation segment
    /checkpoint      # Create named restoration point
    /restore <name>  # Restore to checkpoint
  2. Context Tagging System:

    /tag start debugging-session
    # ... debugging conversation ...
    /tag end debugging-session
    /forget debugging-session  # Remove entire tagged section
  3. Working State Preservation:

    /scope working   # Mark current context as critical working state
    /scope temp      # Mark interactions as removable
    /cleanup temp    # Remove temporary while preserving working state

Technical Implementation:

  • Extend PreCompact hook for selective manipulation
  • Add transcript parsing for targeted removal
  • Implement conversation metadata tracking
  • Use existing CLAUDE.md system for persistent context
  • Leverage MCP servers for external memory management

Benefits:

  • Preserve working state during memory management
  • Maintain project context while removing clutter
  • User control over what stays vs what gets removed
  • Reduce need for complex external memory systems
  • Keep critical debugging/implementation context intact

Related Files

  • Hook system and PreCompact implementation
  • Custom command handlers (.claude/commands/)
  • Memory management utilities
  • Transcript manipulation functions

Test Plan

  • Test /forget commands preserve current working context
  • Verify tagging system protects critical conversation segments
  • Test checkpoint/restore maintains working state
  • Ensure persistent memory (CLAUDE.md) is preserved
  • Test working state preservation during selective removal
  • Validate conversation coherence after targeted forgetting
  • Test integration with existing hooks and MCP servers
  • Document command syntax and working state protection patterns

Main Goal: Enable users to manage conversation memory without losing critical working state that's essential for current tasks.

References: Community solutions (mcp-memory-keeper, claude-memory-mcp), GitHub issues #1345/#1534, PreCompact hook (v1.0.48)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions