Agents Builders

Capture action tokens and cost

Archived
capture-action-tokens-and-cost

Created

Jul 01, 14:49

Started

Jul 01, 14:51

DevOps handoff

Type

Feature

Shape

backend

Worktree Slug

capture-action-tokens-and-cost

Repositories

mcritchie-studio

Release Slug

Branch

feat/capture-action-tokens-and-cost

Pull Request

QA URL

Production URL

telemetry migration hook

Acceptance Criteria

  • Capture hook sends per-turn token usage from transcript
  • Turn usage attributed once, parallel siblings stay zero
  • Span and action rows show real tokens and cost

Expected Test Plan

  • [unit] hook parses message.usage + message.id into tokens_in/out + usage_ref
  • [unit] capture zeroes usage on a duplicate usage_ref (turn counted once)
  • [integration] POST atomic_actions persists tokens/cost; sibling action zeroed

Checks Run

No completed checks recorded.

Agent Context

The PostToolUse hook (bin/atomic-capture-hook) already reads message.model from the transcript tail but never message.usage, and the capture endpoint doesnt permit tokens/cost, so AtomicAction rows land with tokens_in/out=0, cost=0 -> heartbeat span roll-up shows blank tokens/cost while model populates. Fix: hook also reads message.usage (+ message.id as usage_ref) from the same assistant line and sends tokens_in/tokens_out; controller permits tokens_in/tokens_out/cost/usage_ref; AtomicAction.capture dedupes by usage_ref so one assistant turn (which can fan out parallel tool calls) is counted ONCE (first action of the turn keeps usage, siblings zeroed) -> no double counting. Cost derived server-side from model price table. No view change: _event_table already rolls up totals.

Stage Timeline

Who handled each stage, the time it took (measured), and the model / tokens / cost reported (best-effort) — plus who's on it right now. means the agent didn't report that metric.

Sizing Avi · PO MEDIUM Dev MEDIUM Actual
  1. Created Designed
    D Dragonair
    Dragonair
    Model
    Duration
    Tokens
    Cost
    Completed Jul 01, 14:49 · 7 days ago
    api
  2. Designed Building
    D Dragonair
    Dragonair
    Model
    claude-opus-4-8
    Duration
    1 minute
    Tokens
    1,294,407
    Cost
    ~$1.56
    Started Jul 01, 14:49
    Completed Jul 01, 14:51 · 7 days ago
    cli
  3. Building Designed
    D Dragonair
    Dragonair
    Model
    claude-opus-4-8
    Duration
    3 minutes
    Tokens
    1,644,816
    Cost
    ~$1.40
    Started Jul 01, 14:51
    Completed Jul 01, 14:54 · 7 days ago
    cli
  4. Designed Archived
    4
    482d770c-e05a-44db-914a-4545849edf20
    Model
    claude-opus-4-8
    Duration
    1 minute
    Tokens
    1,027,316
    Cost
    ~$0.87
    Started Jul 01, 14:54
    Completed Jul 01, 14:55 · 7 days ago
    cli

Conversation

QA review feedback, agent handoffs, and follow-up notes for this task.

No task feedback has been recorded yet.

Sealed-bid sizing

Edit →

Alex (PM)

Avi (PO)

MEDIUM

Dev

MEDIUM

Actual