Skip to main content

Real-time cost tracking and budget enforcement for the Claude Agent SDK

Project description

Argos Budget Guardian

Real-time cost tracking and budget enforcement for the Claude Agent SDK

Named after Argos Panoptes — the all-seeing giant of Greek mythology with 100 eyes who never slept — because this tool watches every token, every tool call, every dollar.

The Problem

AI agents built with the Claude Agent SDK can spiral in cost — retrying, looping, spawning subagents — with no way to set limits or see spending in real time. Cost unpredictability is the #1 developer complaint in the AI agent ecosystem. There's no open-source tool that prevents overspend in real time for Claude Agent SDK.

Argos Budget Guardian fills this gap.

Features

  • Real-time cost tracking per query, session, and daily
  • Budget enforcement that actually stops agents before you overspend
  • Live terminal dashboard showing costs as they happen
  • Natural language budgets ("spend no more than $5 today")
  • Drop-in wrapper — 2 lines to add to existing code
  • Works with your hooks — merges with existing SDK hooks
  • CLI tools for monitoring, history, and configuration
  • Accessible for both developers and non-technical team leads

Quick Start

pip install argos-budget-guardian
from argos_budget_guardian import guarded_query

async for msg in guarded_query("Refactor the auth module", budget=5.0):
    print(msg)
# Prints cost summary automatically at the end

Usage

With GuardedAgent (recommended)

from argos_budget_guardian import GuardedAgent

async with GuardedAgent(budget=10.0, dashboard=True) as agent:
    async for msg in agent.query("Analyze and fix all bugs in src/"):
        pass  # Dashboard shows live costs

    print(f"Total: ${agent.total_cost:.4f}")
    print(f"Remaining: ${agent.budget_remaining:.4f}")
    print(agent.cost_report())

Natural language budget

from argos_budget_guardian import GuardedAgent

async with GuardedAgent(budget="spend no more than $5 today") as agent:
    async for msg in agent.query("..."):
        pass

Custom policy

from argos_budget_guardian import GuardedAgent, BudgetPolicy

policy = BudgetPolicy(
    max_cost_usd=20.0,
    warn_at_percent=70,
    action_on_limit="pause",
    cooldown_seconds=5,
    scope="daily",
)

async with GuardedAgent(budget=policy) as agent:
    async for msg in agent.query("..."):
        pass

With existing SDK options

from claude_agent_sdk import ClaudeAgentOptions, HookMatcher
from argos_budget_guardian import GuardedAgent

options = ClaudeAgentOptions(
    model="sonnet",
    permission_mode="acceptEdits",
    allowed_tools=["Read", "Write", "Bash"],
    hooks={
        "PreToolUse": [HookMatcher(matcher="Bash", hooks=[my_custom_hook])]
    }
)

# Guardian merges its hooks with yours — yours still run
async with GuardedAgent(budget=5.0, options=options) as agent:
    async for msg in agent.query("..."):
        pass

Callbacks for alerts

from argos_budget_guardian import GuardedAgent

def on_warn(current: float, limit: float):
    slack.post(f"Agent at {current/limit*100:.0f}% of budget")

def on_limit(current: float, limit: float):
    slack.post(f"Agent budget exhausted: ${current:.2f}")

async with GuardedAgent(
    budget=50.0,
    on_warning=on_warn,
    on_limit=on_limit,
) as agent:
    async for msg in agent.query("..."):
        pass

CLI

argos setup       # Interactive configuration wizard
argos status      # Current running session costs
argos history     # Past session cost history
argos dashboard   # Launch live terminal dashboard
argos config      # View or edit configuration
argos export      # Export cost history to CSV/JSON

Dashboard

+-----------------------------------------------------------+
|  Argos Budget Guardian                    SESSION ACTIVE   |
+-----------------------------------------------------------+
|  Current Cost:  $0.4230                                    |
|  Budget: ################..........  42% of $1.00          |
|                                                            |
|  Cost by Model          |  Recent Tool Calls               |
|  sonnet-4.6  $0.38 90%  |  14:32 Write   $0.045           |
|  haiku-4.5   $0.04 10%  |  14:31 Bash    $0.012           |
|                          |  14:31 Read    $0.003           |
|                                                            |
|  Tokens: 12,450 in / 3,200 out / 8,100 cached             |
+-----------------------------------------------------------+

API Reference

GuardedAgent

Parameter Type Default Description
budget float | str | BudgetPolicy 10.0 Budget limit — dollar amount, natural language, or policy object
options ClaudeAgentOptions | None None Existing SDK options (hooks will be merged)
on_warning Callable | None None Called when approaching budget threshold
on_limit Callable | None None Called when budget is exceeded
dashboard bool False Show live terminal dashboard

BudgetPolicy

Field Type Default Description
max_cost_usd float required Hard spending ceiling
warn_at_percent float 80.0 Warning threshold as % of max
action_on_limit "warn" | "pause" | "stop" "stop" What happens at the limit
scope "session" | "daily" | "global" "session" Budget time scope
cooldown_seconds float 0 Pause duration (for "pause" action)

guarded_query()

Drop-in replacement for claude_agent_sdk.query() with budget enforcement.

async for msg in guarded_query(prompt, budget=5.0, options=None):
    ...

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

argos_budget_guardian-0.1.0.tar.gz (26.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

argos_budget_guardian-0.1.0-py3-none-any.whl (24.9 kB view details)

Uploaded Python 3

File details

Details for the file argos_budget_guardian-0.1.0.tar.gz.

File metadata

  • Download URL: argos_budget_guardian-0.1.0.tar.gz
  • Upload date:
  • Size: 26.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for argos_budget_guardian-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7c79851409f449e0f9ef95a53de81b3347f904ef95a2e5403f632b5376d57c25
MD5 26623a33bd246e40e60f25cc9d0b42e5
BLAKE2b-256 83042889de45bc6bc2bd198261cad6e1b2e755bfa4f806d3fb8be6c966027123

See more details on using hashes here.

File details

Details for the file argos_budget_guardian-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for argos_budget_guardian-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 90e7a2d74671d021c147cc0a80532a8775ff53212cf3963614a0e0be85eaac7d
MD5 370a8345656674eb0ad8ee24228c8f4f
BLAKE2b-256 fcf0753f6e83955512fe4c309688a18f26d76dc7370b513403b03dbd6628d309

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page