feat(economy): compress Agent/Task prompt at PreToolUse time#87
Merged
claudioemmanuel merged 1 commit intomainfrom Apr 22, 2026
Merged
feat(economy): compress Agent/Task prompt at PreToolUse time#87claudioemmanuel merged 1 commit intomainfrom
claudioemmanuel merged 1 commit intomainfrom
Conversation
1be6214 to
5b76ae1
Compare
- Add `agent_prompt_max_tokens` config field (default 2000, 0=disabled) - New `squeez compress-prompt` subcommand: reads stdin, runs markdown compression via compress_md, head-truncates with notice if still over budget; echos unchanged when under budget - Hook pretooluse.sh: intercept Agent/Task tools, pipe prompt through compress-prompt, replace only when output is shorter than input - Extend PreToolUse matcher to Bash|Read|Grep|Glob|Agent|Task so the Agent/Task branch fires correctly - Integration test: short prompt passes through verbatim; large markdown prompt shrinks and retains key headings
5b76ae1 to
ae3f38e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
squeez compress-promptsubcommand reads stdin, runs markdown compression via the existingcompress_mdpipeline (Ultra mode), and head-truncates with a notice if still over budget; echos unchanged when under the token budgetagent_prompt_max_tokensconfig field (default2000,0= disabled) with parser arm inConfig::from_strand entry in the defaultconfig.iniwritten bysqueez setuphooks/pretooluse.sh: new Agent/Task branch pipestool_input.promptthroughsqueez compress-promptand replaces it only when the output is strictly shorter than the inputsrc/hosts/claude_code.rs: PreToolUse matcher extended from"Bash"to"Bash|Read|Grep|Glob|Agent|Task"so the new branch firestests/test_compress_prompt.rs: integration test spawns the debug binary; asserts short prompt echoes verbatim, large markdown prompt is shorter than input, and key headings surviveMotivation
In observed production sessions a single plan.md (1,754 lines, ~7,000+ tokens) was injected verbatim into every Agent/Task spawn. With multiple agent invocations per session this compounds quickly. squeez already compresses Bash output and Read/Grep/Glob inputs; this PR closes the gap for the prompt field, which is the single largest uncompressed input vector for multi-agent workflows.
Test plan
cargo test— all tests pass (162 unit + 3 new integration intest_compress_prompt.rs)cargo build --release— binary builds clean, zero-dep constraint preservedecho "# Plan\n\nshort" | squeez compress-prompt— echoes unchangedsqueez setup: verify~/.claude/settings.jsonPreToolUse matcher includesAgent|Task~/.claude/squeez/config.inicontainsagent_prompt_max_tokens = 2000