-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Parent Epic
Summary
Add per-agent cost tracking by parsing Claude Code's --output-format stream-json output and enforcing configurable budget limits.
Changes Required
terraphim_spawner
- Add
--output-format stream-jsonto Claude CLI args inconfig.rs:infer_args() - Create
cost.rsmodule withCostEventstruct and stream JSON parser - Parse stdout for Claude stream JSON events:
session_id,usage.input_tokens,usage.output_tokens,cost_usd - Emit
CostEventvia broadcast channel alongsideOutputEvent
terraphim_orchestrator
- Add
budget_monthly_cents: Option<u64>field toAgentDefinition(with#[serde(default)]) - Add
CostTrackerstruct: accumulates per-agent spend, writes tocosts.jsonl - Budget enforcement in
reconcile_tick(): warn at 80%, pause agent at 100% - New
AgentStatusfield:spent_monthly_cents
Config
[[agents]]
name = "product-development"
budget_monthly_cents = 5000 # $50/month limitReference
- Paperclip cost service:
server/src/services/costs.ts - Paperclip Claude parser:
packages/adapters/claude-local/src/server/parse.ts - Claude stream JSON schema:
{type: "result", usage: {input_tokens, output_tokens}, cost_usd}
Acceptance Criteria
- Claude agents emit cost events from stream JSON output
- Per-agent costs accumulated and written to
costs.jsonl - Budget enforcement pauses agent when limit reached
- Codex agents gracefully skip cost tracking (no stream JSON available)
- Existing agents work without
budget_monthly_cents(default: no limit) - Unit tests for stream JSON parser and budget enforcement
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request