ajbcoding/claude-skill-eval/moai-alfred-context-budget

Trust tier 3
  • community
Source check pending

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

Enterprise Claude Code context window optimization with 2025 best practices: aggressive clearing, memory file management, MCP optimization, strategic chunking, and quality-over-quantity principles for 200K token context windows.

Install

npx vskill@latest install ajbcoding/claude-skill-eval/moai-alfred-context-budget

SKILL.md

moai-alfred-context-budget

Enterprise Context Window Optimization for Claude Code

Overview

Enterprise-grade context window management for Claude Code covering 200K token optimization, aggressive clearing strategies, memory file management, MCP server optimization, and 2025 best practices for maintaining high-quality AI-assisted development sessions.

Core Capabilities:

  • ✅ Context budget allocation (200K tokens)
  • ✅ Aggressive context clearing patterns
  • ✅ Memory file optimization (<500 lines each)
  • ✅ MCP server efficiency monitoring
  • ✅ Strategic chunking for long-running tasks
  • ✅ Quality-over-quantity principles

Quick Reference

When to Use This Skill

Automatic Activation:

  • Context window approaching 80% usage
  • Performance degradation detected
  • Session handoff preparation
  • Large project context management

Manual Invocation:

Skill("moai-alfred-context-budget")
Key Principles (2025)
  1. Avoid Last 20% - Performance degrades in final fifth of context
  2. Aggressive Clearing - /clear every 1-3 messages for quality
  3. Lean Memory Files - Keep each file < 500 lines
  4. Disable Unused MCPs - Each server adds tool definitions
  5. Quality > Quantity - 10% with relevant info beats 90% with noise

Pattern 1: Context Budget Allocation

Overview

Claude Code provides 200K token context window with strategic allocation across system, tools, history, and working context.

Context Budget Breakdown
yaml
# Claude Code Context Budget (200K tokens)
Total Context Window: 200,000 tokens
Allocation:
System Prompt: 2,000 tokens (1%)
- Core instructions
- CLAUDE.md project guidelines
- Agent directives
Tool Definitions: 5,000 tokens (2.5%)
- Read, Write, Edit, Bash, etc.
- MCP server tools (Context7, Playwright, etc.)
- Skill() invocation metadata
Session History: 30,000 tokens (15%)
- Previous messages
- Tool call results
- User interactions
Project Context: 40,000 tokens (20%)
- Memory files (.moai/memory/)
- Key source files
- Documentation snippets
Available for Response: 123,000 tokens (61.5%)
- Current task processing
- Code generation
- Analysis output
Monitoring Context Usage
bash
# Check current context usage
/context
# Example output interpretation:
# Context Usage: 156,234 / 200,000 tokens (78%)
# ⚠️ WARNING: Approaching 80% threshold
# Action: Consider /clear or archive old discussions
Context Budget Anti-Patterns
yaml
# BAD: Unoptimized Context
Session History: 80,000 tokens (40%) # Too much history
- 50 messages of exploratory debugging
- Stale error logs from 2 hours ago
- Repeated "try this" iterations
Project Context: 90,000 tokens (45%) # Too much loaded
- Entire src/ directory (unnecessary)
- node_modules types (never needed)
- 10 documentation files (only need 2)
Available for Response: 23,000 tokens (11.5%) # TOO LOW!
- Can't generate quality code
- Forced to truncate responses
- Poor reasoning quality
# GOOD: Optimized Context
Session History: 15,000 tokens (7.5%) # Cleared regularly
- Only last 5-7 relevant messages
- Current task discussion
- Key decisions documented
Project Context: 25,000 tokens (12.5%) # Targeted loading
- 3-4 files for current task
- CLAUDE.md (always)
- Specific memory files (on-demand)
Available for Response: 155,000 tokens (77.5%) # OPTIMAL!
- High-quality code generation
- Deep reasoning capacity
- Complex refactoring support

Pattern 2: Aggressive Context Clearing

Overview

The /clear command should become muscle memory, executed every 1-3 messages to maintain output quality.

When to Clear Context
typescript
// Decision Tree for /clear Usage
interface ContextClearingStrategy {
trigger: string;
frequency: string;
action: string;
}
const clearingStrategies: ContextClearingStrategy[] = [
{
trigger: "Task completed",
frequency: "Every task",
action: "/clear immediately after success"
},
{
trigger: "Context > 80%",
frequency: "Automatic",
action: "/clear + document key decisions in memory file"
},
{
trigger: "Debugging session",
frequency: "Every 3 attempts",
action: "/clear stale error logs, keep only current"
},
{
trigger: "Switching tasks",
frequency: "Every switch",
action: "/clear + update session-summary.md"
},
{
trigger: "Poor output quality",
frequency: "Immediate",
action: "/clear + re-state requirements concisely"
}
];
Clearing Workflow Pattern
bash
#!/bin/bash
# Example: Task completion workflow with clearing
# Step 1: Complete current task
implement_feature() {
echo "Implementing authentication..."
# ... work done ...
echo "✓ Authentication implemented"
}
# Step 2: Document key decisions BEFORE clearing
document_decision() {
cat >> .moai/memory/auth-decisions.md <<EOF
## Authentication Implementation ($(date +%Y-%m-%d))
**Approach**: JWT with httpOnly cookies
**Rationale**: Prevents XSS attacks, CSRF protection via SameSite
**Key Files**: src/auth/jwt.ts, src/middleware/auth-check.ts
EOF
}
# Step 3: Clear context
# /clear
# Step 4: Start fresh with next task
start_next_task() {
echo "Context cleared. Starting API rate limiting..."
}
# Workflow
implement_feature
document_decision
# User manually executes: /clear
# start_next_task
What to Clear vs Keep
yaml
# ✅ ALWAYS CLEAR (After Documenting)
Clear:
- Exploratory debugging sessions
- "Try this" iteration history
- Stale error logs
- Completed task discussions
- Old file diffs
- Abandoned approaches
# 📝 DOCUMENT BEFORE CLEARING
Document First:
- Key architectural decisions
- Non-obvious implementation choices
- Failed approaches (why they failed)
- Performance insights
- Security considerations
# ❌ NEVER CLEAR (Part of Project Context)
Keep:
- CLAUDE.md (project guidelines)
- Active memory files
- Current task requirements
- Ongoing conversation
- Recent (< 3 messages) exchanges

Pattern 3: Memory File Management

Overview

Memory files are read at session start, consuming context tokens. Keep them lean and focused.

Memory File Structure (Best Practices)
.moai/memory/
├── session-summary.md # < 300 lines (current session state)
├── architectural-decisions.md # < 400 lines (ADRs)
├── api-contracts.md # < 200 lines (interface specs)
├── known-issues.md # < 150 lines (blockers, workarounds)
└── team-conventions.md # < 200 lines (code style, patterns)
Total Memory Budget: < 1,250 lines (~25K tokens)
Memory File Template
markdown
<!-- .moai/memory/session-summary.md -->
# Session Summary
**Last Updated**: 2025-01-12 14:30
**Current Sprint**: Feature/Auth-Refactor
**Active Tasks**: 2 in progress, 3 pending
## Current State
### ✅ Completed This Session
1.JWT authentication implementation (commit: abc123)
2.Password hashing with bcrypt (commit: def456)
### 🔄 In Progress
1.OAuth2 integration (70% complete)
-Provider setup done
-Callback handler in progress
-Files: src/auth/oauth.ts
### 📋 Pending
1.Rate limiting middleware
2.Session management
3.CSRF protection
## Key Decisions
**Auth Strategy**: JWT in httpOnly cookies (XSS prevention)
**Password Min Length**: 12 chars (OWASP 2025 recommendation)
## Blockers
None currently.
## Next Actions
1.Complete OAuth callback handler
2.Add tests for OAuth flow
3.Document OAuth setup in README
Memory File Anti-Patterns
markdown
<!-- ❌ BAD: Bloated Memory File (1,200 lines) -->
# Session Summary
## Completed Tasks (Last 3 Weeks)
<!-- 800 lines of old task history -->
<!-- This is what git commit history is for! -->
## All Code Snippets Ever Written

// 400 lines of full code snippets // Should be in git, not memory files

<!-- ✅ GOOD: Lean Memory File (180 lines) -->
# Session Summary
**Last Updated**: 2025-01-12 14:30
## Active Work (This Session)
- OAuth integration: 70% (src/auth/oauth.ts)
- Blocker: None
## Key Decisions (Last 7 Days)
1. Auth: JWT in httpOnly cookies (XSS prevention)
2. Hashing: bcrypt, cost factor 12
## Next Actions
1. Complete OAuth callback
2. Add OAuth tests
3. Update README
<!-- Archive older content to .moai/memory/archive/ -->
Memory File Rotation Strategy
bash
#!/bin/bash
# Rotate memory files when they exceed limits
rotate_memory_file() {
local file="$1"
local max_lines=500
local current_lines=$(wc -l < "$file")
if [[ $current_lines -gt $max_lines ]]; then
echo "Rotating $file ($current_lines lines > $max_lines limit)"
# Archive old content
local timestamp=$(date +%Y%m%d)
local archive_dir=".moai/memory/archive"
mkdir -p "$archive_dir"
# Keep only recent content (last 300 lines)
tail -n 300 "$file" > "${file}.tmp"
# Archive full file
mv "$file" "${archive_dir}/$(basename "$file" .md)-${timestamp}.md"
# Replace with trimmed version
mv "${file}.tmp" "$file"
echo "✓ Archived to ${archive_dir}/"
fi
}
# Check all memory files
for file in .moai/memory/*.md; do
rotate_memory_file "$file"
done

Pattern 4: MCP Server Optimization

Overview

Each enabled MCP server adds tool definitions to system prompt, consuming context tokens. Disable unused servers.

MCP Context Impact
json
// .claude/mcp.json - Context-optimized configuration
{
"mcpServers": {
// ✅ ENABLED: Active development tools
"context7": {
"command": "npx",
"args": ["-y", "@context7/mcp"],
"env": {
"CONTEXT7_API_KEY": "your-key"
}
},
// ❌ DISABLED: Not needed for current project
// "playwright": {
// "command": "npx",
// "args": ["-y", "@playwright/mcp"]
// },
// ✅ ENABLED: Documentation research
"sequential-thinking": {
"command": "npx",
"args": ["-y", "@sequential-thinking/mcp"]
}
// ❌ DISABLED: Slackbot not in use
// "slack": {
// "command": "npx",
// "args": ["-y", "@slack/mcp"]
// }
}
}
Measuring MCP Overhead
bash
# Monitor MCP context usage
/context
# Example output:
# MCP Servers (3 enabled):
# - context7: 847 tokens (tool definitions)
# - sequential-thinking: 412 tokens
# - playwright: 1,234 tokens (DISABLED to save tokens)
#
# Total MCP Overhead: 1,259 tokens
MCP Usage Strategy

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 1 Apr 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-context-budget/badge)](https://verified-skill.com/skills/ajbcoding/claude-skill-eval/moai-alfred-context-budget)

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