Second-pass context optimization that analyzes user prompts and removes irrelevant specs, agents, and skills from loaded context. Achieves 80%+ token reduction through smart cleanup. Activates for optimize context, reduce tokens, clean context, smart context, precision loading.
View on GitHubanton-abyzov/specweave
sw
January 25, 2026
Select agents to install to:
npx add-skill https://github.com/anton-abyzov/specweave/blob/main/plugins/specweave/skills/context-optimizer/SKILL.md -a claude-code --skill context-optimizerInstallation paths:
.claude/skills/context-optimizer/# Context Optimizer
Second-pass context optimization that analyzes user intent and surgically removes irrelevant content from loaded context, achieving 80%+ total token reduction.
## Purpose
After `context-loader` loads context based on manifest (70% reduction), `context-optimizer` performs intelligent analysis of the user's specific prompt to remove sections that aren't needed for that particular task.
## The Two-Pass Strategy
### Pass 1: Context Loader (Manifest-Based)
```yaml
# context-manifest.yaml
spec_sections:
- auth-spec.md
- payment-spec.md
- user-management-spec.md
Result: Load only relevant specs (70% reduction)
Before: 150k tokens → After: 45k tokens
```
### Pass 2: Context Optimizer (Intent-Based)
```typescript
User: "Fix authentication bug in login endpoint"
Analyzer detects:
• Task type: Bug fix (not new feature)
• Domain: Backend auth
• Scope: Single endpoint
Removes:
❌ payment-spec.md (different domain)
❌ user-management-spec.md (different domain)
❌ PM agent description (not needed for bug fix)
❌ Frontend skills (backend task)
❌ DevOps skills (not deploying)
Keeps:
✅ auth-spec.md (directly relevant)
✅ architecture/security/ (auth considerations)
✅ nodejs-backend skill (implementation)
✅ Tech Lead agent (code review)
Result: Additional 40% reduction
After Pass 1: 45k tokens → After Pass 2: 27k tokens
Total reduction: 82% (150k → 27k)
```
## When to Use
**Activates automatically** after context-loader when:
- User prompt is specific (mentions feature, bug, file)
- Loaded context > 20k tokens
- Task is focused (not "build full product")
**Manual activation:**
- "optimize context"
- "reduce tokens"
- "clean context"
**Skip when:**
- Context already small (<10k tokens)
- User asks broad questions ("explain architecture")
- Planning new features (need full context)
## What It Does
### 1. User Intent Analysis
```typescript
interface IntentAnalysis {
task_type: TaskType;
domains: Domain[];
scope: Scope;