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_compress on 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_tool hook 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_ms mirroring pre_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.
Motivation
docs/HOOKS.mddocumentspre_toolas a gate (exit 0/2).post_toolcurrently fires for telemetry but cannot modify the tool result returned to the model. This blocks a large class of context-hygiene automations:mcp__headroom__headroom_compresson any tool output above a byte/line threshold.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>"}.post_tool_timeout_msmirroringpre_tool_timeout_ms.Alternatives considered
pre_tool— impossible, output does not exist yet.Related:
~/.jcode/preferred-tools.mdalready tells the model to compress big outputs, but nothing enforces it. Version: v0.84.0.