Feature Request: Hierarchical Context Management (Conversation Stack)

Resolved 💬 8 comments Opened Aug 7, 2025 by punya Closed Jan 3, 2026

Summary

Add conversation stacking functionality to enable pushing into focused contexts for subtasks, working interactively within those contexts, and popping back to parent contexts with compressed summaries.

Problem

Claude Code currently manages conversation context as a single linear thread. For complex multi-step tasks, this creates several inefficiencies:

Context Pollution: Detailed subtask work (debugging, research, iteration) clutters the main task context, reducing focus and consuming tokens unnecessarily.

Manual Context Management: Users must manually decide what information to preserve when switching between task hierarchies, often using workarounds like multiple sessions, external documentation, or complex subagent coordination systems.

Limited Task Delegation: Current subagents require pre-definition and don't support interactive collaboration within focused contexts.

Invisible Context Relationships: No indication of task hierarchy or current "level" of operation.

Related Issues

  • #2265: Compaction during complex operations destroys progress
  • #1345: Users building 62-agent coordination systems due to context limitations
  • #4182: Request for nested task spawning indicates need for hierarchical management
  • #4908: Scoped context passing shows demand for controlled information flow

Proposed Solution

Core Commands

/push "debug compilation errors"     # Push into focused context
/pop                                 # Pop back with compressed summary  
/stack                              # Show current context hierarchy
/peek 1                             # Preview parent context without switching

Context Stack Structure

Each context level maintains:

  • Isolated message history for focused work
  • Project state snapshot (directory, commit, branch)
  • Parent context reference for proper restoration
  • Compression metadata for summary generation

Terminal UI Indicator

┌─ Context Stack (depth: 2/5) ──────────────────────┐
│ 1. Main: Auth System Implementation (15 msgs)     │
│ 2. └─ [ACTIVE] Debugging compilation (8 msgs)     │
└───────────────────────────────────────────────────┘

Interactive Stack Navigation

/stack --expand           # Detailed view with context previews
/stack --preview 1        # Show summary of specific context level
↑/↓ arrows                # Navigate in /stack mode
Enter                     # Switch to selected context

Implementation Details

Context Compression

When popping contexts, apply configurable summarization:

  • Length: brief|standard|detailed
  • Focus: outcomes|process|technical|decisions
  • Format: bullets|prose|structured

State Management

  • Session persistence: Context stacks survive Claude Code restarts
  • File change tracking: Monitor modifications across context levels
  • Conflict detection: Handle overlapping file edits between contexts

Project Integration

  • Git integration: Track repository state changes per context level
  • Multi-project support: Context stacks work across different repositories
  • Checkpoint recovery: Restore context stacks after crashes or interruptions

Use Cases

Debugging Within Feature Work: Push into compilation error fixing, iterate interactively on solutions, pop back with "Fixed 3 import errors, updated type definitions" summary.

Research Within Implementation: Push into API research, explore documentation and examples interactively, pop back with implementation recommendations and code patterns.

Code Review Within Development: Push into security analysis, discuss findings interactively, pop back with security checklist and identified issues.

Benefits

  • Context Efficiency: Automatic compression prevents context window overflow
  • Interactive Workflows: Support back-and-forth collaboration within focused contexts
  • Visual Clarity: Always know current position in task hierarchy
  • Reduced Manual Overhead: Eliminate need for complex external context management systems

Technical Considerations

Backwards Compatibility: Existing workflows continue unchanged; stack commands are additive.

Resource Management: Context levels stored efficiently with lazy loading and compression.

Integration: Works with existing subagents, slash commands, and MCP servers.

---

This feature would transform Claude Code from a linear conversation tool into a hierarchical task management system that matches how developers naturally decompose complex problems.

View original on GitHub ↗

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