plugins/ruflo-cost-tracker/commands/ruflo-cost.md
Cost tracking commands:
cost report [--period today|week|month] -- Generate a cost report for the specified period.
cost-tracking namespace for the periodcost breakdown [--by agent|model|task] -- Detailed cost breakdown by dimension.
cost-tracking namespacecost budget set <amount> -- Set a budget limit in USD (real implementation, persisted to cost-tracking:budget-config).
node plugins/ruflo-cost-tracker/scripts/budget.mjs set <amount> to write the config to the cost-tracking namespacecost budget get -- Show the current budget config.
node plugins/ruflo-cost-tracker/scripts/budget.mjs getcost budget check [--period today|week|month|all] -- Compute utilization + alert level (50/75/90/100% ladder).
node plugins/ruflo-cost-tracker/scripts/budget.mjs checkBUDGET_PERIOD=today|week|month|all (default all)total_cost_usd across all session-* records in cost-trackingbudget check && spawn ... to fail closedcost optimize -- Analyze usage and suggest cost optimizations.
cost-tracking namespacecost track -- Auto-capture token usage for the active Claude Code session and persist to the cost-tracking namespace. Run after significant work or at session end so cost report has real data.
node plugins/ruflo-cost-tracker/scripts/track.mjs (no flags = current cwd's most-recent session)cost-tracking namespace record at key session-<sessionId> (consumed by cost-report step 1)cost outcome <task> <model> <outcome> -- Emit a hooks_model-outcome event so the router learns from applied recommendations. Auto-wired into cost-optimize step 8.
outcome ∈ {success, escalated, failure}node plugins/ruflo-cost-tracker/scripts/outcome.mjs "<task>" <model> <outcome>npx @claude-flow/cli hooks model-outcome -t ... -m ... -o ... with explicit-argv spawnSync so quoting is safecost summary [--format json|markdown] -- Single-shot programmatic dump of all cost data. Other plugins/scripts can shell out and parse the JSON.
node plugins/ruflo-cost-tracker/scripts/summary.mjs --format json--format markdown; JSON contract is stable for programmatic consumerscost federation -- Consumer-side wiring for ADR-097 Phase 3 federation_spend events. Aggregates per-peer 1h/24h/7d rolling windows and flags peers exceeding the suspension threshold (default $5/24h).
node plugins/ruflo-cost-tracker/scripts/federation.mjsFED_FORMAT=json, FED_NAMESPACE=federation-spend, FED_SUSPEND_THRESHOLD_USD=5.0{peerId, taskId, tokensUsed, usdSpent, ts} to the federation-spend namespacecost export [--prometheus <path>] [--webhook <url>] -- Export cost-tracking telemetry to external observability systems.
--prometheus <path> writes the node_exporter textfile-collector format (gauges + counters with session labels)--webhook <url> POSTs JSON; auth via EXPORT_WEBHOOK_HEADER='K: V'cost_tracker_total_usd, cost_tracker_tier_total_usd{tier=...}, cost_tracker_session_total_usd{session=...}, cost_tracker_session_messages{session=...}, cost_tracker_budget_usd, cost_tracker_budget_utilizationcost conversation -- Per-conversation cost view: list every session in cost-tracking with started-at, message count, top model, total cost. Different lens from cost report (which is per-agent/per-model).
node plugins/ruflo-cost-tracker/scripts/conversation.mjsCONV_FORMAT=json, CONV_LIMIT=N, CONV_NAMESPACE=...cost trend -- Read all docs/benchmarks/runs/*.json and surface drift in the gate metrics — win rate, avg latency, p99, escalation rate, speedup vs LLM. Flags regressions the binary smoke gate misses.
node plugins/ruflo-cost-tracker/scripts/trend.mjsTREND_FORMAT=json for machine-readable output, TREND_LIMIT=N to truncatecost projection [--window 7d] [--horizons 7d,30d,90d,365d] [--format table|json] -- Forward-looking spend extrapolation. Predictive counterpart to cost budget check (reactive).
node plugins/ruflo-cost-tracker/scripts/projection.mjs--horizons)cost budget set has run: surface "days until 75%/90%/100% consumed" tablesjq '.budget.exhaustion[2].daysUntilReached < 7' to fail builds when 100% exhaustion is < 1 week away)PROJECTION_NAMESPACE, PROJECTION_QUIET=1cost counterfactual [--since 7d] [--baseline always-haiku|always-sonnet|always-opus|all] [--format table|json] -- Multi-baseline counterfactual cost analysis. Comparative counterpart to budget-check (reactive) and projection (predictive): answers "is the routing earning its keep?".
node plugins/ruflo-cost-tracker/scripts/counterfactual.mjs--baseline all)always-haiku savings = over-escalation signal (router picked sonnet/opus when haiku could have done it). Positive always-sonnet quantifies the router's win against the "safe default" baseline.jq '.baselines[1].savingsPct > 30' to flag workload shifts where routing isn't saving ≥30% vs sonnetcost burn [--bucket 1d] [--lookback 14d] [--alert-on-acceleration-pct N] [--format table|json] -- Burn-rate trend over time with optional drift-alert exit code. Trend counterpart to reactive/predictive/comparative: answers "is daily burn accelerating?".
node plugins/ruflo-cost-tracker/scripts/burn.mjs--bucket duration windows (default 1d) over --lookback (default 14d)--alert-on-acceleration-pct N: exit 1 when latest exceeds prior mean by N%+. Independent of budget — catches "hot loop burning 10× normal" before budget alarm firescost trend (which surfaces BENCHMARK drift across docs/benchmarks/runs/*.json); this tracks PRODUCTION spend.--bucket > --lookback → exit 2 (config error).cost anomaly [--since 7d] [--threshold 3.5] [--alert-on-outliers N] [--format table|json] -- MAD-based outlier detection on session spend. Point-anomaly counterpart to cost-burn's aggregate-trend signal: answers "which specific session is the outlier?".
node plugins/ruflo-cost-tracker/scripts/anomaly.mjsmedian(total_cost_usd) and MAD = median(|x - median|) over the filtered windowz = 0.6745 × (x - median) / MAD (Iglewicz-Hoaglin 1993)|z| > --threshold (default 3.5)--alert-on-outliers N: exit 1 when ≥N outliers foundhigh (over-spending) vs low (crash/drop) direction.cost session [--session-id <id>] [--top 20] [--since <iso-ts>] [--format table|json] -- Per-message cost breakdown within ONE session. Drill-down companion to cost-anomaly.
node plugins/ruflo-cost-tracker/scripts/session.mjs--session-id (scans ~/.claude/projects/*/) or --latest (default)cost diff --baseline <path> --current <path> [--alert-on-pct N] [--alert-on-usd N] [--alert-on-class-pct <class>:N[,<class>:N]] [--format table|json] -- Snapshot delta between two cost-summary JSON outputs. PR-level regression detection.
node plugins/ruflo-cost-tracker/scripts/diff.mjs --baseline <path> --current <path>|delta| descending so biggest movers bubble to the top--alert-on-pct N exits 1 when total grew >N%; --alert-on-usd N exits 1 when total grew >$N; both can be set, first to trigger winscost summary --format json — the stable JSON contract is the protocol between snapshot capture and snapshot diffingcost health [--alert-acceleration 100] [--alert-outliers 1] [--alert-days-to-exhaust 14] [--skip burn,anomaly] [--format table|json] -- Composite CI gate. Runs all four alert ladders (budget / burn / anomaly / projection) in parallel and returns max(exit_codes). One shell-out replaces four separate CI steps.
node plugins/ruflo-cost-tracker/scripts/health.mjsPromise.all--format json; parse exit codesdaysUntilReached[100%] < --alert-days-to-exhaustmax(subcheck exits) — any failure fails the gate--skip <list> to disable specific subchecks (e.g. --skip burn for fast-feedback smoke runs).cost benchmark [--llm] [--anthropic] -- Run the corpus benchmark to verify booster claims with measured numbers.
--llm: also run Gemini 2.0 Flash baseline (uses GCP GOOGLE_AI_API_KEY secret)--anthropic: also run Claude Sonnet 4.6 + Opus 4.7 (uses GCP ANTHROPIC_API_KEY secret)docs/benchmarks/runs/latest.json and timestamped siblingwinRate < 0.80. See cost-benchmark skill for env-var overrides.cost workers -- Inspect the optimize and benchmark background workers consumed from ruflo-loop-workers.
mcp__claude-flow__hooks_worker-status --worker optimize -- report last-run timestamp, outcome, and any pending recommendationsmcp__claude-flow__hooks_worker-status --worker benchmark -- report last-run timestamp, outcome, and any pending benchmark deltascost history -- Show cost tracking history over time.
cost-tracking namespace