---
name: "agent-token-budget-limiter"
description: "Enforce strict token consumption and spending limits on autonomous agent execution."
metadata:
  author: "OpenAI"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "limit agent token budget"
  - "prevent runaway agent cost"
  - "track cumulative llm spend"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# Agent Token Budget & Cost Guardrails

Monitors cumulative input, output, and cache read tokens across multi-turn agent runs, enforcing hard caps, emitting warning thresholds, and gracefully aborting runaway loops.

## When to Invoke
Invoke this skill whenever you need to:
- limit agent token budget
- prevent runaway agent cost
- track cumulative llm spend

## Execution SOP & Rules
1. Track token usage metadata returned in API response headers or response.usage objects.
2. Maintain a running accumulator of prompt_tokens and completion_tokens.
3. Trigger emergency task finalization when cumulative tokens exceed the specified budget cap.
4. Log cost per turn using model pricing tables to provide real-time budget telemetry.

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
