mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-12-05 16:07:33 +00:00
FilterThinkingBlocks runs on every Anthropic forward. Its substring fast path matches any request with top-level thinking config or signed thinking history, which is nearly all Claude Code traffic, so it decoded the whole body into a map even when nothing would be filtered. Mirror the filter decision on borrowed gjson views, applying encoding/json's last-wins rule for duplicate keys, and return the body untouched when no block would be dropped. Bodies that need filtering still take the original decode and marshal path, so output bytes are unchanged; a differential test and fuzz target compare both paths. On a 450 KB signed history: 1.29 ms, 904 KB, 10,629 allocs -> 0.67 ms, 0 B. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>