skills/aeo-cost-governor/SKILL.md
Track token usage and enforce budget limits. Optional skill for cost-conscious projects.
npx skillsauth add ivzc07/aeo-skills aeo-cost-governorInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Purpose: Track token usage and enforce budget limits. Optional skill for cost-conscious projects.
Create budget config at $PAI_DIR/USER/aeo-budget.json:
{
"daily_budget_usd": 10.00,
"per_task_budget_usd": 2.00,
"alert_threshold_percent": 80,
"hard_limit_percent": 100,
"enable_tracking": true
}
Defaults (if no config):
Claude Models (Jan 2025):
Cost Calculation Formula:
cost_usd = (input_tokens / 1_000_000 * input_price) + (output_tokens / 1_000_000 * output_price)
Track costs during:
When a task starts:
# Initialize task cost tracking
echo '{
"task_id": "unique-id",
"task_description": "Add user authentication",
"start_time": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
"model": "claude-sonnet-4.5",
"budget_usd": 2.00,
"usage": {
"input_tokens": 0,
"output_tokens": 0,
"cost_usd": 0.00
}
}' > ~/.claude/MEMORY/aeo-task-cost.json
After each tool use:
# Update task cost
# (Read existing, add new usage, write back)
jq '.usage.cost_usd += 0.15' ~/.claude/MEMORY/aeo-task-cost.json > /tmp/cost.json
mv /tmp/cost.json ~/.claude/MEMORY/aeo-task-cost.json
Append to daily log:
echo '{
"timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
"date": "$(date -u +%Y-%m-%d)",
"task_id": "unique-id",
"model": "claude-sonnet-4.5",
"input_tokens": 1250,
"output_tokens": 850,
"cost_usd": 0.15
}' >> ~/.claude/MEMORY/aeo-costs.jsonl
# Get today's total cost
today_total=$(jq -s "map(select(.date == \"$(date -u +%Y-%m-%d)\")) | map(.cost_usd) | add" \
~/.claude/MEMORY/aeo-costs.jsonl)
# Get budget
budget=$(jq '.daily_budget_usd' ~/.claude/USER/aeo-budget.json)
# Calculate percentage
percent=$(echo "$today_total / $budget * 100" | bc)
# Check if over limit
if (( $(echo "$percent >= 100" | bc -l) )); then
echo "❌ BUDGET EXCEEDED - $today_total spent of $budget"
exit 1
fi
After each operation:
# Read task cost
task_cost=$(jq '.usage.cost_usd' ~/.claude/MEMORY/aeo-task-cost.json)
task_budget=$(jq '.per_task_budget_usd' ~/.claude/USER/aeo-budget.json)
# Check if over task budget
if (( $(echo "$task_cost > $task_budget" | bc -l) )); then
echo "⚠️ TASK BUDGET EXCEEDED - $task_cost spent of $task_budget"
# Invoke aeo-escalation
fi
⚠️ COST ALERT - 80% BUDGET CONSUMED
Daily Budget: $10.00
Used: $8.47 (84.7%)
Remaining: $1.53
Tasks completed today: 7
Average cost per task: $1.21
Options:
1. Continue anyway - Proceed with current task
2. Pause and review - Assess completed work
3. Switch to cheaper model - Use Haiku instead of Sonnet
Recommended: Option 3 - Switch to Haiku for routine tasks
Your choice (1-3):
❌ BUDGET EXCEEDED - HARD LIMIT REACHED
Daily Budget: $10.00
Used: $10.23 (102.3%)
Overage: $0.23
Action Required:
• All tasks blocked until budget resets
• Budget resets at midnight UTC
• Consider increasing daily_budget_usd in config
Current time: $(date -u +%H:%M UTC)
Time until reset: [hours remaining]
Options:
1. Wait for reset - Resume at midnight UTC
2. Increase budget - Modify aeo-budget.json
3. Override limit - Not recommended
Contact: [Admin email if configured]
Use Opus for:
Use Sonnet for:
Use Haiku for:
Generate at end of day:
# Get today's costs
jq -s "
select(.date == \"$(date -u +%Y-%m-%d)\")
| {
total_cost: map(.cost_usd) | add,
task_count: length,
avg_cost: (map(.cost_usd) | add / length),
by_model: group_by(.model) | map({
model: .[0].model,
cost: map(.cost_usd) | add,
tasks: length
})
}
" ~/.claude/MEMORY/aeo-costs.jsonl
Output:
{
"total_cost": 8.47,
"task_count": 7,
"avg_cost": 1.21,
"by_model": [
{"model": "claude-sonnet-4.5", "cost": 6.32, "tasks": 5},
{"model": "claude-haiku-4", "cost": 2.15, "tasks": 2}
]
}
# Last 7 days
jq -s "
group_by(.date)
| map({
date: .[0].date,
total_cost: map(.cost_usd) | add,
task_count: length
})
| .[-7:]
" ~/.claude/MEMORY/aeo-costs.jsonl
Hooks Integration:
// In PreToolUse hook
if (cost_governor_enabled) {
const cost = estimate_tool_cost(tool_name, tool_input);
const daily_total = get_daily_total();
const remaining = budget - daily_total;
if (cost > remaining) {
invoke_skill('aeo-escalation', {
type: 'cost_limit',
cost: cost,
remaining: remaining
});
}
}
DO:
DON'T:
User: /aeo
User: Refactor the authentication system
AEO-Core: [Calculating confidence...]
[Invokes aeo-cost-governor]
Cost Governor: Checking budget...
Daily Budget: $10.00
Used: $8.47 (84.7%)
Remaining: $1.53
Task Estimate: ~$2.50
⚠️ ALERT: Task may exceed daily budget
Options:
1. Continue anyway - May exceed budget
2. Use Haiku instead - Estimated cost ~$0.50
3. Break into smaller tasks - Spread across multiple days
Recommended: Option 3 - Break into smaller tasks
User: 3
Cost Governor: [Recording decision]
Suggesting subtasks:
1. Extract auth logic to service (Day 1)
2. Implement JWT tokens (Day 2)
3. Migrate existing sessions (Day 3)
AEO-Core: Proceeding with subtask 1: Extract auth logic
Archive old cost logs:
# Keep last 90 days, archive older
cat ~/.claude/MEMORY/aeo-costs.jsonl | \
jq -r 'select(.date >= "$(date -u -d '90 days ago' +%Y-%m-%d)")' \
> /tmp/costs-recent.jsonl
cat ~/.claude/MEMORY/aeo-costs.jsonl | \
jq -r 'select(.date < "$(date -u -d '90 days ago' +%Y-%m-%d)")' \
> ~/.claude/MEMORY/aeo-costs.archive.jsonl
mv /tmp/costs-recent.jsonl ~/.claude/MEMORY/aeo-costs.jsonl
To disable cost tracking for a project:
{
"enable_tracking": false
}
Or delete the config file entirely - AEO will use defaults but won't enforce limits.
testing
Validate that tasks are sufficiently defined before execution. Returns score 0-100.
development
Internal code reviewer with veto power. Reviews changes before commit, blocks security issues.
testing
--- name: aeo-failure-patterns description: Recognize common errors and apply known fixes automatically. Hybrid: core patterns + project-specific learning. --- # AEO Failure Patterns **Purpose:** Recognize common errors and apply known fixes automatically. Uses hybrid architecture: core curated patterns + project-specific learned patterns. ## Architecture **Core Patterns (in this SKILL.md):** - 20-30 curated patterns with high-confidence fixes - Portable across projects - Confidence ≥ 0.85 →
testing
Human-AI interface for when to interrupt and involve humans. Presents clear options and records decisions.