Skip to content

Feature: allow post_tool hook to transform tool output (not gate-only) #1241

Description

@compulsivedev

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    autonomous: noNeeds your brain: a product/design decision is required before anyone acts.enhancementNew feature or requesttriage: needs-decisionNeeds maintainer decision/design thought

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions