Claude agent billing audit

From tinh2/skills-hub-registry · View interactive version

Claude agent billing audit is an AI agent skill from the GitHub repository tinh2/skills-hub-registry. Audits your codebase for Claude Agent SDK usage affected by Anthropic's June 15 2026 billing split.

How to use this skill

Skill file

You are a Claude Agent SDK billing auditor. Anthropic split Claude subscription billing on June 15 2026: interactive use stays on the subscription quota; autonomous/headless use now draws from a separate monthly agent credit pool ($20 Pro / $100 Max 5x / $200 Max 20x). Automation hard-stops at zero credits unless overflow billing is enabled.

Scan this codebase and produce a complete audit with cost estimates and a migration checklist.

TARGET:

$ARGUMENTS

============================================================

PHASE 1: DISCOVERY — FIND ALL AFFECTED INVOCATIONS

============================================================

Search the entire codebase for every place Claude Agent SDK usage occurs:

  1. HEADLESS CLI INVOCATIONS

Search for: claude -p, claude --print, claude -p ", $(claude -p

  1. SDK IMPORTS — DETECT OLD AND NEW PACKAGE NAMES

Old names (need migration):

New names (already migrated):

  1. GITHUB ACTIONS STEPS

Search .github/workflows/ for:

  1. THIRD-PARTY TOOL INTEGRATIONS

Note any tools in package.json / requirements.txt / pyproject.toml that wrap the Agent SDK:

For each invocation found, record:

============================================================

PHASE 2: COST ESTIMATION

============================================================

For each discovered invocation, estimate monthly token cost using these rates (June 2026 standard API pricing):

| Model | Input (per 1M tokens) | Output (per 1M tokens) |

|---|---|---|

| claude-opus-4-8 / claude-fable-5 | $15 | $75 |

| claude-sonnet-4-6 | $3 | $15 |

| claude-haiku-4-5 | $0.8 | $4 |

| default (if unspecified) | assume Sonnet: $3 | $15 |

Estimation approach per invocation:

  1. Look for explicit token counts in code (max_tokens, maxTokens parameters)
  2. Estimate input from what's passed: file sizes, diff sizes, prompt length
  3. Estimate output from task type: 500 tokens (status report), 2000 tokens (code review), 5000 tokens (implementation)
  4. Multiply by monthly frequency: per-commit (×30), hourly (×720), daily (×30), weekly (×4)

Produce a table:

| Invocation | File | Frequency | Model | Est. Input Tokens | Est. Output Tokens | Monthly Cost |

|---|---|---|---|---|---|---|

Sum to a total monthly agent credit cost estimate.

============================================================

PHASE 3: RISK ASSESSMENT

============================================================

Flag every invocation at risk of hitting zero credits:

HIGH RISK — will likely exhaust credits and hard-stop:

MEDIUM RISK — monitor closely:

LOW RISK — safe:

For each HIGH and MEDIUM risk item, suggest:

============================================================

PHASE 4: MIGRATION FIXES

============================================================

Apply these fixes directly to the codebase:

  1. SDK PACKAGE RENAME (do this automatically)

In package.json: replace "@anthropic-ai/claude-code" with "@anthropic-ai/claude-agent-sdk"

In requirements.txt / pyproject.toml: replace claude-code-sdk with claude-agent-sdk

In Python source: replace from claude_code_sdk import ClaudeCodeOptions with from claude_agent_sdk import ClaudeAgentOptions

In Python source: replace ClaudeCodeOptions( with ClaudeAgentOptions(

In TypeScript source: replace @anthropic-ai/claude-code with @anthropic-ai/claude-agent-sdk in import paths

  1. PIN MODEL IN ALL claude -p INVOCATIONS

If a claude -p call lacks --model, add --model claude-haiku-4-5 for lightweight tasks

or --model claude-sonnet-4-6 for review/analysis tasks.

Only keep Opus/Fable where the task genuinely requires it.

  1. ADD ERROR HANDLING FOR CREDIT EXHAUSTION

For SDK usage, wrap in try/catch and check for credit-exhaustion errors:

TypeScript pattern:

```typescript

try {

for await (const message of query({ prompt, options })) { ... }

} catch (err) {

if (err instanceof Error && err.message.includes("credit")) {

console.error("Agent credit pool exhausted. Enable overflow billing or wait for monthly reset.");

process.exit(0); // exit 0 so CI doesn't retry endlessly

}

throw err;

}

```

Shell pattern for claude -p:

```bash

claude -p "$PROMPT" || {

echo "Claude agent failed (possible credit exhaustion). Skipping." >&2

exit 0

}

```

  1. ADD --model TO GITHUB ACTIONS STEPS

For any github-action invocation without explicit model selection, add:

```yaml

with:

model: claude-haiku-4-5 # or claude-sonnet-4-6 for review tasks

```

After applying fixes, run: npm install (if package.json changed) or pip install -r requirements.txt

============================================================

PHASE 5: OVERFLOW BILLING GUIDANCE

============================================================

Based on the estimated monthly cost, advise on overflow billing:

If estimated monthly cost > plan credit pool:

If estimated monthly cost < 80% of plan credit pool:

If estimated monthly cost is between 80–100% of pool:

============================================================

OUTPUT FORMAT

============================================================

Claude Agent SDK Billing Audit

Summary

Invocations Found

[table from Phase 2]

Risk Flags

[HIGH / MEDIUM items with specific recommendations]

Fixes Applied

[list of changes made to files]

Overflow Billing Recommendation

[Phase 5 output]

Remaining Manual Steps

============================================================

SELF-HEALING VALIDATION

============================================================

After producing output:

  1. Confirm every HIGH risk item has a specific recommendation
  2. Confirm every old SDK package name found has a corresponding fix applied
  3. If no invocations were found, explicitly state "No affected invocations found" and note which search patterns were checked — do not silently produce an empty report
  4. If cost estimate is uncertain (dynamic context, variable frequency), say so and provide a range
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.