Read Claude Code's own quota endpoint, not just its status line

Decision 0015 rejected the account usage endpoint because AGENTS.md forbade
reading a harness's credential. The rule was written to stop one program
helping itself to another's secrets, and it was catching a legitimate use with
it: the user asking about their own subscription, through software they
installed to do that. AGENTS.md now states the narrow allowance instead of an
absolute the project does not hold, and 0016 records it.

The status line stays. It is free and it speaks every turn. What it cannot do
is report the per-model weekly limits a Max plan meters separately, or answer
at all before a session has taken a turn. The first live reading found the
account-wide seven-day window at 38% left and a per-model weekly window at 77%
left — a second ceiling the footer previously could not see.

Constraints the credential is read under, all enforced in code: access token
only, never the refresh token; zeroed on drop, along with the file buffer it
was borrowed out of; unprintable by construction, since HarnessError carries no
owned strings and AccessToken's Debug is hand-written; identified as
lumbridge/<version>, because sending claude-code/2.1.0 would make our traffic
indistinguishable from the harness's in Anthropic's logs; and off entirely
under LUMBRIDGE_CLAUDE_OAUTH=0.

The request runs on a detached thread with a slow refresh and a 429 backoff, so
a ten-second round trip cannot stall the transcript follower or make quitting
wait on the network, and one surface failing does not fault the other two.

Footer polish on top: the harness name prints once per group instead of in
front of each of its four windows, each quota carries a short scope pill
(5h, 7d, Fable wk, tokens) where an invisible BORDER-weight label used to be,
quotas sort ahead of spend, and a window under ten percent turns its headline
amber — value colour on the number, provenance colour on the meter, never
mixed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Metal Agent
2026-08-31 22:04:34 -07:00
co-authored by Claude Opus 5
parent ef52aa7ce2
commit 219c674aea
13 changed files with 1674 additions and 73 deletions
+45 -12
View File
@@ -2126,10 +2126,21 @@ impl LumbridgeShell {
.child("no harness on this pane"),
)
})
.children(segments.into_iter().map(|segment| {
let selected = active.as_ref() == Some(&segment.id);
usage_segment(segment, selected)
}))
// The harness name is printed once per group. Repeating
// "CLAUDE CODE" in front of four of its own windows spends the
// strip's width on a word the eye has already read.
.children({
let mut previous: Option<String> = None;
segments
.into_iter()
.map(|segment| {
let repeats = previous.as_deref() == Some(segment.label.as_str());
previous = Some(segment.label.clone());
let selected = active.as_ref() == Some(&segment.id);
usage_segment(segment, selected, repeats)
})
.collect::<Vec<_>>()
})
}
}
@@ -2176,9 +2187,20 @@ fn usage_meter(consumed_permille: Option<u64>, color: u32) -> impl IntoElement {
.into_any_element()
}
fn usage_segment(segment: UsageSegment, selected: bool) -> impl IntoElement {
/// One quota in the strip.
///
/// `continues_group` means the harness above this one is the same, so its name
/// is left off and only the window is named.
fn usage_segment(segment: UsageSegment, selected: bool, continues_group: bool) -> impl IntoElement {
let color = provenance_color(segment.provenance);
let name_color = if selected { TEXT } else { MUTED };
let headline_color = if segment.headline.is_none() {
MUTED
} else if segment.critical {
ATTENTION
} else {
TEXT
};
div()
.flex()
.items_center()
@@ -2186,21 +2208,32 @@ fn usage_segment(segment: UsageSegment, selected: bool) -> impl IntoElement {
.when(selected, |view| {
view.px_2().py_1().rounded(px(4.0)).bg(rgb(PANEL_ACTIVE))
})
.when(!continues_group, |view| {
view.child(
div()
.flex_none()
.text_color(rgb(name_color))
.child(segment.label),
)
})
// A quiet pill rather than more running text. The window's name is a
// label on the number, not another number, and at BORDER weight it was
// simply invisible.
.child(
div()
.flex_none()
.text_color(rgb(name_color))
.child(segment.label),
.px(px(5.0))
.py(px(1.0))
.rounded(px(3.0))
.bg(rgb(if selected { BORDER } else { BORDER_QUIET }))
.text_color(rgb(if selected { TEXT } else { MUTED }))
.child(segment.scope),
)
.child(usage_meter(segment.consumed_permille, color))
.child(
div()
.flex_none()
.text_color(rgb(if segment.headline.is_some() {
TEXT
} else {
MUTED
}))
.text_color(rgb(headline_color))
.child(segment.headline.unwrap_or_else(|| "no reading".to_owned())),
)
.when_some(segment.reset, |view, reset| {
+59 -19
View File
@@ -183,6 +183,17 @@ impl UsageFeed {
let outcome = probe.poll();
let health = outcome.health();
for profile in probe.profiles() {
// A probe may announce a profile after it starts: the per-model
// weekly limits are named by the provider's response, so they
// cannot be declared up front. Without this they would report
// readings the strip has no profile to render them against.
if self
.profiles
.insert(profile.id().clone(), profile.clone())
.is_none()
{
changed = true;
}
if self.health.insert(profile.id().clone(), health) != Some(health) {
changed = true;
}
@@ -255,28 +266,46 @@ impl UsageFeed {
.into_iter()
.filter_map(|id| self.segment(id))
.collect();
// Two windows on one account would otherwise both read "CODEX". A
// strip that names two different quotas the same thing is worse than
// a longer label.
let duplicated: Vec<String> = segments
.iter()
.filter(|segment| {
segments
.iter()
.filter(|other| other.label == segment.label)
.count()
> 1
})
.map(|segment| segment.label.clone())
.collect();
for segment in &mut segments {
if duplicated.contains(&segment.label) {
segment.label = format!("{} {}", segment.label, segment.model.to_uppercase());
// Keep one harness's quotas together. Claude Code alone reports four,
// and a strip that interleaves them with Codex reads as eight unrelated
// numbers instead of two accounts. Stable within a group, so a segment
// never moves under the pointer.
let mut order: Vec<String> = Vec::new();
for segment in &segments {
if !order.contains(&segment.label) {
order.push(segment.label.clone());
}
}
segments.sort_by_key(|segment| {
(
order
.iter()
.position(|label| *label == segment.label)
.unwrap_or(usize::MAX),
// Quotas before spend within a harness. "How much is left" is
// the question; "how much was used" is the footnote.
usize::from(segment.consumed_permille.is_none()),
)
});
segments
}
/// The shortest unambiguous name for a quota window.
///
/// The provider's own wording — "five-hour window", "Fable weekly" — is
/// right in a detail view and far too long in a strip that has to hold six
/// of them.
fn short_scope(model: &str) -> String {
match model {
"five-hour window" => "5h".to_owned(),
"seven-day window" => "7d".to_owned(),
"session transcripts" => "tokens".to_owned(),
other => other
.strip_suffix(" weekly")
.map_or_else(|| other.to_owned(), |name| format!("{name} wk")),
}
}
fn segment(&self, id: &AccountProfileId) -> Option<UsageSegment> {
let profile = self.profiles.get(id)?;
let projection = self.projection(id);
@@ -285,7 +314,7 @@ impl UsageFeed {
Some(UsageSegment {
id: id.clone(),
label: profile.harness().to_uppercase(),
model: profile.model().to_owned(),
scope: Self::short_scope(profile.model()),
consumed_permille,
// "How much do I have left" is the question an engineer actually
// asks. Consumption stays available in the expanded detail.
@@ -310,6 +339,10 @@ impl UsageFeed {
let unit = projection.unit()?;
Some(format!("{} used", unit.format_amount(consumed)))
}),
// Ten percent of a window is the point at which the number stops
// being background information and starts being a decision about
// what to run next.
critical: consumed_permille.is_some_and(|permille| permille >= 900),
// A profile that reports spend but no ceiling and no reset should
// say so where the reset would go, rather than leaving a silent
// gap that reads as "we just haven't shown it yet".
@@ -361,11 +394,18 @@ impl Drop for UsageFeed {
pub(crate) struct UsageSegment {
pub(crate) id: AccountProfileId,
pub(crate) label: String,
pub(crate) model: String,
/// The window this segment is about, in the shortest form that stays
/// unambiguous: `5h`, `7d`, `fable wk`, `tokens`. One account has several
/// quotas and the strip has to name which one it is showing.
pub(crate) scope: String,
pub(crate) consumed_permille: Option<u64>,
/// What to lead with: how much is left when a ceiling is known, how much
/// was spent when it is not, and nothing at all when there is no reading.
pub(crate) headline: Option<String>,
/// Nearly gone. Drives the headline's colour, never the meter's: the meter
/// carries provenance, and mixing the two would make a trustworthy reading
/// and an alarming one look the same.
pub(crate) critical: bool,
pub(crate) reset: Option<String>,
pub(crate) burn: String,
pub(crate) burn_provenance: UsageProvenance,