generated from nhcarrigan/template
-
v1.2.0
Stablereleased this
2026-02-04 20:21:00 -08:00 | 39 commits to main since this releaseCost Management Features
1. Historical Cost Tracking & Persistence
- Backend (
src-tauri/src/cost_tracking.rs): Full Rust implementation for tracking daily costs with persistence via Tauri's store plugin - Tracks: input tokens, output tokens, cost in USD, messages sent, and session counts
- Data stored per-day with automatic aggregation for weekly/monthly periods
- Supports cost summary generation for any number of days (7, 30, 90, etc.)
- CSV export functionality for cost data
2. Cost Alert System
- Configurable thresholds: Set daily, weekly, and monthly spending limits
- Alert triggering: When spending exceeds thresholds, alerts are generated
- Desktop notifications: Alerts trigger the notification system with the "Cost Alert!" sound (reuses the "oh-no.mp3" sound file)
- Alert state resets daily to prevent duplicate notifications
3. Per-Message Cost Attribution
- New
MessageCosttype (src-tauri/src/types.rs): Tracks input tokens, output tokens, and cost USD per message - Cost flows through the entire pipeline:
- Rust backend calculates cost when processing assistant messages
- Cost data included in
OutputEventemitted to frontend - TypeScript receives and converts snake_case to camelCase
- Terminal lines can display cost badges
4. Session Recording
- Automatic session tracking (
src-tauri/src/bridge_manager.rs): Each time Claude starts, a new session is recorded - Sessions counted in daily cost summaries
- Enables tracking usage patterns over time
5. Frontend Cost Display
StatsDisplay Component (
src/lib/components/StatsDisplay.svelte)- Historical Costs section: Collapsible panel showing:
- Quick stats badges (Today, Week, Month costs)
- Expanded view with detailed cost breakdown
- Link to settings for detailed history
CostSummary Component (
src/lib/components/CostSummary.svelte)- Full cost management UI in the Config Sidebar:
- Quick stats cards (Today/Week/Month)
- Period selector (7/30/90 days)
- Detailed summary: total cost, average daily, messages, sessions, token counts
- Mini bar chart showing daily spending (last 14 days)
- CSV export button
- Alert threshold configuration UI
6. Cost Tracking Store (
src/lib/stores/costTracking.ts)- Svelte store managing cost tracking state
- Methods:
refresh(),getSummary(),setAlertThresholds(),exportCsv() - Derived store
formattedCostsfor display-ready values - Helper functions:
formatCost(),formatAlertType(),getAlertMessage() - Automatic alert notification triggering on refresh
7. Notification Integration
- New notification type:
NotificationType.COST_ALERT - Sound: Uses "oh-no.mp3" with "Cost Alert!" phrase
- Helper method:
notificationManager.notifyCostAlert()
8. Tauri Commands (Backend API)
get_today_cost: Returns today's total costget_week_cost: Returns current week's total costget_month_cost: Returns current month's total costget_cost_summary: Returns detailed summary for N daysget_cost_alerts: Checks thresholds and returns triggered alertsset_cost_alert_thresholds: Configure daily/weekly/monthly limitsexport_cost_csv: Generate CSV export of cost datarecord_cost: Record a cost entry (called internally)record_session: Record a new session start
9. Supporting Infrastructure
- Tool cache analytics (
src-tauri/src/tool_cache.rs): Framework for tracking potential cache hits (for future optimisation) - Budget status types (
src-tauri/src/stats.rs):ContextWarning,BudgetStatus,BudgetTypeenums for frontend budget warnings - Conversation utilities (
src/lib/utils/conversationUtils.ts): JSON sanitisation for safe IPC, summary generation helpers
Technical Details
Pricing Model
Uses Claude API pricing:
- Sonnet: $3/$15 per MTok (input/output)
- Opus: $15/$75 per MTok
- Haiku: $0.25/$1.25 per MTok
Data Flow
- Assistant message received in
wsl_bridge.rs - Cost calculated using
calculate_cost() - Cost recorded via
record_cost()command (async) MessageCostattached toOutputEvent- Frontend receives event, updates conversation store
costTrackingStore.refresh()called on stats updates- Alerts checked and notifications triggered if thresholds exceeded
Downloads
- Backend (