Skip to main content
ClaudeWave
Slash Command193 repo starsupdated 6mo ago

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).

Install in Claude Code
Copy
mkdir -p ~/.claude/commands && curl -fsSL https://raw.githubusercontent.com/VAMFI/claude-user-memory/HEAD/.claude/commands/context.md -o ~/.claude/commands/context.md
Then start a new Claude Code session; the slash command loads automatically.

context.md

# /context - Context Analysis & Optimization

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

## Usage

```bash
/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

```markdown
📊 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

```markdown
✅ 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 tokens: 600
- Stale information: 0 tokens (0%)
- Redundant content: 0 tokens (0%)

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

## Performance Impact

**Expected Improvements** (based on Anthropic research):
- Context-focused tasks: 39% im
brahma-analyzerSubagent

Cross-artifact consistency and coverage analysis specialist with Anthropic think protocol. Validates alignment between specifications, plans, tasks, and implementation. Use before implementation to catch conflicts early.

brahma-deployerSubagent

Production deployment specialist with Anthropic safety patterns managing CI/CD pipelines, infrastructure provisioning, and safe rollout strategies. Defaults to canary deployments with auto-rollback. Use for production deployments and release management.

brahma-investigatorSubagent

Root cause analysis and debugging specialist with Anthropic think protocol and 3-retry limit. Focuses on systematic problem diagnosis, error tracing, and fix validation. Use for complex bugs and system failures.

brahma-monitorSubagent

Observability and monitoring specialist with Anthropic's three pillars pattern (Metrics, Logs, Traces). Sets up comprehensive monitoring, SLI/SLO tracking, and incident detection. Use for system observability and proactive alerting.

brahma-optimizerSubagent

Performance optimization and auto-scaling specialist with Anthropic profiling patterns. Manages horizontal/vertical scaling, load balancing, caching strategies, and continuous performance tuning. Use for scaling challenges and performance work.

chief-architectSubagent

Master orchestrator for complex, multi-faceted software projects. Coordinates specialist agents (researchers, planners, implementers) to deliver cohesive solutions. Use for projects requiring 3+ capabilities or cross-domain work (frontend + backend + devops).

code-implementerSubagent

Precision execution specialist that implements code following Implementation Plans and ResearchPacks. Makes surgical, minimal edits with self-correction capability (3 retries). Always runs tests and validates against plan. Requires both ResearchPack and Implementation Plan as input.

docs-researcherSubagent

High-speed documentation specialist. Fetches version-accurate docs from official sources to prevent coding from stale memory. Use before implementing any feature with external libraries or APIs. Delivers ResearchPack in < 2 minutes.