Track session costs, set budget alerts, and optimize token spend. Use to check costs mid-session or set spending limits.
git clone https://github.com/rohitg00/pro-workflow.git--- name: cost-tracker description: Track session costs, set budget alerts, and optimize token spend. Use to check costs mid-session or set spending limits. user-invocable: true --- # Cost Tracker Monitor and optimize Claude Code session costs. ## Trigger Use when: - Checking session costs - Setting budget alerts - Optimizing token spend - Planning multi-session work ## Cost Awareness ### Check Current Costs ```bash # Session cost is shown at the end of each session # Mid-session: check the status bar or run /cost ``` ### Cost Drivers | Operation | Relative Cost | Optimization | |-----------|--------------|-------------| | Large file reads | High | Use offset/limit params | | Broad grep searches | Medium | Scope to specific dirs | | Subagent spawning | High (new context) | Reuse agents via SendMessage | | Repeated tool calls | Cumulative | Batch operations | | MCP tool calls | Variable | Minimize round-trips | | Model selection | 3-10x difference | Use haiku for simple tasks | ### Token Budget by Task Type | Task | Typical Cost | Budget Alert | |------|-------------|-------------| | Bug fix | $0.10-0.50 | $1.00 | | Feature (small) | $0.50-2.00 | $3.00 | | Feature (large) | $2.00-8.00 | $10.00 | | Refactor | $1.00-5.00 | $7.00 | | Code review | $0.20-1.00 | $2.00 | ### Tool-Call Budgets Set explicit budgets by task complexity: | Task Type | Tool-Call Budget | Wrap-Up At | |-----------|-----------------|------------| | Quick fix / lookup | 20 calls | 15 | | Bug fix | 30 calls | 25 | | Feature (small) | 50 calls | 40 | | Feature (large) | 80 calls | 65 | | Refactor | 50 calls | 40 | At the wrap-up threshold: commit progress, assess remaining work, decide whether to continue or start fresh. ### Optimization Strategies 1. **Scope prompts tightly** — "Fix the auth bug in src/auth/login.ts" vs "Fix the auth bug" 2. **Use the right model** — Haiku for simple lookups, Sonnet for features, Opus for architecture 3. **Delegate to subagents** — Search/explore operations in subagents keep main context lean 4. **Compact proactively** — Don't wait for auto-compact; compact at task boundaries 5. **Read selectively** — Use `offset` and `limit` params for large files 6. **Batch operations** — Multiple independent tool calls in one message 7. **One-pass discipline** — Write complete solution, test once, stop if green 8. **No re-reads** — Don't re-read unchanged files; trust cached knowledge 9. **Read before write** — Never write a file without reading it first 10. **Kill output bloat** — No sycophantic openers, no closing fluff, no prompt restatement ## Budget Alerts Set mental checkpoints: - **50% budget** — Are you on track? Should you compact? - **80% budget** — Wrap up current task, avoid new exploration - **100% budget** — Commit what you have, start fresh session ## Output ```text COST TRACKER Session cost: $X.XX Token usage: [input]K in / [output]K out Cache hit rate: ~XX% Top cost drivers: 1. [operation] — $X.XX 2. [operation] — $X.XX Optimization tips: - [specific suggestion] ``` ## Rules - Track costs as awareness, not hard limits - Never sacrifice code quality to save tokens - Compact at task boundaries, not mid-task - Use subagents for exploration-heavy work
1. **Set up monitoring**: Start your session and immediately ask the AI to 'Track session costs and set a budget alert for $[YOUR_LIMIT]'. Replace [YOUR_LIMIT] with your desired spending cap (e.g., $0.50). 2. **Contextualize your work**: Before diving into complex tasks, provide context about your goals (e.g., 'I need to draft a 1,500-word report about renewable energy trends'). This helps the AI estimate token usage more accurately. 3. **Use mid-session checkpoints**: Every 5-10 minutes, ask for a cost update (e.g., 'Show me my current token usage and cost breakdown'). Use this to adjust your approach if spending is higher than expected. 4. **Optimize dynamically**: If costs exceed expectations, request optimization tips (e.g., 'Suggest ways to reduce token usage without sacrificing quality'). Implement changes like breaking tasks into smaller steps or using more concise language. 5. **Post-session review**: After completing your task, ask for a final cost analysis and efficiency report. Use this data to plan future sessions (e.g., 'What’s the average cost per 1,000 tokens for my typical workload?').
No install command available. Check the GitHub repository for manual installation instructions.
git clone https://github.com/rohitg00/pro-workflow/tree/main/skills/cost-trackerCopy 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.
Track the real-time cost of this AI session and provide a breakdown of token usage and estimated spend. [SET_BUDGET_ALERT] if the session exceeds [BUDGET_LIMIT] tokens or $[BUDGET_AMOUNT]. Suggest ways to optimize token usage to stay within budget. Include a summary of key cost drivers in this session so far.
Current Session Cost Analysis (as of 2:47 PM EST): - Total tokens used: 12,487 (Input: 8,231 | Output: 4,256) - Estimated cost: $0.18 (using default pricing: $0.002/input token, $0.002/output token) - Cost efficiency: 1.46 tokens per $0.01 (industry avg: ~1.2 tokens/$0.01) Budget Alert Status: - Your set budget limit: $0.50 - Current spend: $0.18 (36% of budget) - Remaining budget: $0.32 - Time to budget exhaustion: ~3,800 additional tokens (~15-20 minutes at current rate) Key Cost Drivers: 1. Complexity of queries (long-form responses consume more output tokens) 2. Multi-step reasoning (each step adds input tokens) 3. Large context windows (e.g., past messages in this thread) Optimization Recommendations: 1. Use more concise language in your prompts to reduce input tokens by ~20-30% 2. Break complex requests into smaller, sequential questions to avoid long output chains 3. Enable 'concise mode' if available to reduce verbosity in responses 4. Consider using a smaller model (e.g., switch from Claude 3 Opus to Haiku) for simpler tasks to save ~40% on costs Next Steps: - Would you like me to monitor this session in real-time and alert you when you reach 80% of your budget ($0.40)? - Should I suggest specific prompt refinements to reduce token usage?
skills-collection
Take a free 3-minute scan and get personalized AI skill recommendations.
Take free scan