Feature: allow post_tool hook to transform tool output (not gate-only)
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 19.9k
- Forks
- 2.3k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 30
Description
Motivation
docs/HOOKS.md documents pre_tool as a gate (exit 0/2). post_tool currently fires for telemetry but cannot modify the tool result returned to the model. This blocks a large class of context-hygiene automations:
- Auto-invoking
mcp__headroom__headroom_compresson any tool output above a byte/line threshold. - Redacting secrets that leaked into command output.
- Truncating or summarizing verbose logs before they enter context.
Today the AGENTS.md "compress outputs > 2 KB" rule is prose-only. Users cannot enforce it mechanically, so per-session compression coverage is near zero even when the Headroom MCP is configured.
Proposed contract
post_toolhook may print a JSON envelope on stdout, e.g.{"replace_output": "..."}or{"replace_output_ref": "hr_<hash>"}.- Exit 0 with no stdout = pass-through (current behavior).
- Exit non-zero = fail-open with warning (matches current fail-open semantics).
- Add
post_tool_timeout_msmirroringpre_tool_timeout_ms.
Alternatives considered
- Doing it in
pre_tool— impossible, output does not exist yet. - Client-side hook in the harness — jcode is the harness.
- MCP proxy layer — would need to intercept every tool call type, not just MCP.
Related: ~/.jcode/preferred-tools.md already tells the model to compress big outputs, but nothing enforces it. Version: v0.84.0.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading docs/HOOKS.md and tracing the existing pre_tool hook and pre_tool_timeout_ms handling. Confirm the post_tool path can parse the proposed JSON envelope, preserve pass-through and fail-open behavior, and support a matching timeout; done means transformed output reaches the model without breaking existing telemetry.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- cli, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100