A lightweight, native macOS menubar application for tracking Claude API token usage and costs.
100% AI-Generated Code • Built with Claude Sonnet 4.5
A demonstration of AI-native software development
📖 Read our Philosophy on AI-Native Development → 🔧 Technical Documentation →
This project is entirely AI-generated - not a single line of code was manually typed. It demonstrates:
- 🤖 AI as Developer - Claude Sonnet 4.5 wrote 100% of the Swift code
- 👨💻 Human as Architect - Petr provided requirements, reviewed, and tested
- 🔄 Iterative Refinement - Back-and-forth conversation to perfect the implementation
- ✅ Production Quality - Proper sandboxing, security, and Apple best practices
- 📚 Full Documentation - README, contributing guide, all AI-generated
See CODE_OF_CONDUCT.md for our AI-native development philosophy.
✨ Live Session Tracking - Real-time token counter updates as you chat (2 Hz polling) 📊 Visual Analytics - 7-day usage chart with daily breakdown 💰 Cost Estimation - Calculates costs based on Anthropic pricing 📈 Dual Monitoring - Historical stats from cache + live JSONL file monitoring
📈 Daily/Monthly Breakdown - Comprehensive usage tables by day or month 🤖 Per-Model Statistics - See which Claude models you use most (Opus, Sonnet, Haiku) 💵 Model-Specific Pricing - Accurate costs with cache token calculations 📊 Interactive Charts - Visual representation of usage trends 📝 Message Counting - Track number of messages alongside tokens 🔍 Deduplication - Prevents duplicate entries from being counted
⚡ Ultra Lightweight - Uses only 8-15MB RAM with 0% CPU in background 🔋 Battery Efficient - Kernel-level file monitoring (FSEvents) + smart caching 🎨 Native UI - SwiftUI interface with dark mode support 🔒 Sandboxed - Follows Apple's security best practices
Real-time token tracking with live session monitoring
Comprehensive analytics with daily/monthly breakdowns and per-model statistics
- Download Claude-Tracker.dmg
- Open the DMG file
- Drag Claude-Tracker.app to your Applications folder
- Launch from Applications
- On first launch, grant access to the
~/.claudefolder when prompted
Note: The app may show a security warning on first launch (unsigned app). Right-click the app and select "Open" to bypass Gatekeeper.
-
Clone the repository:
git clone https://github.com/yourusername/Claude-Tracker.git cd Claude-Tracker -
Open in Xcode:
open Claude-Tracker/Claude-Tracker.xcodeproj
-
Build and run (⌘+R)
-
On first launch, grant access to the
~/.claudefolder when prompted
- Launch the app - A Claude C icon appears in your menubar
- Grant file access - On first launch, select the
.claudefolder in your home directory (press ⌘⇧. to show hidden files) - Click the icon - View your quick token usage statistics
- Detailed Analytics - Click the "Detailed Analytics" button for comprehensive breakdowns
- Live session token tracking (updates every 0.5s)
- Today's confirmed usage from cache
- Total usage and cost estimates
- 7-day usage chart
- Cache efficiency metrics
- Overview: Summary with charts and top models
- Daily: Day-by-day usage table
- Monthly: Month-by-month aggregation
- Models: Per-model breakdown with costs and percentages
The app runs silently in the menubar and automatically updates when you use Claude Code!
Claude Tracker uses a dual monitoring approach for comprehensive token tracking:
Monitors ~/.claude/stats-cache.json for confirmed usage data:
- FSEvents - Kernel-level file monitoring for zero CPU overhead
- Auto-refresh - Updates every 3 seconds for recent stats
- Displays: Today's usage, total usage, 7-day chart, cache efficiency
Monitors active conversation JSONL files in ~/.claude/projects/:
- Real-time updates - Polls at 2 Hz (0.5s) when UI is open
- Smart file detection - Automatically finds the most recently modified conversation
- Session tracking - Shows tokens consumed since you opened the menubar
- Efficient caching - Caches active file path to avoid directory scanning
- Security-Scoped Bookmarks - Proper sandboxed file access to
.claudefolder - SwiftUI - Native, efficient UI rendering
- DispatchQueue - Background parsing on utility QoS
- Adaptive polling - 2 Hz active, 30s background to save battery
- Memory: 8-15 MB (idle)
- CPU: 0.0% (background)
- Battery Impact: None (Activity Monitor: "No impact")
- ✅ Sandboxed - Runs in App Sandbox for security
- ✅ Read-only access - Only reads stats, never modifies anything
- ✅ No network - All data stays on your device
- ✅ No telemetry - We don't collect any usage data
- ✅ Open source - Fully auditable code
- macOS 13.0 (Ventura) or later
- Claude Code installed and configured
- Xcode 15+ (for building from source)
Token costs are calculated using model-specific pricing based on Anthropic's pricing:
- Input tokens: $15.00 per 1M tokens
- Output tokens: $75.00 per 1M tokens
- Cache writes: $18.75 per 1M tokens
- Cache reads: $1.50 per 1M tokens
- Input tokens: $3.00 per 1M tokens
- Output tokens: $15.00 per 1M tokens
- Cache writes: $3.75 per 1M tokens
- Cache reads: $0.30 per 1M tokens
- Input tokens: $0.25 per 1M tokens
- Output tokens: $1.25 per 1M tokens
- Cache writes: $0.30 per 1M tokens
- Cache reads: $0.03 per 1M tokens
Note: Costs are estimates and may not reflect your actual billing. Check your Anthropic dashboard for accurate billing information.
Claude-Tracker/
├── ClaudeStats.swift # Data models & JSON parsing
├── StatsMonitor.swift # File monitoring & state management
├── LiveTokenMonitor.swift # Real-time JSONL conversation tracking
├── FileAccessManager.swift # Sandboxed file access
├── MenuBarView.swift # Menubar popover UI
├── DetailedAnalyticsView.swift # Comprehensive analytics window
├── ModelPricingCalculator.swift # Model-specific pricing
├── UsageAggregator.swift # Daily/monthly aggregation
├── Claude_TrackerApp.swift # App lifecycle & window management
└── Info.plist # App configuration
FileAccessManager (Singleton)
↓ Security-scoped bookmarks for ~/.claude folder
↓
StatsParser LiveTokenMonitor
↓ JSON parsing ↓ JSONL file monitoring
↓ ↓ Active conversation detection
↓ ↓ Real-time token counting
↓ ↓
StatsMonitor (ObservableObject) ←──┘
↓ FSEvents monitoring
↓ Published state (2 data sources)
↓
MenuBarPopoverView (SwiftUI) UsageAggregator
↓ SwiftUI Charts ↓ Daily/Monthly aggregation
↓ Live session display ↓ Per-model statistics
↓ Quick stats UI ↓ Message counting
↓ ↓ Deduplication
↓ ↓
└───────────────────────────────────┤
↓
DetailedAnalyticsView (SwiftUI)
↓ Tabbed interface
↓ Charts & Tables
↓ Model pricing breakdown
Contributions are welcome! But remember: we prefer AI-generated code.
See CONTRIBUTING.md for guidelines.
The AI-Native Way:
- Describe what you want to add (in an issue or PR description)
- Share your conversation with Claude/GPT that implements it
- Submit the generated code with proper attribution
- Include
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>in commits
Traditional contributions (manually written code) are still accepted, but we'll ask "why didn't you just ask Claude?" 😉
Read our AI-Native Code of Conduct to understand our development philosophy.
- Menubar quick stats with live session tracking
- Detailed analytics window with daily/monthly breakdowns
- Per-model statistics and pricing
- Message counting and deduplication
- App Store distribution
- Launch at login option
- Custom cost thresholds with notifications
- Export usage data to CSV/JSON
- Widget support (macOS 14+)
- Multiple Claude account support
- Customizable refresh intervals
Q: Why do I need to grant file access?
A: The app is sandboxed for security. Security-scoped bookmarks allow safe, persistent access to the .claude folder (for both stats-cache.json and conversation JSONL files).
Q: What is "Live Session (Since Opened)"? A: This tracks tokens consumed in the active conversation since you opened the menubar popover. It updates in real-time (every 0.5s) by monitoring the JSONL conversation file.
Q: Why are there two token counts? A: "Live Session" shows real-time usage from the current conversation. "Today (Confirmed)" shows verified stats from Claude Code's cache. Live updates immediately; confirmed updates after conversations complete.
Q: What's in the Detailed Analytics window? A: The detailed analytics provides:
- Overview: Summary cards, charts, and top models by cost
- Daily View: Day-by-day breakdown with model usage
- Monthly View: Month-by-month aggregation for long-term trends
- Models Tab: Per-model statistics with cost percentages and token breakdowns
Q: How accurate are the per-model costs? A: Very accurate! We use Anthropic's official pricing for each model (Opus, Sonnet, Haiku) including cache token calculations. Costs are calculated per message with model-specific rates.
Q: Will this work with claude.ai? A: No, this only tracks usage from Claude Code (the CLI tool). claude.ai usage is tracked separately in your Anthropic account.
Q: Does this affect Claude Code performance? A: No, the app only reads files that Claude Code writes. No interference with Claude Code operation. Efficient caching minimizes file system overhead.
Q: Can I use this on Windows/Linux? A: Currently macOS only. A cross-platform version using Tauri could be developed if there's interest.
This project is licensed under the MIT License - see the LICENSE file for details.
- Built entirely with Claude Sonnet 4.5 (not a single line manually typed)
- Human architect: Petr Guan (prompting, testing, reviewing)
- Inspired by Claude-Code-Usage-Monitor for analytics features
- Inspired by iStat Menus and other system monitoring tools
- Thanks to Anthropic for creating Claude and Claude Code
- A demonstration that AI can generate production-quality, App Store-ready code
This README was also AI-generated. The irony is not lost on us.
- 🐛 Report a bug
- 💡 Request a feature
- ⭐ Star this repo if you find it useful!
- 🤖 Share your AI-generated contributions
Made with ❤️ (and AI) for the Claude Code community
Humans provide vision. AI provides implementation. Together, we build the future.