From 79c5e4ba091cf92d47ac0131c85f6b7c48c0153d Mon Sep 17 00:00:00 2001 From: arkon Date: Mon, 19 Jan 2026 04:45:51 +0100 Subject: [PATCH] docs: update token tracking documentation - Document different token tracking approaches for one-shot vs interactive modes - Update PTY spawn mode examples to show --output-format stream-json flag - Explain that interactive mode parses tokens from status line with 60/40 split estimate Co-Authored-By: Claude Opus 4.5 --- CLAUDE.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index e4ef93cb..d97647c4 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -111,12 +111,12 @@ const msg = JSON.parse(cleanLine) as ClaudeMessage; ### PTY Spawn Modes -**One-shot mode** (prompt execution): +**One-shot mode** (prompt execution with JSON output for token tracking): ```typescript -pty.spawn('claude', ['-p', '--dangerously-skip-permissions', prompt], { ... }) +pty.spawn('claude', ['-p', '--dangerously-skip-permissions', '--output-format', 'stream-json', prompt], { ... }) ``` -**Interactive mode** (persistent terminal): +**Interactive mode** (persistent terminal, tokens parsed from status line): ```typescript pty.spawn('claude', ['--dangerously-skip-permissions'], { ... }) ``` @@ -168,7 +168,11 @@ Default config (`RespawnConfig` in `src/types.ts`): ### Token Tracking & Auto-Clear -Session tracks input/output tokens from Claude's JSON messages: +Session tracks input/output tokens differently depending on mode: + +**One-shot mode (`runPrompt`)**: Uses `--output-format stream-json` to get JSON output with detailed token usage from `msg.message.usage.input_tokens` and `output_tokens`. + +**Interactive mode (`startInteractive`)**: Parses tokens from Claude's status line display (e.g., "123.4k tokens"). Since only total is shown, estimates 60/40 input/output split. ```typescript {