Skip to content

feat(usage_limits): per-window session/weekly tokens and a {bar} placeholder - #202

Merged
stephenleo merged 1 commit into
stephenleo:mainfrom
nh13:nh13/feat-usage-limits-per-period
Sep 6, 2026
Merged

feat(usage_limits): per-window session/weekly tokens and a {bar} placeholder#202
stephenleo merged 1 commit into
stephenleo:mainfrom
nh13:nh13/feat-usage-limits-per-period

Conversation

@nh13

@nh13 nh13 commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Adds two capabilities to [cship.usage_limits], both opt-in and backward-compatible.

Per-window tokens

$cship.usage_limits.session and $cship.usage_limits.weekly (aliases .five_hour / .seven_day) render a single standard window, colored by that window's own utilization — unlike $cship.usage_limits, whose threshold color keys off max(5h, 7d). This lets the session and weekly limits sit on separate lines and escalate (green → yellow → red) independently.

{bar} placeholder

A proportional Unicode bar usable in five_hour_format / seven_day_format, with bar_width, bar_filled_char, and bar_empty_char config (mirrors context_bar's fill math). It is scoped to the per-window formats only — the per-model and extra-usage formats leave {bar} literal. Combined with the per-window tokens, each window can show its own progress bar:

[cship]
lines = ["$cship.usage_limits.session", "$cship.usage_limits.weekly"]

[cship.usage_limits]
five_hour_format   = "5h {bar} {pct}%"
seven_day_format   = "7d {bar} {pct}%"
bar_width          = 20
warn_threshold     = 50
warn_style         = "yellow"
critical_threshold = 80
critical_style     = "bold red"

Notes

  • Default $cship.usage_limits output is unchanged — the shared per-window formatter produces byte-identical text when no {bar} is present, and show_per_model / extra-usage / separator handling is preserved.
  • bar_width is clamped to a sane maximum, and the bar string is built only when {bar} is actually referenced.
  • render_bar is kept local with a "keep in sync" note rather than refactoring context_bar in this feature PR — happy to extract a shared helper if you'd prefer.
  • cship explain reports the per-window tokens as plan-unavailable on Enterprise (alongside the per-model sub-tokens) instead of a misleading fetch-failure hint.

Docs & tests

docs/configuration.md, docs/faq.md, README.md, and the committed config-schema.json are updated. New unit tests cover bar rendering (incl. 0-width, clamping, floor semantics), placeholder substitution, the {bar} negative scope in per-model/extra formats, independent per-window coloring, and the aliases. cargo fmt, clippy --all-targets (0 warnings), and the full suite pass.

…older

Add $cship.usage_limits.session and .weekly tokens (aliases .five_hour /
.seven_day) that render a single standard window colored by that window's
own utilization, rather than max(5h, 7d) as $cship.usage_limits does. This
lets the session and weekly limits live on separate lines and escalate
independently.

Add a {bar} placeholder to the per-window format strings, plus bar_width /
bar_filled_char / bar_empty_char config, so each window can show its own
proportional Unicode progress bar (mirroring context_bar).

Docs, JSON schema, and README updated; unit tests cover bar rendering,
placeholder substitution, independent per-window coloring, and aliases.
@jarcec

jarcec commented Aug 31, 2026

Copy link
Copy Markdown

I'm really missing having a bar in the usage limits - I was even considering about looking into adding this same feature myself and I'm really glad that someone already done that :)

@stephenleo

Copy link
Copy Markdown
Owner

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

@stephenleo
stephenleo merged commit 934d1ab into stephenleo:main Sep 6, 2026
3 checks passed
@stephenleo stephenleo mentioned this pull request Sep 6, 2026
stephenleo added a commit that referenced this pull request Sep 6, 2026
Bumps to 1.8.2 and adds the changelog entries for the per-window
usage_limits tokens with {bar} (#202), the CSHIP_ACCOUNT account source
(#201), and the CSHIP_ACCOUNT explain-hint fix (#204).

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants