claude-code - 💡(How to fix) Fix [FEATURE] Safe, Declarative Response Text Substitutions (Post-Render Transforms) [1 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#46407Fetched 2026-04-11 06:21:07
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
0
Author
Participants
Timeline (top)
labeled ×3
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

LLMs persistently use certain typographic patterns (em dashes, placeholder text like [Your Name], curly quotes) despite explicit instructions in CLAUDE.md and system prompts. These instructions are advisory and the model routinely ignores them. There is currently no deterministic way to clean up Claude Code's conversational/terminal output before it renders to the user.

Hooks solve this problem for file writes (PostToolUse on Write/Edit), but the chat response text has no equivalent interception point. Why a generic response-transform hook is dangerous An open-ended hook that lets users run arbitrary scripts on response text before rendering would effectively be a post-guardrail injection point. A malicious or careless script could strip safety refusals, rewrite disclaimers, or make Claude appear to say things it never generated. This would undermine Anthropic's safety architecture.

Proposed Solution

Instead of an arbitrary transform hook, provide a safe, declarative configuration for simple text replacements. Example in .claude/settings.json: json{ "responseSubstitutions": [ { "find": "\u2014", "replace": ", " }, { "find": "\u2013", "replace": "- " }, { "find": "[Your Name]", "replace": "Jay Chetty" }, { "find": "\u201c", "replace": """ }, { "find": "\u201d", "replace": """ } ] } Safety constraints Anthropic could enforce:

Plain string matching only (no regex, no scripts) Maximum replacement length cap (e.g., 100 characters) to prevent injecting large blocks of text Replacements cannot target or remove known safety-critical patterns (refusal phrases, warning prefixes) A short allowlist of substitution categories could further limit scope: typographic normalization, placeholder fill-in, locale formatting Substitutions are visible in settings and auditable

Alternative Solutions

CLAUDE.md instructions: Advisory only. The model ignores them unpredictably. PostToolUse hooks on file writes: Works for files but not chat output. A full response-transform hook: Too dangerous for the reasons described above.

Priority

Critical - Blocking my work

Feature Category

CLI commands and flags

Use Case Example

I'm a security architect using Claude Code to draft architecture documents, threat models, and technical proposals. My writing style strictly avoids em dashes. I have this rule in my CLAUDE.md, in my system prompt, and I've told the model directly in conversation. Despite all of this, roughly 1 in 3 responses still contain em dashes. Step-by-step scenario:

I ask Claude Code to draft a threat model section for an AI inference pipeline. Claude generates a solid technical response, but the chat output contains: The attestation service validates the TEE report — including the firmware measurement chain — before releasing decryption keys. I notice the em dashes, sigh, and manually ask Claude to rewrite without them. Claude rewrites. Two paragraphs later in the same response, there's another em dash. I copy the text out of the terminal into my document and do a manual find-and-replace. This cycle repeats across every session, every day.

With the proposed responseSubstitutions config, I would add { "find": "\u2014", "replace": ", " } once and never think about it again. The fix is deterministic, costs zero tokens, requires no re-prompting, and doesn't touch the model's actual generation or safety behavior. It's a cosmetic pass on the rendered output, the same thing I'm already doing by hand every single time. The same pattern applies to users who always have to fix [Your Name] placeholders, or teams that prefer straight quotes over curly quotes. These are all surface-level text preferences that prompt instructions cannot reliably enforce.

Additional Context

This is a small feature that solves a real and persistent pain point. The constrained design preserves Anthropic's safety guarantees while giving users deterministic control over surface-level formatting in chat responses.

extent analysis

TL;DR

Implement a declarative configuration for simple text replacements in the .claude/settings.json file to address the issue of LLMs ignoring explicit instructions regarding typographic patterns.

Guidance

  • Introduce a responseSubstitutions array in the .claude/settings.json file to define replacement rules for unwanted typographic patterns.
  • Enforce safety constraints such as plain string matching, maximum replacement length cap, and restrictions on targeting safety-critical patterns.
  • Limit the scope of substitutions to specific categories like typographic normalization, placeholder fill-in, and locale formatting.
  • Ensure that substitutions are visible in settings and auditable for transparency and security.

Example

{
  "responseSubstitutions": [
    { "find": "\u2014", "replace": ", " },
    { "find": "\u2013", "replace": "- " },
    { "find": "[Your Name]", "replace": "Jay Chetty" },
    { "find": "\u201c", "replace": "\"" },
    { "find": "\u201d", "replace": "\"" }
  ]
}

Notes

The proposed solution aims to balance user control over surface-level formatting with the need to preserve Anthropic's safety guarantees. By introducing a constrained and declarative configuration for text replacements, users can achieve deterministic control over unwanted typographic patterns without compromising the model's safety behavior.

Recommendation

Apply the proposed workaround by implementing the responseSubstitutions configuration in the .claude/settings.json file. This approach addresses the user's pain point while maintaining the safety and security of 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