skyfom-tokens-efficiency
npx machina-cli add skill SkyfomLabs/skyfom-claude-orchestration/skyfom-tokens-efficiency --openclawSkyfom Tokens Efficiency
Token optimization and management for multi-agent orchestration.
Core Principles
- Estimate Before Execute - Calculate token cost before spawning agents
- Split Large Tasks - Auto-split tasks estimated >100k tokens
- Track Consumption - Monitor token usage in real-time
- Warn at Threshold - Alert at 160k tokens, act at 180k
- Summarize & Resume - Create summary, spawn fresh agent
Token Limits
| Metric | Value | Action |
|---|---|---|
| Ideal per agent | 100,000 | Target for task planning |
| Warning threshold | 160,000 | Create summary file |
| Hard limit | 200,000 | Must spawn new agent |
| Epic maximum | 1,000,000 | Split into multiple phases |
Token Estimation
See workflows/estimation.md for detailed formulas and examples.
Formula
tokens ≈ characters × 0.25
Task Complexity
| Size | Tokens | Examples |
|---|---|---|
| Trivial | <5k | Config changes, typos, simple fixes |
| Small | 5k-25k | Single component, basic feature |
| Medium | 25k-75k | Multi-component feature, API endpoint |
| Large | 75k-150k | Complex feature, multiple files |
| Epic | >150k | Requires splitting into subtasks |
PM/CTO Workflow
See workflows/task-splitting.md for detailed process.
Before Creating Tasks
- Analyze Epic - Calculate estimated tokens from description
- Estimate Complexity - Count requirements × avg tokens per requirement
- Auto-Split if >100k - Break into logical subtasks <100k each
- Create Dependencies - Document task relationships
Task Template
bd create "Task: $title" \
-d "## Requirements\n...\n## Token Estimate\n~$tokens tokens" \
--json
Agent Token Tracking
See workflows/monitoring.md for tracking implementation.
During Execution
Agents track usage in .claude/state/agents.json:
{
"id": "agent-abc123",
"tokenUsage": 85000,
"tokenEstimate": 100000,
"warnings": []
}
Checkpoints
Monitor at: 50k, 100k, 160k, 180k, 200k tokens
Warning Response (160k tokens)
See workflows/summary-creation.md for complete process and template.
Actions
- Create summary file (completed/remaining work, context)
- Save to
.claude/state/agent-$id-summary.md - Spawn new agent referencing summary with @file
- Update state (mark old completed, link new)
Communication Efficiency
See reference/communication.md for best practices.
| Format | Use For | Token Savings |
|---|---|---|
| JSON | Structured data | 60% vs prose |
| Emoji status | Quick updates | 90% vs full sentences |
| Tables | Comparisons | 70% vs paragraphs |
| References | Context | 95% vs repetition |
Agent-to-PM Status
✅ bd-xyz - PR #42 (85k tokens, 3 loops)
🔄 bd-abc - Implementing (45k tokens)
❌ bd-def - Blocked by dependency
Token Budget Management
Epic-Level Budget
task_count=$(bd list --parent $epic_id | wc -l)
total_budget=$((task_count * 75000)) # 75k avg per task
consumed=$(jq '.metrics.totalTokensUsed' .claude/state/orchestration.json)
remaining=$((total_budget - consumed))
Phase-Level Limits
- Phase 1 (Planning): ~50k tokens
- Phase 2 (Implementation): ~400k tokens (7 agents × ~60k avg)
- Phase 3 (Review): ~100k tokens
- Phase 4 (CI/CD): ~20k tokens
- Phase 5 (Integration): ~30k tokens
Total Phase Budget: ~600k tokens
Cost Optimization
Model Selection
| Model | Use For | Cost |
|---|---|---|
| Haiku | Routine ops, status checks, simple fixes | ~1/20th Sonnet |
| Sonnet | Architecture, complex implementation, code review | Standard |
Best Practices
- Avoid Repeated Context - Use @file references and summary files
- Batch Operations - Review multiple files in one session
- Link to Beads - Reference task IDs instead of repeating details
- Concise Updates - Use emoji status, not full sentences
Integration with Orchestration
Hooks
Token tracking via PostToolUse hook:
# Update .claude/state/agents.json with token usage
State Management
Track in orchestration.json:
{
"metrics": {
"totalTokensUsed": 338000,
"averageTokensPerTask": 67600,
"tokensPerAgent": {...}
}
}
Monitoring
See workflows/monitoring.md for setup.
# Watch total usage
watch -n 5 'jq ".metrics.totalTokensUsed" .claude/state/orchestration.json'
# Check per-agent
jq '.[] | {id, tokenUsage}' .claude/state/agents.json
Alerts
- Individual agent >160k tokens → Create summary
- Total phase >600k tokens → Review task breakdown
- Epic >1M tokens → Split into multiple epics
- Unusual spikes → Investigate inefficiency
Token Savings Example
See reference/communication.md for more examples.
| Style | Tokens | Example |
|---|---|---|
| Verbose | 500 | "I have analyzed the requirements..." |
| Concise | 50 | "Epic: Backend ~85k, Frontend ~75k, Mobile ~65k, DevOps ~45k. Total ~270k (4 tasks)" |
Savings: 90% reduction
Success Metrics
- Average tokens per task <100k
- Zero agents exceeding 200k
- <10% of tasks require splitting
- Summary files used for context preservation
- Cost per epic <$10 (based on token pricing)
Source
git clone https://github.com/SkyfomLabs/skyfom-claude-orchestration/blob/main/skills/skyfom-tokens-efficiency/SKILL.mdView on GitHub Overview
Skyfom-tokens-efficiency provides token estimation before spawning agents, auto-splits large tasks when they exceed 100k tokens, and tracks consumption in real time. It enforces a 160k warning and 180k hard limit, then generates a summary file and respawns with a fresh agent to keep multi-agent orchestration cost-efficient.
How This Skill Works
Before execution, it estimates tokens using epic analysis and a simple formula. If a task exceeds 100k tokens, it auto-splits into subtasks under 100k and documents dependencies. During execution, agents report tokenUsage and tokenEstimate to a centralized state; at thresholds, it creates a summary file, saves it, and spawns a new agent referencing the summary to resume work.
When to Use It
- Before creating tasks, to analyze an epic and estimate total tokens.
- When an epic is likely to exceed 100k tokens and requires auto-splitting into smaller subtasks.
- During execution to monitor token usage in real-time across agents.
- At 160k tokens, to generate a summary file and spawn a fresh agent referencing the summary.
- When planning budgets across phases and coordinating multiple agents for complex workflows.
Quick Start
- Step 1: Analyze Epic and estimate tokens from the description to determine overall scope.
- Step 2: If estimated tokens > 100k, auto-split into logical subtasks < 100k and define dependencies.
- Step 3: Run agents and monitor tokenUsage; at 160k create a summary and spawn a new agent referencing the summary, then update state.
Best Practices
- Always estimate tokens before executing an epic or large task.
- Auto-split tasks when the estimate exceeds 100k tokens to keep subtasks under 100k each.
- Track tokenUsage and tokenEstimate in the centralized state (.claude/state/...).
- Respond to 160k by creating a summary file and spawning a new agent; only escalate at 180k hard limit.
- Document dependencies and spawn fresh agents that reference the summary to maintain continuity.
Example Use Cases
- An Epic with multiple components is analyzed, tokens allocated per component stay under 100k, and subtasks are created automatically.
- Agent-abc123 reports 85k tokens used with an estimated 100k, allowing progress without triggering thresholds.
- At 160k tokens, the system creates a summary file at .claude/state/agent-abc123-summary.md and spawns a new agent referencing the summary.
- Epic budgeting computes total_budget from task count × 75k and tracks remaining tokens in orchestration state.
- Status updates leverage JSON over verbose prose to reduce token expenditure while maintaining clarity.