Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(plan-usage): read the Claude Code login only when an instance opts in

heimixieb7e16fe14baf1
diff --git a/server/plan-usage.test.ts b/server/plan-usage.test.ts
index 7ef62da29e..7980465452 100644
--- a/server/plan-usage.test.ts
+++ b/server/plan-usage.test.ts
@@ -489,7 +489,7 @@ describe("plan usage fetcher", () => {
it("lists configured Claude, Codex, and Grok accounts and skips other engines", () => {
expect(planAccountsFromInstances({
- claude: { driver: "claudeAgent", displayName: " Personal Claude ", config: { configDir: "/tmp/claude" } },
+ claude: { driver: "claudeAgent", displayName: " Personal Claude ", config: { configDir: "/tmp/claude", usageMeter: true } },
codex: { driver: "codex" },
grok: { driver: "grokAgent", environment: { GROK_HOME: "/tmp/grok" } },
cursor: { driver: "cursorAgent", displayName: "Cursor" },
@@ -614,4 +614,20 @@ describe("plan usage fetcher", () => {
expect(fetchImpl).toHaveBeenCalledTimes(1);
expect(report.providers.map((row) => row.id)).toEqual(["codex"]);
});
+
+ it("reads no Claude login unless the instance turns its usage meter on", async () => {
+ const accounts = planAccountsFromInstances({
+ claude: { driver: "claudeAgent" },
+ metered: { driver: "claudeAgent", displayName: "Metered", config: { usageMeter: true } },
+ });
+ expect(accounts).toEqual([
+ { id: "claude", name: "Claude", driver: "claude", environment: {}, noUsage: true },
+ { id: "metered", name: "Metered", driver: "claude", environment: {} },
+ ]);
+ const read = vi.fn((_account: PlanAccount) => ({ token: SECRET, accountId: null, expired: false }));
+ const fetchImpl = vi.fn<PlanFetch>(async () => jsonResponse({}));
+ const report = await fetchPlanUsage(accounts, { fetch: fetchImpl, now: () => NOW, credentials: { read } });
+ expect(read.mock.calls.map(([account]) => account.id)).toEqual(["metered"]);
+ expect(report.providers.map((row) => row.id)).toEqual(["metered"]);
+ });
});
diff --git a/server/plan-usage.ts b/server/plan-usage.ts
index 648bad6b0f..3582577322 100644
--- a/server/plan-usage.ts
+++ b/server/plan-usage.ts
@@ -72,7 +72,7 @@ export interface PlanAccount {
driver: PlanDriver;
environment: Record<string, string | undefined>;
configDir?: string;
- /** Signed in through OpenMausBot (ChatGPT plan), not a CLI login on disk, so it has no usage reading. */
+ /** No usage reading: a ChatGPT plan signed in through OpenMausBot has no CLI login on disk, and a Claude login is read only when its instance sets `usageMeter: true`, since Anthropic's credential policy covers that token for Claude Code alone (a refused turn still fails over). */
noUsage?: true;
}
@@ -164,7 +164,7 @@ export function planAccountsFromInstances(instances: InstanceConfigMap): PlanAcc
environment: { ...entry.environment },
...(configDir ? { configDir } : {}),
// Reading ~/.codex/auth.json for a ChatGPT-plan provider would report (and hold it on) another account's limit.
- ...(config?.authMode === "chatgpt-plan" ? { noUsage: true as const } : {}),
+ ...(config?.authMode === "chatgpt-plan" || (driver === "claude" && config?.usageMeter !== true) ? { noUsage: true as const } : {}),
});
}
return accounts;