Repository navigation
Conversation
Claude Code's status line input carries only the 5-hour and 7-day windows, so the weekly Fable limit is missing. The new quota.fable item reads it from the usage endpoint's limits[] row (kind weekly_scoped, scoped to a model labeled Fable). Renders only read the recorded answer; a detached `ccline usage-check` refreshes it at most every five minutes, and only when a line shows quota.fable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reviewer's GuideData structuresAdd the persisted OAuth usage state and per-profile storage for the Fable weekly window, including its refresh status and failure reason.
APIExpose a hidden
Uses of the APIConnect opted-in status and task-line renders to the cached Fable window, and dispatch the background usage check through the CLI.
ImplementationImplement asynchronous refresh, credential selection, endpoint parsing, and protection against stale or failed checks overwriting a usable Fable limit.
UIRegister
DocumentationDocument the new quota metric, its endpoint and credentials, and its opt-in refresh behavior in both READMEs.
TestsAdd regression coverage for metric discovery, Fable window rendering, credential and endpoint handling, and preview scenario values.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Linked issuesChecked at commit 487946a #144 Show the weekly Fable limit (not in the status line input) · 6 of 6 met
|
There was a problem hiding this comment.
Hey - I've found 8 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/state/mod.rs" line_range="174" />
<code_context>
/// What the companion mod reports for this session.
pub bridge: Option<std::rc::Rc<bridge::Bridge>>,
+ /// The Fable weekly limit, from the usage endpoint.
+ pub fable_weekly: Option<crate::input::Window>,
}
</code_context>
<issue_to_address>
**Downstream struct literals stop compiling**
When an external consumer constructs `StateView` without struct-update syntax, downstream crates that construct the public `StateView` with a complete struct literal now fail to compile because the new required `fable_weekly` field is missing.
Provide a compatible construction API and avoid exposing `StateView` as an externally constructible field-by-field struct.
</issue_to_address>
### Comment 2
<location path="src/state/oauth_usage.rs" line_range="55" />
<code_context>
+
+fn paths() -> (PathBuf, PathBuf) {
+ (
+ dir().join("oauth_usage.json"),
+ dir().join("oauth_usage.lock"),
+ )
</code_context>
<issue_to_address>
**Previous account quota appears**
When the same ccline state directory is used with different Claude profiles or accounts, `paths()` stores the cached window and refresh lock in the shared state directory, while token lookup follows the active Claude config. `fable_weekly()` can therefore return the previous profile’s quota, and the shared lock can suppress the correct profile’s refresh; failed checks leave the old value visible until reset.
Scope the cached window and refresh lock to the active Claude profile or account, or invalidate them when that profile changes.
Also at `src/main.rs:85-86`, `src/state/oauth_usage.rs:70-73`, `src/state/oauth_usage.rs:79`.
</issue_to_address>
### Comment 3
<location path="src/state/oauth_usage.rs" line_range="76-93" />
<code_context>
+}
+
+/// Check now, record the result and release the background lock.
+pub fn check(now: i64) {
+ let (path, lock) = paths();
+ let answer = access_token().and_then(|token| fetch(&token));
+ let previous: UsageState = read_json(&path).unwrap_or_default();
+ let state = match answer {
+ Some(body) => UsageState {
+ checked_at: now,
+ ok: true,
+ fable_weekly: fable_window(&body),
+ },
+ None => UsageState {
+ checked_at: now,
+ ok: false,
+ ..previous
+ },
+ };
+ let _ = write_json(&path, &state);
+ swr::release(&lock);
+}
+
</code_context>
<issue_to_address>
**Concurrent checks overwrite newer quota**
When a manual `ccline usage-check` runs while a render-started check is in flight, `check()` writes its response without verifying that it owns the refresh lock, then releases the shared lock. A later render can start another check, and whichever response finishes last can replace fresher quota data and reset the refresh timestamp.
Make checks acquire and release only their own lock, and prevent an overlapping check from writing over a newer result.
Also at `src/main.rs:29`.
</issue_to_address>
### Comment 4
<location path="src/config/mod.rs" line_range="248-252" />
<code_context>
impl Config {
+ /// Whether any status line shows `metric`.
+ pub fn shows(&self, metric: &str) -> bool {
+ self.lines
+ .iter()
+ .flat_map(|l| l.left.iter().chain(&l.right))
+ .any(|item| item.config().metric == metric)
+ }
+
pub fn to_toml(&self) -> String {
</code_context>
<issue_to_address>
**Subagent quota has no reading**
When a user configures `quota.fable` in the subagent line, `Config::shows` checks only the main lines, and the normal render path sets `view.fable_weekly` after the subagent path has returned. The subagent frame therefore has no Fable reading and does not start a background refresh.
Recognize `quota.fable` in the subagent line and populate its frame with the Fable reading before rendering it.
Also at `src/main.rs:84-87`.
</issue_to_address>
### Comment 5
<location path="src/state/oauth_usage.rs" line_range="115-118" />
<code_context>
+/// else its `.credentials.json`. An expired token is left alone; Claude
+/// Code refreshes it on its next request.
+fn access_token() -> Option<String> {
+ let raw = keychain_credentials().or_else(|| {
+ std::fs::read_to_string(crate::paths::claude_dir().join(".credentials.json")).ok()
+ })?;
+ token_from_credentials(&raw, chrono::Utc::now().timestamp_millis())
+}
+
</code_context>
<issue_to_address>
**Valid file token is skipped**
When the macOS keychain command succeeds with invalid or expired credentials while `.credentials.json` contains a valid token, `or_else` selects the keychain credentials, then `token_from_credentials()` returns `None` without trying the file credentials, so the Fable limit stays unavailable.
Try the `.credentials.json` credentials when the keychain credentials do not produce a valid token.
</issue_to_address>
### Comment 6
<location path="src/metrics/usage.rs" line_range="97" />
<code_context>
+ Metric {
+ meta: MetricMeta {
+ widget: WidgetKind::Pace,
+ templates: ["Fable {pct}%[ · {reset}]", "Fable {pct}%", "{pct}%"],
+ fields: WINDOW_FIELDS,
+ levels: LEVELS,
</code_context>
<issue_to_address>
**Fable percentage loses its label**
When a layout selects the compact or minimal template for `quota.fable`, the selected template renders only `{pct}%`, so the Fable limit is indistinguishable from other quota items that share its icon.
Keep a Fable label in every template variant.
</issue_to_address>
### Comment 7
<location path="src/state/oauth_usage.rs" line_range="164-169" />
<code_context>
+/// the same test Claude Code applies.
+fn fable_window(body: &Value) -> Option<StoredWindow> {
+ let row = body.get("limits")?.as_array()?.iter().find(|row| {
+ row.get("kind").and_then(Value::as_str) == Some("weekly_scoped")
+ && row
+ .pointer("/scope/model/display_name")
+ .and_then(Value::as_str)
+ .is_some_and(is_fable)
+ })?;
+ Some(StoredWindow {
+ used_percentage: row.get("percent")?.as_f64()?,
</code_context>
<issue_to_address>
**Quota depends on API row order**
When the usage response contains more than one `weekly_scoped` row with a Fable-prefixed model label, `fable_window` takes the first matching row, so when `limits[]` contains multiple weekly-scoped Fable model rows, the stored percentage depends on API array order and can represent a different model’s limit.
Define how multiple matching model limits should resolve and apply that selection or aggregation explicitly.
</issue_to_address>
### Comment 8
<location path="src/state/oauth_usage.rs" line_range="80-92" />
<code_context>
+ let (path, lock) = paths();
+ let answer = access_token().and_then(|token| fetch(&token));
+ let previous: UsageState = read_json(&path).unwrap_or_default();
+ let state = match answer {
+ Some(body) => UsageState {
+ checked_at: now,
+ ok: true,
+ fable_weekly: fable_window(&body),
+ },
+ None => UsageState {
+ checked_at: now,
+ ok: false,
+ ..previous
+ },
+ };
+ let _ = write_json(&path, &state);
+ swr::release(&lock);
+}
</code_context>
<issue_to_address>
**Quota fetch failures are invisible**
When credentials are unavailable, the endpoint request or response parsing fails, or the state file cannot be written, `check()` turns missing credentials, curl errors, and invalid response JSON into `None`, records `ok: false`, and ignores write errors. The render then either keeps showing a cached value or hides the metric, with no diagnostic to distinguish a broken integration from an account without a Fable limit.
Record or emit a rate-limited diagnostic that distinguishes credential, request, parse, and persistence failures while keeping renders non-blocking.
</issue_to_address>Sourcery assessment
Approval pending. 8 findings to address first.
Blocking findings: src/state/mod.rs:174, src/state/oauth_usage.rs:55, src/state/oauth_usage.rs:93, src/config/mod.rs:252, src/state/oauth_usage.rs:118, and 3 more
Config::shows looked at the status lines only, and the subagent render never asked for the window, so quota.fable on the subagent line stayed empty and started no refresh. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ck failed - Record the answer per Claude config directory, so two profiles sharing one ccline home don't show each other's limit or hold each other's refresh lock. - Use the first credentials that hold a usable token: an expired keychain item no longer hides a valid .credentials.json. - Record why a check got no answer (no_token, request, response), to tell a broken setup from an account without the limit. - A check that started earlier no longer overwrites the answer of one that started later. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Went through the Sourcery findings. Five are addressed in 165e5d8 and 487946a; three I left as they are, with reasons below. Changed
Not changed
Tests: One correction to the description above: the state file is now |
Closes #144
Adds
quota.fable, the weekly Fable limit, which Claude Code doesn't pass to status lines.How it works
limits[]row of/api/oauth/usagewithkind: "weekly_scoped"and a model label starting with the word "Fable" (the test Claude Code applies, so "Fable 5.2" also matches). The reset time is rounded to the minute, since the endpoint can send22:59:59.state/oauth_usage.json. When it is older than 5 minutes (15 after a failed check), a render starts a detachedccline usage-check(hidden subcommand) behind the existingswrlock, which calls the endpoint through curl and records the answer. No HTTP stack is added.quota.fable(Config::shows).Claude Code-credentials, else.credentials.jsonin the Claude config directory. WithCLAUDE_CONFIG_DIRset it uses the file only, rather than guess the suffixed keychain name. The token goes to curl on stdin (-H @-), never on its command line. An expired token is skipped; ccline never refreshes it, so it can't disturb Claude Code's own sign-in.Pacewindow likequota.5h/quota.7d, with default templates prefixedFableso it can be told apart from the other quota items, which share its icon. The preview scenariosnormalandnear-fullinclude sample values.Tests
Config::shows.cargo fmt --check,cargo clippy --all-targets -- -D warnings,cargo test(207 passed).ccline usage-checkrecorded{"used_percentage":27.0,"resets_at":…}and the status line showed the item; a config withoutquota.fablecreates no state file and makes no request.Not tested on Linux or Windows; there it relies on
.credentials.jsonand curl being present.🤖 Generated with Claude Code
Summary by Sourcery
Expose the weekly Fable limit as an opt-in quota metric backed by cached OAuth usage data.
New Features:
quota.fablemetric to display the weekly Fable usage limit from Claude Code’s OAuth usage data.Enhancements:
Documentation:
Tests: