[BUG] 2.1.300: api-request records bloat transcripts ~5x — unbounded prior_turn_context re-serialized every request (quadratic)
Version: 2.1.300 (regression vs 2.1.299) · Platform: Linux
2.1.300 writes a new api-request record per API call into session transcripts. These account for 79% of transcript bytes in tool-heavy sessions. Same workload, same repo, across ~28 consecutive sessions:
| version | api-request records | typical session size |
|---|---|---|
| 2.1.299 and earlier | 0 | 3–8 MB |
| 2.1.300 | 150–412 | 10–69 MB |
The cutover is exact — every session on 2.1.299 has zero such records, every session on 2.1.300 has them.
Root cause
The record logs the request params, correctly stripping messages (confirmed messages: 0 in every record). But one field is not stripped:
params.safeguards[0].classifier_context.prior_turn_context → 254 KB of the 266 KB record
prior_turn_context is a cumulative list holding one ~0.9 KB entry per tool call, and the entire list is re-serialized on every request. Growth is therefore quadratic in tool calls:
request #1 → 0 entries → 12.7 KB
request #151 → 107 entries → 101.5 KB
request #351 → 274 entries → 237.2 KB
(At request #401 the list drops to 159 entries, where context compaction trims it.)
Impact
- One 69 MB transcript contains only ~13 MB of actual conversation; 54.8 MB is this telemetry.
- Per-session disk use went from ~1 MB to ~6.2 MB average — 0.40 GB written in a single day vs 1.71 GB accumulated over the preceding months.
- Inflates the size shown in the
/resumepicker, making sessions appear far larger than their real content.
Expected
prior_turn_context should be windowed/truncated, or omitted from the on-disk log the same way messages already is.
Repro
Run a tool-heavy session on 2.1.300, then:
grep -c '"type":"api-request"' ~/.claude/projects/<project>/<session>.jsonl
To see the breakdown:
python3 -c '
import json,sys
tot=ptc=0
for line in open(sys.argv[1]):
o=json.loads(line)
if o.get("type")!="api-request": continue
tot+=len(line)
sg=o["params"].get("safeguards") or []
if sg: ptc+=len(json.dumps(sg[0]["classifier_context"].get("prior_turn_context",[])))
print("api-request bytes: %.1f MB, of which prior_turn_context: %.1f MB"%(tot/1e6,ptc/1e6))
' ~/.claude/projects/<project>/<session>.jsonl