Waste Detection Engine
Relevant source files
The following files were used as context for generating this wiki page:
The Waste Detection Engine is a core diagnostic framework designed to identify context window inefficiencies, unnecessary token expenditure, and architectural anti-patterns within agentic systems. It operates across multiple platforms, including Claude Code, Codex, and OpenClaw, to recover context budget and reduce operational costs. Sources: skills/fleet-auditor/SKILL.md:1-5, skills/token-optimizer/SKILL.md:1-10
The engine categorizes waste into two primary domains: Static Config Analysis, which examines configuration files for bloat and misrouting, and Session Log Analysis, which utilizes parsed run data to identify behavioral inefficiencies such as looping or empty heartbeat runs. Sources: skills/fleet-auditor/references/waste-patterns.md:5-10
Detection Architecture
The engine utilizes a tiered detection strategy to ensure comprehensive coverage of the agent's environment and execution history.
The diagram shows the flow from initial system detection to the generation of a prioritized optimization plan. Sources: skills/token-optimizer/SKILL.md:200-240, skills/fleet-auditor/references/waste-patterns.md:5-70
Multi-Agent Audit Workflow
In Phase 1 of the optimization cycle, the engine dispatches six specialized audit agents in parallel. Each agent is assigned a specific model tier based on the complexity of the data gathering or judgment required. Sources: skills/token-optimizer/SKILL.md:220-235, skills/token-optimizer/references/agent-prompts.md:14-17
| Auditor Agent | Model | Focus Area |
|---|---|---|
| CLAUDE.md | Sonnet | Size, duplication, tiered content, cache structure. |
| MEMORY.md | Sonnet | Size, overlap with global configurations. |
| Skills | Sonnet | Frontmatter overhead, duplicate logic, unused domains. |
| MCP | Sonnet | Tool Search status, deferred tools, broken auth. |
| Commands | Haiku | Count and menu overhead. |
| Settings | Sonnet | Hooks, rules, path-scoping, and model routing. |
Sources: skills/token-optimizer/SKILL.md:225-235, skills/token-optimizer/references/agent-prompts.md:21-25
Waste Patterns and Thresholds
The engine identifies specific signals that indicate context waste, applying thresholds and confidence levels to each finding. Sources: skills/fleet-auditor/references/waste-patterns.md:1-4
Static Analysis Patterns (Tier 1)
Static patterns are verified against configuration files without requiring session history. Sources: skills/fleet-auditor/references/waste-patterns.md:7-8
- Heartbeat Model Waste: Triggered when a non-Haiku model (Opus/Sonnet) is used for scheduled tasks costing >$0.10/month. Sources: skills/fleet-auditor/references/waste-patterns.md:11-15
- Skill Bloat: Identifies overhead when >10 skills are loaded per agent. Each skill contributes ~100 tokens to the frontmatter menu every session. Sources: skills/fleet-auditor/references/waste-patterns.md:26-31, skills/token-coach/references/coach-patterns.md:6-10
- Unscoped Rules: Rules in
.claude/rules/lackingpaths:frontmatter are flagged as they load on every message, regardless of context. Sources: skills/token-coach/references/coach-patterns.md:104-108
Session Behavioral Patterns (Tier 2)
Session patterns require parsed data from fleet.db or individual session logs. Sources: skills/fleet-auditor/references/waste-patterns.md:52-53
- Empty Heartbeat Runs: The highest priority waste pattern. Occurs when input context >5K tokens but output <100 tokens with minimal messaging. Sources: skills/fleet-auditor/references/waste-patterns.md:55-60
- Loop Detection: Identified by a high input-to-output ratio (>20:1) in sessions exceeding 10 messages, suggesting the agent is "stuck" reading context without progress. Sources: skills/fleet-auditor/references/waste-patterns.md:70-75
- Abandoned Sessions: Sessions with large input tokens (>3K) but only 1-2 messages, indicating context was loaded but the task was never executed. Sources: skills/fleet-auditor/references/waste-patterns.md:78-82
Optimization Synthesis and Verification
Once audits are complete, a Synthesis Agent (preferred model: Opus) reads all findings to calculate a "Baseline Overhead" and prioritize actions. Sources: skills/token-optimizer/references/agent-prompts.md:244-255
Synthesis Logic
The engine prioritizes "Quick Wins" (high impact, low effort) over "Deep Optimizations." Sources: skills/token-optimizer/references/agent-prompts.md:260-270
- Baseline Calculation: Sums tokens from
CLAUDE.md,MEMORY.md, Skills menu, and MCP definitions. Sources: skills/token-optimizer/references/agent-prompts.md:264-270 - Model Routing Analysis: Evaluates if >70% of tokens go to expensive models for tasks manageable by Haiku. Sources: skills/token-optimizer/references/agent-prompts.md:275-285
- Behavioral Coaching: Recommends habits like
/clearor/compactat 50-70% context fill. Sources: skills/token-coach/references/coach-patterns.md:100-102, skills/token-optimizer/references/agent-prompts.md:273-275
Verification Cycle
Post-implementation, a Verification Agent (Haiku) re-measures the environment to quantify realized savings. Sources: skills/token-optimizer/references/agent-prompts.md:291-300
Core Configuration Benchmarks
The engine uses the following targets for an optimized system:
- Global CLAUDE.md: Target < 800 tokens. Sources: skills/token-coach/references/coach-patterns.md:86-88
- Skill Description: Under 200 characters (trigger-rich). Sources: skills/token-coach/references/coach-patterns.md:7-8
- Skill Frontmatter Truncation: Combined
description+when_to_usemust not exceed 1,536 characters (Claude Code limit). Sources: skills/token-optimizer/references/implementation-playbook.md:214-220 - Compaction Frequency: Triggered at 50-70% context fill to maintain performance quality. Sources: skills/token-coach/references/coach-patterns.md:100-101
The Waste Detection Engine serves as a continuous feedback loop, ensuring that as agents evolve, their configurations remain lean and their model routing stays cost-effective. Sources: skills/fleet-auditor/SKILL.md:5-10, skills/token-optimizer/references/agent-prompts.md:310-315