Claude Code Keeps Forgetting Your Rules? Try This 4-Message Reminder Trick

AI coding assistants like Claude are incredibly powerful, and their code generation capabilities are advancing daily. However, as discussed previously, there are common pitfalls that can seriously compromise your application: unrequested code modifications, the insertion of placeholder values, the introduction of security vulnerabilities, and the generation of unmaintainable, duplicated code.
By explicitly prompting the AI to avoid these traps, you can improve maintainability and security. (See the detailed breakdown of these traps in the previous article.)
A recommended practice is placing a common set of instructions in a claude.md
file that’s loaded at the start of every session. However, this can fail in long sessions due to a core limitation of transformer-based AI: the limited context window.
The Problem: Why AI Forgets Your Instructions
When a conversation exceeds the model’s context limit (e.g., 200,000 tokens), AI tools may truncate the earliest parts of the conversation. Your initial claude.md
instructions can fall out of context and be ignored.
This is separate from the general tendency of LLMs to sometimes "forget" parts of the context depending on where they appear in the conversation, but the outcome is the same: your rules are ignored.
Fine-tuning could help, but it’s not necessary here. There’s a simpler approach: use a reminder technique.
How the Reminder Technique Works
The AI outputs a message number after each response, creating an external anchor that helps it track conversation progress. Every nth message, this numbering triggers an automatic reminder of the rules, preventing the typical memory drift that occurs in long conversations.
Here’s how to implement it. We’ll trigger a typical problem in coding sessions: the AI modifies code instead of just answering a question.
This issue might not always occur in Claude Sonnet 4/4.1, but we use it here as an example. The same technique applies to any issue you face with Claude.
First, give it the initial instructions:
I will now start a coding session with you. Output the message number after each message without explanation. Every 4th message, remind yourself of these rules: * If I ask a question, just answer - never modify code * Always ask permission before changing anything * Keep responses short Start with message #1.
The AI confirms and starts with message #1.

Next, ask it to write some code:
code hello world
It responds with the message number and a simple piece of code, as requested.

Now ask a question about the code:
Why did you use print()?
It correctly answers the question instead of modifying code.

Trigger the fourth message:
why pyhton
It outputs the message number, re-lists the rules, then answers the question.

Now, even in very long conversations, the AI keeps reminding itself of your core rules. You can change the reminder cadence and rules as needed.
Example Checklist for your claude.md
File
Based on the common issues encountered with Claude, here’s a compact set of instructions to add to claude.md
:
I will start a coding session with you.
Output the message number after each message without explanation.
Every 4th message, remind yourself of these rules:
MANDATORY CHECKS:
* Only change what's explicitly requested - NEVER modify unrelated code
* Update package.json/dependencies when adding imports
* NO placeholders (YOUR_API_KEY, TODO) - use proper variables/config
* Questions = Answers ONLY - Don't modify code unless asked to "change/update/fix"
* NO assumptions - ASK for missing information
* Security first - NO secrets in client code, use env variables
* Add intelligent logging to core flows automatically
* Clean unused code when making changes
* Provide CODE EVIDENCE when asked about implementations
If you violate these rules, you are breaking critical development protocols.
Start with message #1.
Wrap Up
Think of this like working with a teammate. In a long meeting, people forget the ground rules unless you repeat them. The reminder technique is just a quick “rules check” every few messages so the assistant stays on track—answer questions, don’t change code, no placeholders. It’s the same trick you’d use with people: clear rules, repeated briefly, at steady intervals.
Comments ()