claude-usage

Crates.ioclaude-usage
lib.rsclaude-usage
version0.1.0
created_at2026-01-25 14:30:01.335679+00
updated_at2026-01-25 14:30:01.335679+00
descriptionFetch Claude API usage data from Anthropic
homepagehttps://github.com/PabloLION/agent-console-dashboard
repositoryhttps://github.com/PabloLION/agent-console-dashboard
max_upload_size
id2068838
size90,657
Pablo LION (PabloLION)

documentation

https://docs.rs/claude-usage

README

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

[dependencies]
claude-usage = "0.1"

Usage

use claude_usage::get_usage;

fn main() -> Result<(), claude_usage::Error> {
    let usage = get_usage()?;

    println!("5-hour utilization: {}%", usage.five_hour.utilization);
    println!("7-day utilization: {}%", usage.seven_day.utilization);

    // Check if usage is sustainable
    if usage.five_hour_on_pace() {
        println!("5-hour usage is on pace");
    }

    // Get time until reset
    let time_left = usage.five_hour.time_until_reset();
    println!("Resets in {} minutes", time_left.num_minutes());

    Ok(())
}

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:

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.

Commit count: 93

cargo fmt