@juspay/neurolink
Version:
The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002
26 lines (25 loc) • 1.44 kB
TypeScript
/**
* Reads token usage out of Claude Code's own session transcripts.
*
* Layout, confirmed on a real machine rather than from documentation:
* `~/.claude/projects/<sanitized-cwd>/<sessionId>.jsonl`, where the sanitized
* cwd is the absolute working-directory path with every `/` replaced by `-`.
*
* The load-bearing detail is that top-level session transcripts are a tiny
* minority of the files. On the machine this was written against, 17,439
* transcripts totalling 9.7 GB broke down as roughly 103 top-level sessions
* against 17,116 subagent-task transcripts nested under
* `<sessionId>/subagents/`. A reader that globbed only `<project>/*.jsonl`
* would miss essentially all of a subagent-heavy user's real spend, so this
* one recurses.
*
* The files are not homogeneous message streams. A single 14,747-line
* transcript carried eleven distinct `type` values — `assistant`, `user`,
* `attachment`, `pr-link`, `last-prompt`, `mode`, `permission-mode`,
* `queue-operation`, `system`, `file-history-delta`, `file-history-snapshot` —
* several of which have no `message` key at all. Every one of its 6,028
* `type: "assistant"` lines carried a `message.usage` object, so that filter is
* safe, but everything else must be skipped rather than treated as malformed.
*/
import type { LocalUsageReader } from "../types/index.js";
export declare function createClaudeCodeReader(): Promise<LocalUsageReader>;