//! Takes one reading from Claude Code's account usage endpoint and prints it. //! //! `cargo run -p lumbridge-harness --example claude_usage` //! //! Useful for answering "what does the provider actually say right now?" //! without launching the shell. It performs exactly one request — the endpoint //! rate-limits under polling — and prints only the parsed windows. The token is //! never printed, because there is no code path here that could reach it. use lumbridge_harness::MonotonicWallClock; use lumbridge_harness::claude::WindowReading; use lumbridge_harness::claude::oauth::{ClaudeOauthOptions, RefreshOutcome, refresh}; fn main() { let options = ClaudeOauthOptions::default(); if !options.enabled { println!("the usage endpoint is disabled (LUMBRIDGE_CLAUDE_OAUTH=0)"); return; } let now_ms = MonotonicWallClock::start().now_ms(); println!("GET {}", options.endpoint); match refresh(&options, now_ms) { RefreshOutcome::Snapshot(snapshot, plan) => { println!("plan: {}", plan.label.as_deref().unwrap_or("unreported")); print_window("five hour", snapshot.five_hour, now_ms); print_window("seven day", snapshot.seven_day, now_ms); for scoped in snapshot.scoped { print_window(&scoped.model, scoped.reading, now_ms); } } RefreshOutcome::RateLimited => println!("rate limited; try again later"), RefreshOutcome::Unauthenticated => { println!("no usable credential (not signed in, expired, or disabled)"); } RefreshOutcome::Failed(error) => println!("failed: {error}"), } } fn print_window(label: &str, reading: WindowReading, now_ms: u64) { match reading { WindowReading::Usable { permille, window } => { let left = (1_000 - permille.min(1_000)) / 10; let resets = window.map_or_else( || "no reset reported".to_owned(), |window| { format!( "resets in {}", lumbridge_core::format_duration_ms(window.remaining_ms(now_ms)) ) }, ); println!("{label:>22}: {left}% left · {resets}"); } WindowReading::Absent => println!("{label:>22}: not reported"), } }