Repository navigation
feat(usage): Claude Code's plan limits, signed-out logins, team seats, and boxes with no projects #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tinhthanh
wants to merge
3
commits into
cosscom:main
Choose a base branch
from
tinhthanh:feat/usage-claude-limits-upstream
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat(usage): Claude Code's plan limits, signed-out logins, team seats, and boxes with no projects #115
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
70c2515
feat(usage): plan limits from claude code's own /usage, signed-out lo…
tinhthanh 4900d8b
fix(usage): address review: exec without a location only on a box wit…
tinhthanh 8c65467
fix(usage): a lock it can't make doesn't cost the limits, and exec ch…
tinhthanh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // node --experimental-strip-types --test src/lib/usage-limits.test.ts (pnpm test) | ||
| import assert from "node:assert/strict"; | ||
| import { test } from "node:test"; | ||
|
|
||
| import type { Account, Limits, Report } from "../../../plugins/usage/src/box.ts"; | ||
| import { dedupeLimits, type Source } from "../../../plugins/usage/src/data.ts"; | ||
|
|
||
| const win = { used_percent: 10, window_minutes: 300, resets_at: 2_000_000_000 }; | ||
| const limits = (account: string, at: string, org?: string): Limits => ({ agent: "claude", account, at, ...(org ? { org } : {}), limits: { primary: win, secondary: null } }); | ||
| const report = (l: Limits[]): Report => ({ generated: "", days: 7, since: "2026-10-08", today: "2026-10-14", tz: "+00", partial: false, pending: 0, files: 0, daily: [], sessions: [], limits: l }); | ||
| const source = (box: string, l: Limits[]) => ({ box, report: report(l) }) as unknown as Source; | ||
| const account = (id: string, email: string): Account => ({ agent: "claude", id, email }) as Account; | ||
|
|
||
| test("one email signed in to two plans shows both on the Usage screen, each named by its account", () => { | ||
| const accounts = { devl: [account("ana-team", "ana@acme.test"), account("ana-max", "ana@acme.test")] }; | ||
| const got = dedupeLimits("claude", [source("devl", [limits("ana-team", "2026-10-14T10:00:00Z", "o-team"), limits("ana-max", "2026-10-14T10:00:00Z", "o-max")])], accounts, 7); | ||
| assert.deepEqual(got.map((l) => l.label).sort(), ["ana@acme.test · ana-max", "ana@acme.test · ana-team"]); | ||
| assert.equal(new Set(got.map((l) => l.key)).size, 2); | ||
| }); | ||
|
|
||
| test("one login read on two boxes is one row, as most recently read", () => { | ||
| const accounts = { devl: [account("default", "bo@acme.test")], gpu: [account("default", "bo@acme.test")] }; | ||
| const got = dedupeLimits("claude", [source("devl", [limits("default", "2026-10-14T10:00:00Z", "o-1")]), source("gpu", [limits("default", "2026-10-14T11:00:00Z", "o-1")])], accounts, 7); | ||
| assert.equal(got.length, 1); | ||
| assert.deepEqual(got[0].boxes, ["devl", "gpu"]); | ||
| assert.equal(got[0].limits.at, "2026-10-14T11:00:00Z"); | ||
| // One login needs no name. | ||
| assert.equal(got[0].label, undefined); | ||
| }); | ||
|
|
||
| test("two plans of one email, each the default login of its own box, are told apart by box", () => { | ||
| const accounts = { devl: [account("default", "ana@acme.test")], gpu: [account("default", "ana@acme.test")] }; | ||
| const got = dedupeLimits("claude", [source("devl", [limits("default", "2026-10-14T10:00:00Z", "o-team")]), source("gpu", [limits("default", "2026-10-14T10:00:00Z", "o-max")])], accounts, 7); | ||
| assert.deepEqual(got.map((l) => l.label).sort(), ["ana@acme.test · default (devl)", "ana@acme.test · default (gpu)"]); | ||
| }); | ||
|
|
||
| test("a box that listed no accounts still has its login named by the report's email", () => { | ||
| const read = (at: string): Limits => ({ ...limits("default", at, "o-1"), email: "bo@acme.test" }); | ||
| const got = dedupeLimits("claude", [source("devl", [read("2026-10-14T10:00:00Z")]), source("gpu", [read("2026-10-14T11:00:00Z")])], {}, 7); | ||
| assert.equal(got.length, 1); | ||
| assert.deepEqual(got[0].boxes, ["devl", "gpu"]); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // node --experimental-strip-types --test src/lib/usage-plan.test.ts (pnpm test) | ||
| import assert from "node:assert/strict"; | ||
| import { test } from "node:test"; | ||
|
|
||
| import type { Account } from "../../../plugins/usage/src/box.ts"; | ||
| import { plan } from "../../../plugins/usage/src/data.ts"; | ||
|
|
||
| const claude = (over: Partial<Account>): Account => ({ agent: "claude", id: "x", dir: "/x", exists: true, signed_in: true, billing: "stripe_subscription", ...over }) as Account; | ||
|
|
||
| test("a team seat is named by its organization, not the Max-like tier it records", () => { | ||
| assert.equal(plan(claude({ tier: "default_claude_max_5x", org_type: "claude_team" }))?.label, "Claude Team"); | ||
| assert.equal(plan(claude({ tier: "default_claude_max_5x", org_type: "claude_enterprise" }))?.label, "Claude Enterprise"); | ||
| }); | ||
|
|
||
| test("a personal plan is named by its tier", () => { | ||
| assert.equal(plan(claude({ tier: "default_claude_max_20x", org_type: "claude_max" }))?.label, "Claude Max 20x"); | ||
| assert.equal(plan(claude({ tier: "default_claude_max_5x" }))?.label, "Claude Max 5x"); | ||
| assert.equal(plan(claude({ tier: "default_claude_pro", org_type: "claude_pro" }))?.label, "Claude Pro"); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // node --experimental-strip-types --test src/lib/usage-py.test.ts (pnpm test) | ||
| // Runs usage.py's own tests (plugins/usage/box/usage_test.py) in the app's | ||
| // test run, so the box-side script is checked where CI checks everything else. | ||
| import assert from "node:assert/strict"; | ||
| import { spawnSync } from "node:child_process"; | ||
| import { dirname, join } from "node:path"; | ||
| import { test } from "node:test"; | ||
| import { fileURLToPath } from "node:url"; | ||
|
|
||
| const box = join(dirname(fileURLToPath(import.meta.url)), "..", "..", "..", "plugins", "usage", "box"); | ||
| const python = spawnSync("python3", ["--version"]).status === 0; | ||
|
|
||
| test("usage.py reads Claude Code's /usage", { skip: !python && "no python3" }, () => { | ||
| // A hung run fails the test rather than holding up the whole suite. | ||
| const r = spawnSync("python3", ["-m", "unittest", "-q", "usage_test.py"], { cwd: box, encoding: "utf8", timeout: 120_000 }); | ||
| assert.equal(r.status, 0, r.stderr || r.stdout); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.