Cost Guardian is a real-time budget enforcement and cost tracking tool for Claude Code. It helps operations teams monitor and optimize spending, ensuring adherence to budget constraints. It integrates with Claude Code's CLI and provides actionable insights for cost management.
git clone https://github.com/Belkins/cost-guardian.gitCost Guardian is a native Claude Code plugin that monitors your Claude API spending in real-time, enforcing budget limits at session, daily, monthly, or project scopes. Unlike external cost tracking tools, it warns you before expensive operations happen and offers three enforcement modes—warn, confirm, or block—to match your team's cost policies. The plugin automatically tracks costs per operation and file, estimates expenses before execution via pre-operation hooks, and generates AI-powered optimization suggestions based on usage patterns. Operations teams and individual developers use Cost Guardian to prevent budget overruns, identify redundant API calls, and discover model optimization opportunities that typically yield 30-50% savings on Claude costs.
1. **Installation**: Add the Cost Guardian extension to your Claude Code CLI using `npm install -g cost-guardian` and authenticate with your cloud provider credentials. 2. **Configuration**: Create a `cost-guardian.json` file in your project root with budget parameters (e.g., {"budget_cap": 5000, "threshold_percent": 80, "cloud_providers": ["aws", "gcp"]}). 3. **Integration**: Add the Cost Guardian hook to your Claude Code workflow by including `// @cost-guardian` at the top of your main script file. 4. **Monitoring**: Run `cost-guardian monitor --project Phoenix` to start real-time tracking. The tool will automatically flag anomalies and provide optimization suggestions. 5. **Action**: Review the generated report and implement the suggested optimizations. Use `cost-guardian optimize --action [ACTION_ID]` to track which suggestions have been applied. **Tips:** - Set up Slack/email alerts for critical budget breaches using `cost-guardian alerts --channel #finance` - Use the `--dry-run` flag to simulate cost changes before applying them - Review weekly cost trends with `cost-guardian trends --period 7d`
Monitor per-session and daily API spending limits during Claude Code development
Prevent budget overruns with pre-operation cost warnings before expensive file reads or edits
Identify redundant API calls and model optimization opportunities via automated analysis
Enforce team cost policies with configurable enforcement modes (warn/confirm/block)
No install command available. Check the GitHub repository for manual installation instructions.
git clone https://github.com/Belkins/cost-guardianCopy the install command above and run it in your terminal.
Launch Claude Code, Cursor, or your preferred AI coding agent.
Use the prompt template or examples below to test the skill.
Adapt the skill to your specific use case and workflow.
Act as Cost Guardian for my Claude Code project. Monitor real-time spending for [PROJECT_NAME] and enforce the budget cap of $[BUDGET_CAP] per month. Flag any cost spikes exceeding $[THRESHOLD_PERCENT]% of the monthly budget. Provide a breakdown of top cost drivers and suggest 3 optimization actions to reduce spending. Current monthly spend: $[CURRENT_SPEND].
Cost Guardian Report for Project Phoenix (Budget: $5,000/month | Current Spend: $3,200 | Threshold: 80%) **ALERT: Spending exceeds 64% of monthly budget** Top Cost Drivers: 1. Cloud Compute (AWS EC2): $1,850 (57.8% of spend) - *Spike detected: +42% vs last week* - Primary contributor: ml.g5.2xlarge instances for model training (3 instances running 24/7) - Recommendation: Schedule training during off-peak hours or switch to spot instances 2. API Calls (OpenAI): $980 (30.6% of spend) - *Stable usage pattern* - 12,400 API calls this month (avg $0.079/call) - Recommendation: Implement caching layer for frequent queries 3. Storage (S3): $370 (11.6% of spend) - *Gradual increase* - 450GB stored (growth: +15GB/week) - Recommendation: Archive old model versions to Glacier **Optimization Actions (Potential Savings: $850/month):** 1. Resize EC2 instances: Switch ml.g5.2xlarge to ml.g5.xlarge during non-peak hours (-$420) 2. Implement API caching: Reduce calls by 30% (-$294) 3. Archive old models: Move 200GB to Glacier (-$136) **Next Steps:** - [ ] Implement instance resizing by EOD today - [ ] Add caching middleware to API layer - [ ] Set up automated archiving script for S3 *Report generated at 2024-05-15 14:32 UTC | Next check in 4 hours*
AI assistant built for thoughtful, nuanced conversation
Zero-based budgeting for financial control
Open-source budgeting made simple
Get more done every day with Microsoft Teams – powered by AI
IronCalc is a spreadsheet engine and ecosystem
Customer feedback management made simple
Take a free 3-minute scan and get personalized AI skill recommendations.
Take free scan