Track and optimize Claude Code usage with intelligent recommendations
Track Claude Code usage and get intelligent recommendations to optimize costs and avoid hitting limits. Use after running `/usage` to enable automatic model switching (Haiku for research tasks) and smart task queuing.
/plugin marketplace add Shakes-tzd/contextune/plugin install contextune@ContextuneContextune integrates with Claude Code's /usage command to provide intelligent context optimization, cost savings, and proactive warnings.
Run Claude Code's usage command:
/usage
Copy the entire output
Run this command and paste when prompted:
/contextune:usage
Contextune automatically estimates usage based on tracked operations (~85% accurate for Contextune tasks only).
View current estimates:
/contextune:stats
Based on your current usage, Contextune provides:
š Current Usage Analysis
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
š Usage Metrics:
Session: 19% (resets 1:00am America/New_York)
Weekly: 90% (resets Oct 29, 10:00pm America/New_York) ā ļø CRITICAL
Opus: 0%
šÆ Status: CRITICAL
ā ļø Warnings:
⢠CRITICAL: 90% weekly usage (resets Oct 29, 10:00pm)
⢠You have ~10% capacity until Oct 29, 10:00pm
š” Recommendations:
⢠Switch research tasks to Haiku (87% cost savings)
⢠Recommended max parallel tasks: 2
⢠Consider deferring non-critical tasks until weekly reset
⢠⨠Opus available (0% used) - great for complex architecture tasks
š Historical Trends:
⢠Average daily usage: 12.9% (7-day trend)
⢠Projected usage to limit: [calculation]
⢠Cost savings from Haiku: $0.42 this week
| Weekly Usage | Status | Automatic Actions |
|---|---|---|
| 0-70% | ā Healthy | Normal operation, all models available |
| 71-85% | ā ļø Warning | Suggest Haiku for research tasks |
| 86-95% | šØ Critical | Auto-switch to Haiku, limit parallel tasks |
| 96-100% | š Limit | Defer all tasks until reset |
Once you've logged your usage, Contextune automatically:
Research Tasks (/ctx:research):
Planning (/ctx:plan):
Execution (/ctx:execute):
Contextune can parse Claude Code's /usage output in this format:
Current session
[progress bar] 19% used
Resets 1:00am (America/New_York)
Current week (all models)
[progress bar] 90% used
Resets Oct 29, 10:00pm (America/New_York)
Current week (Opus)
[progress bar] 0% used
Just paste the entire block when prompted.
Without optimization:
With Contextune (90% usage):
Without optimization:
With Contextune (90% usage):
Usage snapshots are stored in .contextune/observability.db:
CREATE TABLE usage_history (
timestamp REAL PRIMARY KEY,
session_percent REAL,
weekly_percent REAL,
opus_percent REAL,
session_reset TEXT,
weekly_reset TEXT
);
When manual data isn't available, Contextune estimates usage from tracked operations:
# Rough estimates (Claude 3.5 limits)
SESSION_LIMIT = 200,000 tokens # Per session limit
WEEKLY_LIMIT = 1,000,000 tokens # Per week limit
# Calculation
session_percent = (tracked_tokens / SESSION_LIMIT) * 100
Accuracy: ~85% for Contextune operations only (doesn't track other Claude Code sessions)
Contextune tries multiple approaches:
Cause: All automatic methods failed Solution: Use manual paste workflow:
/usage
# Copy output
/contextune:usage
# Paste when prompted
Cause: Token estimation only tracks Contextune operations Solution: Use manual paste for accurate data including all Claude Code sessions
Cause: Experimental feature timing out Solution: Press Ctrl+C to cancel, use manual paste instead
.contextune/observability.db/usage - Claude Code's native usage command/context - Claude Code's context management/contextune:stats - View Contextune detection statistics/contextune:config - Configure Contextune settingsPlanned for v1.0:
Pro Tip: Run /contextune:usage at the start of your session to enable intelligent optimization for all subsequent tasks.