Allow `UserPromptSubmit` hooks to replace the user prompt

Resolved 💬 3 comments Opened Apr 11, 2026 by nirmorgo Closed Apr 15, 2026

Preflight Checklist

  • [x] I have searched existing requests and this feature hasn't been requested yet
  • [x] This is a single feature request (not multiple features)

Problem Statement

I am building caveman prompts, a Python library that compresses verbose prompts into token-efficient shorthand before sending them to Claude — saving 30–55% on input tokens with no meaningful loss of intent.

The UserPromptSubmit hook is the natural integration point for this. However, the current hook protocol only supports:

  • Pass-through (no modification)
  • additionalContext (appends to the prompt — this doubles token costs instead of reducing them)

Proposed Solution

Add a updatedPrompt (or modifiedPrompt) field to the UserPromptSubmit hook output so hooks can replace the prompt text before it is sent to the model, rather than only appending context alongside it.

Alternative Solutions

Pipe mode (caveman "your prompt" | claude -p) — works but is manual, single-turn only, and breaks interactive sessions entirely.
Shell wrapper (cc() { claude -p "$(echo "$*" | caveman)"; }) — only compresses the initial prompt, not follow-up messages in a session.
Localhost proxy server — intercepts all API traffic at the network level and replaces message content before forwarding to Anthropic. Technically works but requires a persistent background process, introduces a new failure point for every Claude Code session, and creates unnecessary security exposure since all API traffic (including keys) routes through it.
additionalContext via current hook — tried this first. It sends both the original and compressed prompt to the model simultaneously, doubling token costs instead of reducing them.
None of these are acceptable as a long-term solution for what should be a simple one-line preprocessing step.

Priority

Critical - Blocking my work

Feature Category

Other

Use Case Example

  1. I'm working on a large React/Node.js codebase and use Claude Code heavily throughout the day
  2. I type verbose prompts like "Can you please refactor this function so that it handles errors properly and add some inline comments to explain what it does?"
  3. With a UserPromptSubmit hook that can replace the prompt, caveman-prompts would silently compress this to "refactor fn handle errs add comments" before it hits the model
  4. This saves ~50% of input tokens on every single prompt, across every session, with zero change to my workflow

Additional Context

I built caveman-prompts specifically for this use case — a Python library that compresses verbose prompts into token-efficient shorthand using NLP (spaCy), saving 30–55% on input tokens.

When I tried to integrate it via UserPromptSubmit, I discovered the hook only supports additionalContext, which appends the compressed prompt alongside the original — doubling costs instead of reducing them.

The PreToolUse hook already supports updatedInput to modify tool arguments before execution. This request simply extends that same pattern to UserPromptSubmit.

Without this, the only transparent alternative is a localhost proxy server, which introduces security concerns, infrastructure overhead, and a persistent background process — all disproportionate for what should be a simple preprocessing step.

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗