Expand RTK beyond PreToolUse — add PostToolUse hooks to optimize MCP tool outputs with TOON encoding #2510
gauravsagar483
started this conversation in
Ideas
Replies: 1 comment
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Problem
RTK today only intercepts before execution (
PreToolUse) — rewritinggit status→rtk git status. This works great for Bash or similar cli commands, but completely misses MCP tool outputs or API responses.In a long-running agent session, hundreds of MCP calls return raw JSON (search results, query outputs, API responses) that flow into the LLM context unoptimized. This is arguably a bigger token sink than Bash output.
Proposal
Add
PostToolUsehook support to RTK. After any tool executes, RTK intercepts the response and applies:Config-driven, per-tool:
Bonus: catches what PreToolUse can't
Claude Code's built-in tools (
Read,Grep,Glob) bypass the Bash hook entirely. APostToolUsehook would catch these too — same filtering logic, unified pipeline.Summary
RTK's
PreToolUsehooks solved token optimization for shell commands.PostToolUsehooks would solve it for everything else — MCP tools, built-in agent tools, API responses — using the same filtering intelligence RTK already has, with TOON as the default compact encoding.The combination of RTK's filtering + TOON encoding in a
PostToolUsehook could save 85%+ tokens on structured tool outputs across hundreds of MCP calls in a long-running agent session.Would love to hear thoughts from the maintainers and community on feasibility, especially around agent hook support for
PostToolUse.Config-driven per-tool rules
What the LLM actually sees
before:
{"hotels":[{"id":1,"name":"Grand Hotel","price":250,"rating":4.5,"currency":"USD","city":"Paris","stars":5,"reviewCount":1823,"checkIn":"15:00","checkOut":"11:00","cancellation":"free","provider":"expedia","lastUpdated":"2026-06-19T08:00:00Z"},{"id":2,"name":"City Inn","price":180,"rating":4.2,"currency":"USD","city":"Paris","stars":4,"reviewCount":945,"checkIn":"14:00","checkOut":"12:00","cancellation":"non-refundable","provider":"expedia","lastUpdated":"2026-06-19T08:00:00Z"}]}After:
~40% savings on just 2 rows.
That's the same data the LLM needs to make decisions — at a fraction of the token cost.
RTK already has the filtering engine, the tracking infrastructure, the hook system, and the agent integrations. PostToolUse is the natural extension.
Token Savings Estimate
Based on TOON benchmarks (~40% savings on uniform arrays) combined with RTK's field filtering (~50–80% noise removal):
I can contribute to this if you people approve the idea.
Thanks!!
All reactions