Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Um comando direto ignora o prompt de revisão. Verifique a origem antes de executá-lo.
Unified context optimization and session state management for Claude Code with 200K token budget management, session persistence, and multi-agent handoff protocols.
Core Capabilities:
200K token budget allocation and monitoring
Session state tracking with persistence
Context-aware token optimization
Multi-agent handoff protocols
Progressive disclosure and memory management
Session forking for parallel exploration
When to Use:
Session initialization and cleanup
Long-running workflows (>10 minutes)
Multi-agent orchestration
Context window approaching limits (>150K tokens)
Model switches (Haiku ↔ Sonnet)
Workflow phase transitions
Key Principles (2025):
Avoid Last 20% - Performance degrades in final fifth of context
Aggressive Clearing - /clear every 1-3 messages for SPEC workflows
Concept: Load context progressively based on relevance and need.
Progressive Summarization:
defprogressive_summarization(context: str, target_ratio: float = 0.3):
"""Compress context while preserving key information."""# Step 1: Extract key sentences (50K → 15K)
summary = extract_key_sentences(context, ratio=target_ratio)
# Step 2: Add pointers to original content
summary_with_refs = add_content_pointers(summary, context)
# Step 3: Store original for recovery
store_original_context(context, "session_archive")
return summary_with_refs # 35K tokens saved
Context Tagging:
# Bad (high token cost):"The user configuration from the previous 20 messages..."# Good (efficient reference):"Refer to @CONFIG-001 for user preferences"
Use Case: Maintain context continuity while minimizing token overhead.
Advanced Documentation
For detailed patterns and implementation strategies:
Reference Guide - API reference, troubleshooting, best practices
Best Practices
DO
Execute /clear immediately after SPEC creation
Monitor token usage and plan accordingly
Use context-aware token budget tracking
Create checkpoints before major operations
Apply progressive summarization for long workflows
Enable session persistence for recovery
Use session forking for parallel exploration
Keep memory files < 500 lines each
Disable unused MCP servers to reduce overhead
REQUIREMENTS
[HARD] Maintain bounded context history with regular clearing cycles
WHY: Unbounded context accumulation degrades performance and increases token costs exponentially
IMPACT: Prevents context overflow, maintains consistent response quality, reduces token waste by 60-70%
[HARD] Respond to token budget warnings immediately when usage exceeds 150K tokens
WHY: Operating in the final 20% of context window causes significant performance degradation
IMPACT: Ensures optimal model performance, prevents context overflow failures, maintains workflow continuity
[HARD] Execute state validation checks during session recovery operations
WHY: Invalid state can cause workflow failures and data loss in multi-step processes
IMPACT: Guarantees session integrity, prevents silent failures, enables reliable recovery with >95% success rate
[HARD] Persist session identifiers before any context clearing operations
WHY: Session IDs are the only reliable mechanism for resuming interrupted workflows
IMPACT: Enables seamless workflow resumption, prevents work loss, supports multi-agent coordination
[SOFT] Establish clear session boundaries when working with multiple concurrent sessions
WHY: Session mixing causes context contamination and unpredictable agent behavior
IMPACT: Improves debugging clarity, prevents cross-session interference, maintains clean audit trails
[SOFT] Create checkpoint snapshots before assuming session continuity
WHY: Context can be lost due to network issues, timeouts, or system events
IMPACT: Provides recovery points, reduces rework time, maintains user trust in system reliability
[SOFT] Load codebase components progressively using priority tiers
WHY: Loading entire codebases exhausts token budget and includes irrelevant context
IMPACT: Optimizes token usage by 40-50%, improves response relevance, enables larger project support
[SOFT] Limit handoff packages to critical context only
WHY: Non-critical context increases handoff overhead and reduces available working tokens
IMPACT: Speeds up agent transitions by 30%, preserves token budget for actual work, reduces transfer errors
[HARD] Execute context compression or clearing when usage reaches 85% threshold
WHY: Approaching context limits triggers emergency behaviors and reduces model capabilities
IMPACT: Maintains 55K token emergency reserve, prevents forced interruptions, ensures graceful degradation
Works Well With
moai-cc-memory - Memory management and context persistence
moai-cc-configuration - Session configuration and preferences
moai-core-workflow - Workflow state persistence and recovery
moai-cc-agents - Agent state management across sessions