Get the FREE Ultimate OpenClaw Setup Guide →

skyfom-tokens-efficiency

npx machina-cli add skill SkyfomLabs/skyfom-claude-orchestration/skyfom-tokens-efficiency --openclaw
Files (1)
SKILL.md
5.4 KB

Skyfom Tokens Efficiency

Token optimization and management for multi-agent orchestration.

Core Principles

  1. Estimate Before Execute - Calculate token cost before spawning agents
  2. Split Large Tasks - Auto-split tasks estimated >100k tokens
  3. Track Consumption - Monitor token usage in real-time
  4. Warn at Threshold - Alert at 160k tokens, act at 180k
  5. Summarize & Resume - Create summary, spawn fresh agent

Token Limits

MetricValueAction
Ideal per agent100,000Target for task planning
Warning threshold160,000Create summary file
Hard limit200,000Must spawn new agent
Epic maximum1,000,000Split into multiple phases

Token Estimation

See workflows/estimation.md for detailed formulas and examples.

Formula

tokens ≈ characters × 0.25

Task Complexity

SizeTokensExamples
Trivial<5kConfig changes, typos, simple fixes
Small5k-25kSingle component, basic feature
Medium25k-75kMulti-component feature, API endpoint
Large75k-150kComplex feature, multiple files
Epic>150kRequires splitting into subtasks

PM/CTO Workflow

See workflows/task-splitting.md for detailed process.

Before Creating Tasks

  1. Analyze Epic - Calculate estimated tokens from description
  2. Estimate Complexity - Count requirements × avg tokens per requirement
  3. Auto-Split if >100k - Break into logical subtasks <100k each
  4. 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

  1. Create summary file (completed/remaining work, context)
  2. Save to .claude/state/agent-$id-summary.md
  3. Spawn new agent referencing summary with @file
  4. Update state (mark old completed, link new)

Communication Efficiency

See reference/communication.md for best practices.

FormatUse ForToken Savings
JSONStructured data60% vs prose
Emoji statusQuick updates90% vs full sentences
TablesComparisons70% vs paragraphs
ReferencesContext95% 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

ModelUse ForCost
HaikuRoutine ops, status checks, simple fixes~1/20th Sonnet
SonnetArchitecture, complex implementation, code reviewStandard

Best Practices

  1. Avoid Repeated Context - Use @file references and summary files
  2. Batch Operations - Review multiple files in one session
  3. Link to Beads - Reference task IDs instead of repeating details
  4. 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.

StyleTokensExample
Verbose500"I have analyzed the requirements..."
Concise50"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

  1. Step 1: Analyze Epic and estimate tokens from the description to determine overall scope.
  2. Step 2: If estimated tokens > 100k, auto-split into logical subtasks < 100k and define dependencies.
  3. 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.

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers