Skip to content
Agent Orchestration
Command

/context

Analyze and optimize context configuration. Reviews CLAUDE.md, knowledge-core.md, and active context for optimization opportunities. Helps prevent context rot (39% improvement, 84% token reduction).

From plugin
claude-user-memory
2065 skills9 agents5 commands

How it fires

How this command gets triggered: by you, by Claude, or both.

  • Fires itselfClaude auto-loads it when your prompt matches the work.
  • You can call itInvoke it directly when you want it.
  • Slash command/context

Context preview

What this command does when you run it.

Analyze and optimize context configuration. Reviews CLAUDE.md, knowledge-core.md, and active context for optimization opportunities. Helps prevent context rot (39% improvement, 84% token reduction).

Command definition

context.md
name: context
description: Analyze and optimize context configuration. Reviews CLAUDE.md, knowledge-core.md, and active context for optimization opportunities. Helps prevent context rot (39% improvement, 84% token reduction).

/context - Context Analysis & Optimization

Analyze and optimize your Claude Code context configuration using Anthropic's context engineering principles.

Usage

/context                # Analyze mode (default)
/context analyze        # Same as default
/context optimize       # Actively optimize context
/context reset          # Reset to templates

What This Does

Analyze Mode (Default)

When you run `/context` or `/context analyze`:

1. **Read context files**

  • CLAUDE.md (project configuration)
  • knowledge-core.md (accumulated learnings)
  • Imported files (via `@` syntax)

2. **Analyze token count and relevance**

  • Count total tokens in context
  • Identify stale/redundant information
  • Check for context rot indicators

3. **Identify optimization opportunities**

  • Sections that should be archived
  • Redundant content that can be consolidated
  • Missing imports that could improve modularity

4. **Report findings**

  • Current token usage
  • Stale information detected
  • Potential token savings
  • Recommended actions

Optimize Mode

When you run `/context optimize`:

1. **Run analysis** (as above)

2. **Archive stale information**

  • Move outdated patterns to knowledge-core.md historical section
  • Add timestamps to archived content
  • Preserve information for future retrieval

3. **Prune redundant context**

  • Remove duplicate information
  • Consolidate similar sections
  • Replace verbose explanations with concise bullet points

4. **Update CLAUDE.md**

  • Keep only high-signal, project-specific content
  • Use imports for modular organization
  • Ensure clear structure with markdown headings

5. **Report token savings**

  • Before/after token counts
  • Percentage reduction
  • Expected performance improvement

Reset Mode

When you run `/context reset`:

1. **Confirmation prompt**

  • Warns that this will discard current context
  • Asks for explicit confirmation

2. **Restore templates** (if confirmed)

  • CLAUDE.md → `.claude/templates/CLAUDE.md.template`
  • knowledge-core.md → Fresh template
  • Clear project-specific customizations

3. **Fresh start**

  • Ideal for switching to new project
  • Removes accumulated context rot
  • Begins with clean slate

Output Examples

Analyze Mode Output

📊 Context Analysis

## Current Configuration

**Memory Hierarchy**:
- Enterprise: Not configured
- Project: ./CLAUDE.md (450 tokens)
- User: ~/.claude/CLAUDE.md (120 tokens)
- Imports: 3 files (280 tokens)

**Total Context**: 850 tokens

**Files Analyzed**:
- ✓ CLAUDE.md (450 tokens)
- ✓ knowledge-core.md (320 tokens)
- ✓ @.claude/templates/agents-overview.md (100 tokens)
- ✓ @.claude/templates/skills-overview.md (90 tokens)
- ✓ @.claude/templates/workflows-overview.md (90 tokens)

## Optimization Opportunities

### 1. Stale Information in CLAUDE.md (120 tokens)

**Section: "Python Development"**
- Last used: 30 days ago
- Recommendation: Archive to knowledge-core.md (project now uses TypeScript)

**Section: "Deployment to Heroku"**
- Last used: 45 days ago
- Recommendation: Archive to knowledge-core.md (now using Vercel)

**Section: "Generic Testing Tips"**
- Recommendation: Remove (not project-specific, Claude already knows this)

### 2. Redundant Content (80 tokens)

**Duplicated Information**:
- Git workflow mentioned in 3 places (CLAUDE.md, workflows-overview.md, agents-overview.md)
- Recommendation: Keep in workflows-overview.md only, import elsewhere

### 3. Missing Modularity

**Large CLAUDE.md File**:
- Could be split into modular imports
- Recommendation: Create `project-architecture.md`, import with `@.claude/project-architecture.md`

## Potential Savings

**If all recommendations applied**:
- Stale information removal: 120 tokens (14% reduction)
- Redundancy elimination: 80 tokens (9% reduction)
- Modularity improvements: 50 tokens (6% reduction)

**Total Potential Savings**: 250 tokens (29% reduction)

**Expected Impact**:
- Performance improvement: ~39% (Anthropic research on context engineering)
- Token reduction in long sessions: ~84%
- Clearer, more focused context
- Better agent decision-making

## Recommendations

**Immediate Actions**:
1. Run `/context optimize` to automatically apply changes
2. Review knowledge-core.md after optimization to ensure important information preserved

**Periodic Maintenance**:
- Run `/context analyze` every 50 messages or major task switch
- Archive completed work to knowledge-core.md
- Keep CLAUDE.md project-specific (remove generic advice)

**Best Practices**:
- Be specific: "Use 2-space indentation for JS" not "Format code properly"
- Use structure: Organize with clear markdown headings
- Review periodically: Update as project evolves

Optimize Mode Output

✅ Context Optimized

## Changes Applied

### 1. Archived Stale Information

**To knowledge-core.md**:
- "Python Development" section → `## Historical: Python Setup (archived 2025-10-18)`
- "Deployment to Heroku" section → `## Historical: Heroku Deployment (archived 2025-10-18)`

### 2. Removed Redundant Content

**From CLAUDE.md**:
- Removed generic testing tips (not project-specific)
- Removed duplicate git workflow (kept import from workflows-overview.md)

### 3. Improved Modularity

**Created**:
- `.claude/project-architecture.md` (150 tokens)
  - Moved architecture details from CLAUDE.md
  - Imported in CLAUDE.md with `@.claude/project-architecture.md`

**Updated CLAUDE.md**:
- Replaced verbose architecture section with import
- Clearer structure with focused sections

## Results

**Before Optimization**:
- Total tokens: 850
- Stale information: 120 tokens (14%)
- Redundant content: 80 tokens (9%)

**After Optimization**:
- Total t
Read more
Ships withclaude-user-memory

Research-first development system for Claude Code CLI No API hallucinations. No coding from stale training data. Research → Plan → Implement.

Get the whole plugin