|
| 1 | +# Session Token Scan |
| 2 | + |
| 3 | +`tools/session-token-scan/scan.py` is a deterministic, read-only scanner for |
| 4 | +Every Code rollout/session files. It highlights token-efficiency suspects before |
| 5 | +prompt, memory, agent, or history behavior is changed. |
| 6 | + |
| 7 | +The scanner does not call an LLM. Optional local or cheaper model classifiers |
| 8 | +should be layered on later and should consume only the compact scanner output or |
| 9 | +narrowed suspect spans, not whole raw rollout files. |
| 10 | + |
| 11 | +## Run |
| 12 | + |
| 13 | +```sh |
| 14 | +python3 tools/session-token-scan/scan.py ~/.code/sessions/2026/05/11 --limit 20 |
| 15 | +``` |
| 16 | + |
| 17 | +Useful options: |
| 18 | + |
| 19 | +- `--limit 0`: scan all discovered rollout files under the inputs. |
| 20 | +- `--json`: emit machine-readable output for PR evidence or later classifiers. |
| 21 | +- `--usage-root ~/.code/usage`: correlate timestamped usage entries when |
| 22 | + available. |
| 23 | +- `--large-threshold 16384`: set the byte threshold for large-record suspects. |
| 24 | + |
| 25 | +## Reports |
| 26 | + |
| 27 | +The text report includes: |
| 28 | + |
| 29 | +- peak cumulative and largest single-turn token usage |
| 30 | +- cache ratio from recorded token counts |
| 31 | +- token total reset counts when cumulative counters restart inside a rollout |
| 32 | +- rollout file size, image payload bytes, and base-instruction size |
| 33 | +- duplicated project-doc/skill injection flags |
| 34 | +- largest token-count events |
| 35 | +- largest persisted records and string fields |
| 36 | +- `data:image` and `input_image` suspects |
| 37 | +- optional usage-entry totals that overlap the session timestamp range |
| 38 | + |
| 39 | +## Scope |
| 40 | + |
| 41 | +This tool reads local files only. It does not mutate session history, enforce |
| 42 | +budgets, change model routing, or compact stored payloads. |
0 commit comments