Back to Skills

context-optimizer

verified

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 GitHub

Marketplace

specweave

anton-abyzov/specweave

Plugin

sw

development

Repository

anton-abyzov/specweave
27stars

plugins/specweave/skills/context-optimizer/SKILL.md

Last Verified

January 25, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/anton-abyzov/specweave/blob/main/plugins/specweave/skills/context-optimizer/SKILL.md -a claude-code --skill context-optimizer

Installation paths:

Claude
.claude/skills/context-optimizer/
Powered by add-skill CLI

Instructions

# 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;

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
14919 chars