ajbcoding/claude-skill-eval/moai-alfred-session-state

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Enterprise session state management, token budget optimization, runtime tracking, session handoff protocols, context continuity for Claude Sonnet 4.5 and Haiku 4.5 with context awareness features

Install

npx vskill@latest install ajbcoding/claude-skill-eval/moai-alfred-session-state

SKILL.md

Alfred Session State Management Skill (Enterprise v4.0.0)

Skill Metadata

FieldValue
Skill Namemoai-alfred-session-state
Version4.0.0 (Enterprise)
Updated2025-11-12
StatusActive
TierAlfred
Supported ModelsClaude Sonnet 4.5, Claude Haiku 4.5
Context Window200K tokens (Sonnet/Haiku), 500K tokens (Enterprise), 1M tokens (beta)
Key FeaturesContext Awareness, Token Budget Tracking, Session Persistence, Adaptive Recovery

What It Does

Provides enterprise-grade session state management for extended workflows, token budget optimization, runtime tracking, and handoff protocols to maintain context continuity across Alfred workflows and session boundaries.

Enterprise v4.0.0 Capabilities:

  • ✅ Context-aware token budget management (November 2025 Claude API features)
  • ✅ Session persistence with automatic history loading
  • ✅ Session forking for parallel exploration
  • ✅ Incremental multi-pack index optimization (Git 2.47+ integration)
  • ✅ Context continuity across handoffs with state snapshots
  • ✅ Progressive disclosure for memory efficiency
  • ✅ Adaptive recovery checkpoints
  • ✅ Multi-agent coordination protocols
  • ✅ Memory file state synchronization
  • ✅ Token budget awareness callbacks (Sonnet/Haiku 4.5 feature)

When to Use

Automatic triggers:

  • Session start/end events
  • Long-running task execution (>10 minutes)
  • Multi-agent handoffs
  • Context window approaching limits
  • Model switches (Haiku ↔ Sonnet)
  • Workflow phase transitions

Manual reference:

  • Session state debugging and recovery
  • Token budget optimization strategies
  • Handoff protocol design
  • Context continuity planning
  • Multi-session workflow design

Token Budget Management (November 2025)

Context Awareness Feature

Claude Sonnet 4.5 and Haiku 4.5 feature built-in context awareness, enabling these models to:

  • Track remaining context window ("token budget") throughout conversation
  • Understand current position within 200K token limit (Sonnet/Haiku)
  • Execute adaptive strategies based on available tokens
  • Automatically manage context without manual intervention

Key Advantage: Models now self-regulate context usage in real time.

Token Budget Optimization Framework
Token Allocation Strategy (200K Sonnet context):
├── System Prompt & Instructions: ~15K tokens (7.5%)
│ ├── CLAUDE.md: ~8K
│ ├── Command definitions: ~4K
│ └── Skill metadata: ~3K
├── Active Conversation: ~80K tokens (40%)
│ ├── Recent messages: ~50K
│ ├── Context cache: ~20K
│ └── Active references: ~10K
├── Reference Context (Progressive Disclosure): ~50K (25%)
│ ├── Project structure: ~15K
│ ├── Related Skills: ~20K
│ └── Tool definitions: ~15K
└── Reserve (Emergency Recovery): ~55K tokens (27.5%)
├── Session state snapshot: ~10K
├── TAGs and cross-references: ~15K
├── Error recovery context: ~20K
└── Free buffer: ~10K
Optimization Techniques (v4.0.0)

Technique 1: Progressive Summarization

Step 1: Original context (50K tokens)
Step 2: Compress to summary (15K tokens)
Step 3: Add pointers to original → 35K tokens saved
Step 4: Carry forward summary only across handoffs

Technique 2: Context Tagging with Unique Identifiers

❌ Bad (high token cost):
"The user configuration from the previous 20 messages..."
✅ Good (efficient reference):

Technique 3: Structured Context Architecture

├── Critical Context (ALWAYS keep)
│ ├── Current task objectives
│ ├── User preferences & expertise level
│ └── Active constraints
├── Supporting Context (keep if space allows)
│ ├── Related history
│ ├── Reference documentation
│ └── Tool availability
└── Temporary Context (discard when not needed)
├── Raw tool outputs
├── Intermediate calculations
└── Debug information

Technique 4: MCP Server Context Budget

bash
# Check MCP server context consumption
/context
# Result: Each enabled MCP server adds tool definitions
# Example: context7 MCP = ~2K tokens for tool definitions
# Optimization: Disable unused servers before critical tasks
# Typical savings: 5-10K tokens per unused MCP server

Technique 5: Task-Based Session Management

Strategy: Start new conversation for distinct tasks
Benefits:
- Fresh 200K token budget per task
- Eliminates stale context accumulation
- Enables parallel session forking
- Improves recovery speed
Implementation:
1. Complete current task in Session A
2. Save session snapshot to .moai/sessions/
3. Start Session B for new task with fresh context
4. Resume Session A later if needed via session ID

Session State Architecture (Enterprise v4.0.0)

State Layers
Session State Stack (Enterprise v4.0.0):
├── L1: Context-Aware Layer (Claude 4.5+ feature)
│ ├── Token budget tracking
│ ├── Context window position
│ ├── Auto-summarization triggers
│ └── Model-specific optimizations
├── L2: Active Context (current task, variables, scope)
├── L3: Session History (recent actions, decisions)
├── L4: Project State (SPEC progress, milestones)
├── L5: User Context (preferences, language, expertise)
└── L6: System State (tools, permissions, environment)
Session Creation & Persistence

Agent SDK Session Management (November 2025 API):

json
{
"session_id": "sess_uuid_v4",
"model": "claude-sonnet-4-5-20250929",
"created_at": "2025-11-12T10:30:00Z",
"context_window": {
"total": 200000,
"used": 85000,
"available": 115000,
"position_percent": 42.5
},
"persistence": {
"auto_load_history": true,
"context_preservation": "critical_only",
"cache_enabled": true
},
"forking": {
"enabled": true,
"fork_session_id": "sess_fork_uuid",
"checkpoint_timestamp": "2025-11-12T10:30:00Z"
}
}
Session Resumption Pattern
python
# Capture session ID from initial response
session_id = extract_session_id(response)
# Save for later use
save_session_checkpoint({
'session_id': session_id,
'timestamp': now(),
'model': 'claude-sonnet-4-5',
'context_state': current_context_snapshot()
})
# Later: Resume conversation
response = claude.messages.create(
model="claude-sonnet-4-5-20250929",
resume=session_id, # Continue from checkpoint
messages=[new_message]
)
# Or: Fork session for parallel exploration
response = claude.messages.create(
model="claude-sonnet-4-5-20250929",
fork_session=session_id, # Branch from checkpoint
messages=[alternative_message]
)

Runtime State Tracking

Task State Machine (Enterprise v4.0.0)
Workflow State Transitions:
pending → in_progress → blocked (waiting) → completed/failed
↓ ↓
[monitor token budget] [save checkpoint]
[track elapsed time] [update history]
[check for recovery] [archive state]

Task Lifecycle States:

  • pending - Queued but not started
  • in_progress - Currently executing (monitor tokens)
  • blocked - Waiting for dependencies or input
  • token_warning - Approaching context limit (v4.0.0)
  • context_switch - Model change or session fork
  • completed - Finished successfully
  • failed - Error occurred, initiating recovery
  • recovered - Resumed from checkpoint
Token Budget Callbacks (Haiku/Sonnet 4.5 Feature)
python
def token_budget_callback(context):
"""
Called automatically when token budget changes.
Model provides real-time context awareness.
"""
remaining_tokens = context.available_tokens
used_percent = context.token_usage_percent
if used_percent > 85:
# Activate emergency summarization
compress_context_window()
archive_old_context()
elif used_percent > 75:
# Start progressive disclosure
defer_non_critical_context()
elif used_percent > 60:
# Monitor for safety
track_context_growth()

Session Handoff Protocols

Inter-Agent Handoff Package (Enterprise v4.0.0)
json
{
"handoff_id": "uuid-v4",
"timestamp": "2025-11-12T10:30:00Z",
"from_agent": "spec-builder",
"to_agent": "tdd-implementer",
"session_context": {
"session_id": "sess_uuid",
"model": "claude-sonnet-4-5-20250929",
"context_position": 42.5,
"available_tokens": 115000,
"user_language": "ko",
"expertise_level": "intermediate",
"current_project": "MoAI-ADK"
},
"task_context": {
"spec_id": "SPEC-001",
"current_phase": "implementation",
"completed_steps": ["spec_complete", "architecture_defined"],
"next_step": "write_tests",
"constraints": ["must_use_pytest", "coverage_85"]
},
"context_snapshot": {
"critical_context": "...compressed...",
"session_checkpoints": [...],
"active_todos": [...],
"token_budget_strategy": "progressive_summarization"
},
"recovery_info": {
"last_checkpoint": "2025-11-12T10:25:00Z",
"recovery_tokens_reserved": 55000,
"session_fork_available": true
}
}
Handoff Validation (Enterprise v4.0.0)
python
def validate_handoff(handoff_package):
"""Enterprise validation with token budget check"""
required_fields = [
'handoff_id', 'from_agent', 'to_agent',
'session_context', 'task_context', 'context_snapshot'
]
for field in required_fields:
if field not in handoff_package:
raise HandoffError(f"Missing required field: {field}")
# NEW v4.0.0: Validate token budget
context = handoff_package['session_context']
available = context['available_tokens']
if available < 30000: # Minimum safe buffer
trigger_context_compression()
# Validate agent compatibility
if not can_agents_cooperate(
handoff_package['from_agent'],
handoff_package['to_agent']
):
raise AgentCompatibilityError("Agents cannot cooperate")
return True

Session Recovery (Enterprise v4.0.0)

Recovery Checkpoints

Checkpoint Triggers:

  • Task phase boundaries (before RED, GREEN, REFACTOR)
  • Agent handoffs
  • User interruptions
  • Token budget thresholds
  • Error conditions
  • Session timeouts

Checkpoint Structure:

json
{
"checkpoint_id": "ckpt_uuid",
"timestamp": "2025-11-12T10:30:00Z",
"phase": "GREEN",
"token_usage": {
"used": 85000,
"available": 115000
},
"context_snapshot": "...compressed snapshot...",
"session_id": "sess_uuid",
"recovery_tokens_reserved": 55000
}
Recovery Process (Enterprise v4.0.0)
  1. State Restoration - Reload last valid checkpoint
  2. Context Validation - Verify token budget sufficient
  3. Session Resumption - Use Agent SDK resume feature
  4. Progress Assessment - Determine what was completed
  5. Continuation Planning - Decide next steps with updated token budget
  6. User Notification - Inform user of recovery status

Memory State Synchronization

Memory Files (v4.0.0)

Files:

  • .moai/sessions/session-state.json - Current session metadata
  • .moai/sessions/context-cache.json - Cached context for performance
  • .moai/sessions/checkpoints/ - Saved recovery checkpoints
  • .moai/sessions/token-usage.log - Token budget history
  • active-tasks.md - TodoWrite task tracking

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 95 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
4
7-day trend score
8

Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 30 Mar 2026, 7 months ago.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/ajbcoding/claude-skill-eval/moai-alfred-session-state/badge)](https://verified-skill.com/skills/ajbcoding/claude-skill-eval/moai-alfred-session-state)

Something wrong with this skill or its page? Tell us.