AgentCostGuard is a deterministic 9.9µs circuit breaker, Claude Code PreToolUse/PostToolUse hook guard (with live --max-usd transcript budget enforcement), retrospective session auditor, native MCP server, and STDIO proxy:
hard USD/token caps, canonical SHA-256 retry & ping-pong oscillation detection, prompt-injection scanning,
and zero-CDN HTML audit reports.
Stops a 40-step claude-3.7-sonnet identical retry loop at step 4 ($3.924 → $0.0945).
Catches alternating A ↔ B ↔ A ↔ B tool oscillations on gpt-4o ($1.535 → $0.115).
Pure Python standard library. Zero external pip packages, zero telemetry, 100% local.
examples/benchmark_loop.py)| Scenario | Model | Unprotected | Guarded | Blocked At | Saved |
|---|---|---|---|---|---|
| Identical retry loop (40 steps) | claude-3.7-sonnet |
$3.9240 (1,240,800 tok) | $0.0945 (26,460 tok) | Step 4 (LoopDetectedError) |
97.59% |
| Ping-pong oscillation (30 steps) | gpt-4o |
$1.5353 (579,900 tok) | $0.1153 (40,400 tok) | Step 6 (LoopDetectedError) |
92.49% |
pip install agent-cost-guard
agent-cost-guard doctor
agent-cost-guard estimate gpt-5 --input-tokens 50000 --output-tokens 5000
agent-cost-guard demo --log demo_trace.jsonl --html demo_report.html
# Or zero-install native MCP server with uvx:
uvx agent-cost-guard mcp-server
# Wrap any Claude Desktop / Cursor / Windsurf stdio MCP server in 1 line:
agent-cost-guard mcp-proxy --repeat-limit 3 --blocked-tools drop_table --log mcp.jsonl -- npx -y @modelcontextprotocol/server-filesystem .
# Run AgentCostGuard's native MCP stdio server (cost estimator, prompt-injection scan, config audit, trace summary):
agent-cost-guard mcp-server
# Auto-discover & audit existing Claude / Cursor / Windsurf / VS Code configs:
agent-cost-guard audit
agent-cost-guard wrap-config --discover --repeat-limit 3 --log-dir ./mcp_traces
# Install Claude Code PreToolUse/PostToolUse hooks with live $2.50 session cap in .claude/settings.json:
agent-cost-guard install-hooks .claude/settings.json --max-usd 2.50 --write --backup
# Retrospectively audit past Claude Code JSONL sessions for loops & potential USD savings:
agent-cost-guard scan-sessions --html claude_audit.html
# In Python (works directly with OpenAI, Anthropic, or Gemini response objects/dicts):
# guard.record_llm_response(response, tool_name="web_fetch", tool_args={"url": url})
| Edition | Price | Included | License / Delivery |
|---|---|---|---|
| MIT Core | $0 (Free forever) | SessionGuard, pricing catalog, Claude Code plugin + PreToolUse/PostToolUse hooks, native MCP server + .mcpb bundle, MCP STDIO proxy, auto-discovery audit/wrap-config, CLI & zero-CDN HTML reports |
MIT open source via GitHub / pip install / Release .mcpb |
| Pro Production Policy & MCP Pack | $7 USD (one-time) | 5 production JSON policy profiles (incl. claude_code_strict), drop-in sync/async MCPToolGuardMiddleware, 15-vector injection/exfiltration suite, PII/secret redactor, Claude/Cursor MCP templates, FinOps Playbook & email support |
Direct PayPal checkout + ZIP archive delivery |
Want drop-in production presets and extended security coverage on top of the MIT core? The Pro Pack includes:
redact_secrets / redact_record) for JSONL traces before audit sharingclaude_statusline.py HUD + FinOps Threshold Playbook + email support
Instant checkout ($7 USD via PayPal):
https://www.paypal.com/paypalme/rwachtendorff/7USD
Include your email address in the PayPal payment note (or email rolando@wachtendorff.cl with your PayPal transaction ID) to receive the Pro Pack archive.