Developer's Claude Code Cost Tracker Silently Logged $0 for 52 Days Due to Missing Payload Field
A solo developer building an automated Claude Code environment discovered that their token cost-tracking script had been silently recording zero values for 52 consecutive days across 2,340 logged rows. The error stemmed from a misunderstanding of Claude Code's Stop hook, which fires after every assistant response but does not include usage or model fields in its payload. Because the script attempted to read non-existent fields, it converted undefined values to NaN and ultimately logged $0.00 for every session without throwing any errors. The Stop hook payload contains only four fields — session_id, transcript_path, cwd, and hook_event_name — a detail not clearly documented, making the silent failure easy to miss. The correct approach, the developer explains, is to follow the transcript_path pointer and extract token usage data directly from the session transcript file.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in