{"record":{"id":"28c99a3becae40f2","repo":"paperclipai/paperclip","slug":"could-not-parse-claude-cli-usage-output","errorCode":null,"errorMessage":"Could not parse Claude CLI usage output.","messagePattern":"Could not parse Claude CLI usage output\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/adapters/claude-local/src/server/quota.ts","lineNumber":422,"sourceCode":"      continue;\n    }\n    if (current) current.lines.push(line);\n  }\n  if (current) sections.push(current);\n\n  const windows = sections.map<QuotaWindow>((section) => {\n    const usedPercent = section.lines.map(percentFromLine).find((value) => value != null) ?? null;\n    return {\n      label: section.label,\n      usedPercent,\n      resetsAt: null,\n      valueLabel: null,\n      detail: formatClaudeCliDetail(section.label, section.lines),\n    };\n  });\n\n  if (!windows.some((window) => normalizeForLabelSearch(window.label) === \"currentsession\")) {\n    throw new Error(\"Could not parse Claude CLI usage output.\");\n  }\n  return windows;\n}\n\nfunction quoteForShell(value: string): string {\n  return `'${value.replace(/'/g, `'\\\\''`)}'`;\n}\n\nfunction buildClaudeCliShellProbeCommand(): string {\n  const feed = \"(sleep 2; printf '/usage\\\\r'; sleep 6; printf '\\\\033'; sleep 1; printf '\\\\003')\";\n  const claudeCommand = \"claude --tools \\\"\\\"\";\n  if (process.platform === \"darwin\") {\n    return `${feed} | script -q /dev/null ${claudeCommand}`;\n  }\n  return `${feed} | script -q -e -f -c ${quoteForShell(claudeCommand)} /dev/null`;\n}\n\nexport async function captureClaudeCliUsageText(timeoutMs = 12_000): Promise<string> {","sourceCodeStart":404,"sourceCodeEnd":440,"githubUrl":"https://github.com/paperclipai/paperclip/blob/67001ec6eb96ae601aa27bc91d9b2415d665334a/packages/adapters/claude-local/src/server/quota.ts#L404-L440","documentation":"Thrown by parseClaudeCliUsageText when the parsed usage sections do not include one whose normalized label equals 'currentsession'. The parser splits the captured Claude CLI /usage output into labeled sections; the 'current session' window is mandatory, so its absence means the output did not contain the expected usage panel and cannot be reported as valid quota data.","triggerScenarios":"captureClaudeCliUsageText returned output that usageOutputLooksComplete accepted (it passed the loose completeness check), but the section parser found no 'current session' label. Happens when the CLI rendered a partial or differently-formatted usage panel, or when label text changed in a new Claude CLI version.","commonSituations":"A Claude CLI version that renamed/restructured the usage panel labels; ANSI/terminal cleanup stripping label text; output from a non-interactive locale that changes 'current session' wording; a partial render that fooled usageOutputLooksComplete.","solutions":["Upgrade or pin a Claude CLI version known to render the 'current session' usage label; check `claude --version`.","Capture raw output with --raw-cli (quota-probe) and inspect the actual label text to see what changed.","Run `claude` interactively and issue /usage to confirm the panel renders as expected on this host.","If the label legitimately changed, the parser's canonicalQuotaLabel mapping needs updating upstream."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const windows = parseClaudeCliUsageText(rawText);\n} catch (err) {\n  if (err.message === \"Could not parse Claude CLI usage output.\") {\n    // log rawText for diagnosis, fall back to OAuth quota, do not crash the run\n  }\n  throw err;\n}","preventionTips":["Pin a Claude CLI version whose /usage panel is known-good.","Capture --raw-cli output in monitoring so label drift is visible.","Treat CLI quota parsing as best-effort with an OAuth fallback."],"tags":["claude","cli","quota","parsing","version-compat"],"backgroundTag":null,"analyzedSha":"67001ec6eb96ae601aa27bc91d9b2415d665334a","analyzedAt":"2026-08-12T12:05:45.408Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}