claude-code - 💡(How to fix) Fix Allow `UserPromptSubmit` hooks to replace the user prompt [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#46761Fetched 2026-04-12 13:33:44
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Author
Timeline (top)
labeled ×3commented ×1
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing requests and this feature hasn't been requested yet
  • 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.

extent analysis

TL;DR

Add an updatedPrompt field to the UserPromptSubmit hook output to allow hooks to replace the prompt text before it is sent to the model.

Guidance

  • Review the UserPromptSubmit hook protocol to understand its current limitations and how adding an updatedPrompt field would address the issue.
  • Consider the PreToolUse hook as a reference, which already supports an updatedInput field to modify tool arguments before execution.
  • Evaluate the proposed solution in the context of the caveman-prompts library and its goal of compressing verbose prompts into token-efficient shorthand.
  • Assess the potential impact of adding this feature on the existing workflow and token costs.

Example

No code snippet is provided as the issue is focused on proposing a new feature rather than debugging existing code.

Notes

The proposed solution aims to provide a simple and efficient way to preprocess prompts before sending them to the model, which is currently not possible with the UserPromptSubmit hook. The alternative solutions presented have significant drawbacks, making this feature request a critical one.

Recommendation

Apply the proposed solution by adding an updatedPrompt field to the UserPromptSubmit hook output, as it directly addresses the issue and provides a straightforward way to replace the prompt text before it is sent to the model.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING