oc_chat
Loading...
Searching...
No Matches
cc_thinking_report Namespace Reference

Functions

dict session_stats (Path jsonl_path)
int main (list[str] argv)

Variables

str CLAUDE_PROJECTS = Path.home() / ".claude" / "projects"

Detailed Description

Per-session Claude Code token report WITH an estimated-thinking column.

The CCAssist dashboard (and the session files themselves) expose only the four
API usage fields: ``input_tokens``, ``output_tokens``,
``cache_creation_input_tokens``, ``cache_read_input_tokens``. Extended-thinking
tokens are billed INSIDE ``output_tokens`` and are recorded in no separate
field, so no subtraction of listed columns can recover them. This tool derives
the missing column with the residual method, verified empirically 2026-07-09
(session ``4f696339``: turns with ``output_tokens=39,365`` carrying only ~16k
tokens of visible text -> ~23k thinking; session-wide thinking ~= 83% of
output):

    thinking(turn) ~= output_tokens - visible_chars/4        (floored at 0)

Two correctness details the naive approach gets wrong:

1. **Stream dedup.** Streamed assistant turns are appended to the session file
   repeatedly with cumulative usage snapshots; summing every usage block
   over-counts ~2.6x. We dedupe by ``message.id``, keeping the max
   ``output_tokens`` snapshot and the max visible-content length per turn.
2. **Visible content** = text blocks + serialized ``tool_use`` inputs (both are
   billed output); thinking blocks are excluded (that is the point).

Usage:
    python tools/cc_thinking_report.py                # all projects
    python tools/cc_thinking_report.py <project-dir>  # one project dir name
                                                      # (e.g. g--PythonApps-OC-Chat)

Output: one row per session file (newest first) + a grand-total row.
Estimates are ~4 chars/token heuristics — a reporting aid, not billing truth.

Origin: operator question 2026-07-09 ("does total - sum(parts) give thinking?"
-- it cannot; this derives the real number). Kept as a reusable monitor.

Function Documentation

◆ main()

int cc_thinking_report.main ( list[str] argv)

Definition at line 95 of file cc_thinking_report.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ session_stats()

dict cc_thinking_report.session_stats ( Path jsonl_path)
Dedupe-by-message-id usage sums + residual thinking estimate.

Definition at line 46 of file cc_thinking_report.py.

Here is the caller graph for this function:

Variable Documentation

◆ CLAUDE_PROJECTS

str cc_thinking_report.CLAUDE_PROJECTS = Path.home() / ".claude" / "projects"

Definition at line 43 of file cc_thinking_report.py.