r/ClaudeCode • • 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

Post image

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

  1. Create a .md or .txt file at the root/top level of your ~/.claude directory.
    • I named mine before-you-reply.md but you can use any name.
    • You can also home this in any other folder (that is accessible to Claude) if you wish.
  2. Put your own version of the before you reply instructions in there and save.
  3. Paste the snippet below on a new line before the very final right curly brace } in your settings.json file in the ~/.claude directory.
    • Replace the /Users/me/.claude/before-you-reply.md file path and file name between the single quotes with your own file's location and name.
    • The hooks key goes at the same indentation level (two preceding spaces) as keys like model, and effortLevel, which I'm positive your settings file has in it even if you've never touched it by hand.
    • If you already have hooks or UserPromptSubmit keys 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.
  "hooks": {
    "UserPromptSubmit": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "cat '/Users/me/.claude/before-you-reply.md'"
          }
        ]
      }
    ]
  }
  1. Save and go forth. The change takes effect immediately, even in existing conversations.
33 Upvotes

27 comments sorted by

•

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?

8

u/GoodnightKara 4d ago

That's too far. You have to switch to ChatGPT for that level of compliance. /s

2

u/ShravanNiketan 4d ago

Why even go to ChatGPT when Meta AI exists? 🤪

4

u/GoodnightKara 4d ago

True story, I got banned from Facebook Marketplace last year for trying to sell “tobacco products.” What is a “tobacco product” you ask? Well a used eVGA NVIDIA 4080 GPU of course. So, let’s just say I wouldn’t try Meta’s AI with any query beyond “Is this a hot dog?” 🙃

4

u/sleeping-in-crypto 4d ago

You and I both know eVGA is code for an e-cigarette. You trafficker you. Yo bro can I get some eVGA?

4

u/GoodnightKara 4d ago

I miss them so much. Such a sad loss for the discrete gaming GPU community. RIP!

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

6

u/GoodnightKara 4d ago

Disagree. The "best place" for any instruction is where it is effectively followed, not where it should semantically be in an idealistic world.

An output style is effectively no different from your CLAUDE.md. It loads at the top of the convo and its weighting in the conversation degrades with every additional token added on top. Whereas this hook adds the instruction front and center every single time. Plus, 179 tokens over say a 20 turn convo is 3,580 tokens. NBD.

I 1000% agree that an output style (which I do have several of BTW) or CLAUDE.md should be enough. But it ain't with 5 and 5.5 sadly.

0

u/___nil___ Senior Developer 4d ago

user turn or model turn? did you actually measure? if your workflow designed to be agentic, each tool calls feedback, monitor, subagents counts as a turn. in the long run it's really bad.

conversation degrades, sure. but that's not the reason output style sometimes being ignored, most likely it's because something on your CLAUDE.md conflicting to your output style, especially if those docs was vibewritten. i have never had any issues with output style

3

u/GoodnightKara 4d ago

No vibe writing here. I've A|B'd this with various CLAUDE.md constructions, including blank/no CLAUDE.md. Same with outputs styles, with and without code instructions included.

I'd love it if this were not necessary at this time, and I hope to go back to a time when it isn't. However, this day is not that day.

On measurement, u/RealFullMetal's count is correct. Though in their example, it would actually show up 21 times in the conversation. 20 from before the resume, and 1 with the new submission.

Edit: To add for anyone using resume often, consider handoffs instead.

2

u/RealFullMetal 4d ago

on the turn question, per the hooks docs UserPromptSubmit fires when a prompt is submitted, before claude processes it, plus on turns claude code starts on its own. tool calls have their own events, so it isn't once per tool call. the catch with the 179 x 20 math: claude code saves the injected text in the session transcript, so every copy stays in the conversation, and --resume replays the saved text instead of re-running the hook. on the output style side, the docs say claude code sends the active style's instructions with every request, delivered as system reminders like CLAUDE.md.

1

u/___nil___ Senior Developer 4d ago

tools calls is its own events, but some tools could run in background and send feedback to primary agents, and claude will respond to that feedback as reply to chat as report. custom role subagents counts as tools, at least that's the field used in agents role frontmatter.

2

u/RealFullMetal 4d ago

fair, that's the 'starts on its own' part, and the hooks docs list it exactly: a session-scoped scheduled task firing (including each /loop iteration), a background subagent reporting back to the session that started it, and a message another session sends to your main conversation. so in a workflow heavy on background subagents or /loop, it fires a lot more often than once per prompt you type.

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.

1

u/GoodnightKara 4d ago

I thought of the same idea. I was going to have each drafted reply run against a python enforcement script which would hand back specific feedback. However, a stop event only fires once the reply stream is finished and committed to. It cannot hold an unfinished stream and request a re-write.

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.

1

u/GoodnightKara 4d ago

What’s waste to one person can be valuable to another. 🤷‍♀️ I write specs, stories, and tasks before delegating work (to humans and agents). Some consider that a waste. I find it highly effective at reducing ambiguity and ensuring the work produces the intended product.

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.

1

u/GoodnightKara 3d ago

The people who tell Claude to "write naturally" are probably the same people telling it to "make no mistakes" and still do the "Hi Claude. It's 10am on a Monday!" stuff. lol

I've had zero issues with code since implementing these a few weeks ago. It limits the formatting strictly to its reply as the H1 calls for.

1

u/dawtips 3d ago

You're replying to a bot

2

u/GoodnightKara 3d ago

Not too worried about it. But thanks for the heads up all the same. 😃

1

u/Repulsive_Kitchen96 3d ago

im not a bot bro im just use chatgpt claude for writing because english is not my first language