Skip to content

feat(economy): compress Agent/Task prompt at PreToolUse time#87

Merged
claudioemmanuel merged 1 commit intomainfrom
feat/agent-prompt-compression
Apr 22, 2026
Merged

feat(economy): compress Agent/Task prompt at PreToolUse time#87
claudioemmanuel merged 1 commit intomainfrom
feat/agent-prompt-compression

Conversation

@claudioemmanuel
Copy link
Copy Markdown
Owner

Summary

  • New squeez compress-prompt subcommand reads stdin, runs markdown compression via the existing compress_md pipeline (Ultra mode), and head-truncates with a notice if still over budget; echos unchanged when under the token budget
  • New agent_prompt_max_tokens config field (default 2000, 0 = disabled) with parser arm in Config::from_str and entry in the default config.ini written by squeez setup
  • hooks/pretooluse.sh: new Agent/Task branch pipes tool_input.prompt through squeez compress-prompt and replaces it only when the output is strictly shorter than the input
  • src/hosts/claude_code.rs: PreToolUse matcher extended from "Bash" to "Bash|Read|Grep|Glob|Agent|Task" so the new branch fires
  • tests/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 survive

Motivation

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 in test_compress_prompt.rs)
  • cargo build --release — binary builds clean, zero-dep constraint preserved
  • Manual: echo "# Plan\n\nshort" | squeez compress-prompt — echoes unchanged
  • Manual: pipe a 1500-line markdown file — output is shorter, heading structure preserved
  • After squeez setup: verify ~/.claude/settings.json PreToolUse matcher includes Agent|Task
  • Verify ~/.claude/squeez/config.ini contains agent_prompt_max_tokens = 2000

@claudioemmanuel claudioemmanuel force-pushed the feat/agent-prompt-compression branch from 1be6214 to 5b76ae1 Compare April 22, 2026 00:43
- 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
@claudioemmanuel claudioemmanuel force-pushed the feat/agent-prompt-compression branch from 5b76ae1 to ae3f38e Compare April 22, 2026 00:45
@claudioemmanuel claudioemmanuel merged commit b9dcd03 into main Apr 22, 2026
3 of 5 checks passed
@claudioemmanuel claudioemmanuel deleted the feat/agent-prompt-compression branch April 22, 2026 00:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant