claude-usage
Fetch Claude API usage data from Anthropic.
This crate provides a simple API to retrieve usage statistics for Claude API, including 5-hour and 7-day utilization percentages.
Features
- Cross-platform credential retrieval (macOS Keychain, Linux credential file)
- Typed response structures for usage data
- Secure credential handling (read, use, discard immediately)
- Helper methods for utilization analysis
Platform Support
| Platform | Credential Source |
|---|---|
| macOS | Keychain ("Claude Code-credentials") |
| Linux | ~/.claude/.credentials.json |
Installation
[]
= "0.1"
Usage
use get_usage;
Environment Variable
The CLAUDE_CODE_OAUTH_TOKEN environment variable can be set to override
file-based credential retrieval on any platform.
Requirements
- Claude Code must be installed and logged in
- Valid OAuth credentials in platform-specific storage
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.