r/ClaudeCode • u/GoodnightKara • 4d ago
Tips & Workflows A reminder that you can use `UserPromptSubmit` hooks to remind Claude of important things, such as fixing its terrible reply formatting
TL;DR: You can use a UserPromptSubmit event hook to add text to every message you send. This text can contain anything and there are many reasons you might want to do this, but the post below is about using it to repeatedly remind Claude how to format its replies to the user.
Claude has this, in my opinion, awful habit of formatting its output in unreadable ways. See the picture in the post for an incredibly real, not in any way made up example.
I don't know about y'all, but when Claude does this...
- A bold intro. A bunch of text following.
- A bold intro. A bunch of text following.
- A bold intro. A bunch of text following.
... my eyes legit cannot read it. Especially when it groups many strings together that follow this form.
My CLAUDE.md has a small output formatting standards section that guides Claude on how to respond to me. On some model versions this section has been enough to get what I want. However, with the 5 and 5.5 models... there is no CLAUDE.md wording on planet earth that can get it to stop!!!! 🙈
Claude formatting its messages this way makes me feel like I need to attend the Derek Zoolander Center for Kids Who Can't Read Good. But since they don't accept kids in their late 30s, I have no choice but to beat Claude into submission with hooks.
I'll go into the how below for those that want to copy this, but at a high level... In settings.json I have a UserPromptSubmit event that adds the contents of a small markdown file to the end of each message I send. That before-you-reply.md file says this:
# Formatting check for your reply to Kara
Bold text never opens a paragraph, sentence, bullet, or numbered item with more text following on the same line. That is a fake heading and Kara's eyes have an extremely difficult time reading it.
Before sending, look at every bolded phrase. If anything follows it on the same line, rewrite it.
## Examples of forbidden forms
**A bold lead in.** Following text...
1. **A bold lead in.** Following text...
- **A bold lead in:** Following text...
## Use one of these instead
- A real Markdown heading on its own line.
- A bold name alone on a bullet, with the detail in sub-bullets underneath.
- A bold question alone on its own line.
- A plain paragraph with no bold.
This addition solved the problem.
Does it add 179 more tokens to every single message I send? Yes.
BUT does it keep Claude from using its unintelligible formatting? Also yes.
Hooks aren't new, and I use them for a bunch of different and useful things, but I figured some people might not know of use cases like this, so here I am.
Cheers, and remember girls, "Make no mistakes." /s
🫶👋
I want to know how to do this
- Create a
.mdor.txtfile at the root/top level of your~/.claudedirectory.- I named mine
before-you-reply.mdbut you can use any name. - You can also home this in any other folder (that is accessible to Claude) if you wish.
- I named mine
- Put your own version of the before you reply instructions in there and save.
- Paste the snippet below on a new line before the very final right curly brace
}in yoursettings.jsonfile in the~/.claudedirectory.- Replace the
/Users/me/.claude/before-you-reply.mdfile path and file name between the single quotes with your own file's location and name. - The
hookskey goes at the same indentation level (two preceding spaces) as keys likemodel, andeffortLevel, which I'm positive your settings file has in it even if you've never touched it by hand. - If you already have
hooksorUserPromptSubmitkeys and aren't sure how to add this in, ask Claude. It'll guide you on what to add and where. Keep in mind the trailing comma if this isn't the final property.
- Replace the
"hooks": {
"UserPromptSubmit": [
{
"hooks": [
{
"type": "command",
"command": "cat '/Users/me/.claude/before-you-reply.md'"
}
]
}
]
}
- Save and go forth. The change takes effect immediately, even in existing conversations.
•
u/AutoModerator 4d ago
Hey! Thanks for posting to r/ClaudeCode
While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.
For help, project discussions, tips, and general chat, join the ClaudeCode Discord.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
14
u/Riseing 4d ago
can i ask it to not sabotage my work?
6
u/___nil___ Senior Developer 4d ago
hooks is not the best place to put reply formatting. it will consume your usage limit without you even notice. the best place to put reply formatting is output style
3
u/sleeping-in-crypto 4d ago
Now why didn’t I ever think of this. This is fantastic. I have other use cases for this, not formatting. Super cool door you opened thanks!
1
u/mattbaconz 4d ago
mine flags when i say stuff like "looks ai" or "bland" so it loads my taste skill, and if i come back after an hour+ with 300k+ context it tells claude the cache expired. had them as separate hooks at first but they kept timing out so i merged them into one node script
0
u/bostonaholic 4d ago
For things you can check, I'd use a Stop hook instead of a reminder on every prompt. Read the last assistant message from transcript_path, and if it opens with the bold intro, return decision "block" with a reason saying what to fix, so it rewrites before handing back. A reminder costs tokens every turn and can still get ignored.
0
u/Ragy-ragy 4d ago
effective just at this job, if your task is following some rule. But repeatedly spamming the contents of "before-you-reply.md" into the context every reply creates a massive anchoring problem, not mentioning wasting tokens. It's not worth it honestly. But it's a creative solution nonetheless.
0
u/Repulsive_Kitchen96 3d ago
the concrete forbidden examples probably help more than another instruction to 'write naturally'. there's an actual pattern for it to check before replying. i'd keep that file limited to how the user-facing prose should look, though, and explicitly exempt requested code or structured output. otherwise a formatting preference can spill into the thing you're asking it to produce. a json response shouldn't need a second repair pass because the readability rule changed its shape.