r/ClaudeCode • u/GoodnightKara • 8d 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.
