Skip to content

API cost tracking: capture per-job spend from Claude Code output #14

@FrederikHandberg

Description

@FrederikHandberg

Problem

Zero instrumentation on Anthropic API spend. No cost per job in YAML, no daily total on dashboard, no threshold alert. A single autoresearch job could cost $5 or $50 — currently no way to know.

Fix

Claude Code prints a cost summary at the end of each session:

Total cost: $0.47
  1. In worker.py, after job completion, grep the tmux pane output for the cost pattern:
    import re
    cost_match = re.search(r'Total cost: \$([0-9.]+)', pane_output)
    if cost_match:
        yq -i f'.cost_usd = {cost_match.group(1)}' job_yaml
  2. Add cost_usd field to job YAML schema
  3. Aggregate daily/weekly totals in morning report
  4. Dashboard shows per-job cost and running total
  5. Alert (ntfy) if daily spend > threshold (configurable, start with $10)

Acceptance Criteria

  • cost_usd field in every completed job YAML
  • Morning report shows yesterday's total API spend
  • Dashboard job list shows cost per job
  • Alert fires if daily cost exceeds threshold
  • Threshold configurable via env var or config file

Context

From Jensen limitation audit (2026-03-22). Workstream: WS-001.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions