AgentReceipt

Docs

Every way in sends the same thing: per-step token counts that AgentReceipt prices and explains. Get your ingest key on Connect.

Claude Code hook

The hook is a single Node file (no dependencies, Node 18+). It reads the session transcript on your machine, keeps only the numbers and posts them when the session ends.

shell
mkdir -p ~/.agentreceipt && curl -fsSL https://agentreceipt.vibiz.app/hook.mjs -o ~/.agentreceipt/hook.mjs \
  && node ~/.agentreceipt/hook.mjs --install ar_live_YOUR_KEY

--install saves the key to ~/.agentreceipt/key and adds a SessionEnd hook to ~/.claude/settings.json. We use SessionEnd rather than Stop because Stop fires after every reply, while a receipt is for a finished session.

Flags you can add to the hook command:

  • --status merged|open|abandoned: the task outcome (abandoned counts as wasted spend).
  • --pr 482, --ticket ABC-123, --label "…": override what was detected from the branch and prompts.
  • --client acme or AGENTRECEIPT_CLIENT=acme: a client tag for agencies (Pro).
  • --markdown: print the PR-comment markdown to stdout.

The hook never blocks or fails Claude Code: problems are printed to stderr and it exits 0.

GitHub Action

anthropics/claude-code-action writes an execution file with every model call. Add this step after it; the receipt is posted as a PR comment. Store your key as the repository secret AGENTRECEIPT_KEY.

yaml
permissions:
  contents: write
  pull-requests: write
steps:
  - uses: anthropics/claude-code-action@v1
    id: claude
    with:
      anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
  - name: AgentReceipt
    if: always()
    env:
      AGENTRECEIPT_KEY: ${{ secrets.AGENTRECEIPT_KEY }}
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    run: |
      curl -fsSL https://agentreceipt.vibiz.app/hook.mjs -o /tmp/agentreceipt.mjs
      node /tmp/agentreceipt.mjs --file "${{ steps.claude.outputs.execution_file }}" \
        --source action --repo "${{ github.event.repository.name }}" \
        --pr "${{ github.event.pull_request.number || github.event.issue.number }}" --comment

Codex CLI

Codex writes rollouts to ~/.codex/sessions/YYYY/MM/DD/rollout-*.jsonl with a token count per turn. Run the hook after a task; it picks the newest rollout.

shell
codex exec "add dark mode (WEB-77)" && node ~/.agentreceipt/hook.mjs --latest-codex --status merged

Ingest API

POST https://agentreceipt.vibiz.app/api/ingest with Authorization: Bearer ar_live_…. Prices are always recomputed on the server from the token counts.

request
{
  "agent": "claude_code",            // claude_code | codex | other
  "source": "api",                   // hook | action | api
  "repo": "payments-api", "branch": "fix/PAY-482", "prNumber": 482, "ticketRef": "PAY-482",
  "taskLabel": "PR #482", "taskStatus": "merged",   // merged | open | abandoned | unknown
  "clientTag": "acme",
  "steps": [
    { "ts": 1762700000000, "model": "claude-opus-4-8", "tools": ["Edit"], "target": "f1a2b3c",
      "input": 12, "output": 850, "cacheWrite": 2200, "cacheWrite1h": 0, "cacheRead": 41000,
      "resultChars": 3400, "error": false, "test": false, "compaction": false }
  ]
}
201 response
{
  "id": "k3Fq9TzP2a", "url": "https://agentreceipt.vibiz.app/r/k3Fq9TzP2a",
  "summary": "PR #482: $3.41, 62% cache hit, 2 retry loops",
  "totalCost": 3.4102, "wasteUsd": 1.21, "cacheHitRate": 0.62,
  "flags": [{ "kind": "cache_miss_idle", "title": "Cache expired after a 11 min idle gap", "savingsUsd": 0.48 }],
  "alertsFired": [], "markdown": "### 🧾 Agent receipt: $3.41 …"
}

Errors always come back as { "error": { "code", "message", "fix", "field" } }: 401 invalid_key (rotated or wrong key), 400 invalid_request (the field and how to fix it), 402 plan_limit (a second repo on Free), 429 rate_limited.

Log formats

  • Claude Code JSONL: one line per content block; lines sharing a message id are merged so each model call is counted once. 5-minute and 1-hour cache writes are priced separately.
  • claude-code-action execution file: a JSON array of SDK messages (no timestamps, so idle-gap checks are skipped).
  • Codex rollout: each token_count event is one step; cached input is priced at the cached rate and reasoning tokens as output.

Formats change without notice. If a new version stops parsing, the analyzer says which part it could not read; email the error (not the file) to hello@agentreceipt.vibiz.app.

What is sent

Per model call: timestamp, model id, input/output/cache token counts, tool names, the character count of tool output, whether a tool failed, and an 8-character hash of the edited file name. Repo name, branch, PR number and ticket id as labels. Never prompts, responses, code, file contents or file names.