My AI Forgot What Day It Was: How to Stop Claude Code Losing Context
My AI Forgot What Day It Was: How to Stop Claude Code Losing Context
My AI forgot what day it was, and it never said a word.
It kept working. The answers still looked sensible. The files were still being updated. But every date was four days wrong.
That is what makes context loss dangerous. The system does not always stop or show an error. It can continue with an incomplete version of what happened earlier.
If you use Claude Code for long projects, there is a simple way to reduce this risk. Compact the session deliberately, tell Claude what must survive, and store important facts in a file.
Why AI loses context
Every AI model has a context window. Think of it as the working space available for the current task.
In Claude Code, that space can contain:
- Your conversation
- Files Claude has read
- Command output
- Tool results
- Project instructions
- Loaded skills
- System instructions
As the session grows, that space fills up.
According to the official Claude Code documentation, Claude Code manages this automatically. It removes older tool output first. If that is not enough, it summarizes the conversation so work can continue.
This process is called compaction.
The summary cannot preserve every sentence. It tries to keep the active request and important code, but details from earlier in the session can disappear. A date, customer requirement, rejected option, or temporary decision may not survive.
The AI is not choosing to ignore you. It is continuing from a compressed record that may no longer contain the fact.
Why the mistake can go unnoticed
Context loss is not always obvious.
If Claude forgets the name of a file, a command may fail. You see the problem immediately.
If it forgets a date, assumption, or decision, the next answer can still sound correct. The structure is good. The language is confident. Only the underlying fact is wrong.
That creates a dangerous failure pattern:
- The session becomes large.
- Claude compacts the earlier conversation.
- One important detail is missing from the summary.
- Claude continues using what remains.
- The user sees a believable answer and assumes the earlier instruction still applies.
For a personal experiment, this is annoying. In a business workflow, it can produce the wrong deadline, customer message, price, environment, or approval status.
The command that gives you control
Claude Code supports the /compact command.
Instead of waiting for automatic compaction, run it at a clean boundary and tell Claude what the new summary must preserve.
For example:
/compact keep the current date, approved decisions, rejected options,
customer requirements, files changed, test results, blockers, and next step
For a software project, you could use:
/compact focus on the authentication changes. Keep the API contract,
security decisions, files modified, failed approaches, test status,
deployment environment, and remaining tasks.
The words after /compact give Claude a focus for the summary. Anthropic's documentation explicitly recommends this approach when you want to control what survives compaction.
When to compact
Compact between tasks, not during one.
Good moments include:
- After finishing a feature
- After resolving a bug
- Before moving from research to implementation
- Before starting deployment work
- After a major decision is approved
- When
/contextshows that the session is becoming crowded
Avoid compacting while Claude is halfway through an investigation, migration, or multi-file change. The session may contain unresolved evidence that has not yet been written anywhere permanent.
Finish the stage, record the result, then compact.
The production-safe workflow
For reliable work, use the following process.
Step 1: Check what is using the context
Run:
/context
This shows what is consuming space. Large file reads, logs, tool output, and long conversations can all reduce the room available for the task.
Do not wait until the session is almost full. Check at natural milestones.
Step 2: Finish the current unit of work
Get the task into a stable state. Run the tests, record the result, and make sure any important files are saved.
Compaction should close a chapter. It should not interrupt one.
Step 3: Write the durable facts to a file
Create a file such as PROJECT_STATUS.md and keep it short.
# Project status
Current date: 16 September 2026
## Approved decisions
- Use PostgreSQL for production.
- Keep manual approval before refunds.
- Deploy to staging before production.
## Rejected options
- Do not store secrets in the front end.
- Do not allow automatic database deletion.
## Current state
- Authentication change is complete.
- Tests pass locally.
- Staging deployment is pending.
## Next step
- Deploy version 1.4.2 to staging and run the smoke test.
Conversation context is temporary. A project file is inspectable, editable, and available in future sessions.
Step 4: Run /compact with a focus
Tell Claude exactly what matters for the next stage.
/compact keep the current date, approved decisions, rejected options,
current project state, test results, and next step from PROJECT_STATUS.md
Do not ask it to keep everything. That defeats the purpose. Preserve the facts needed to continue safely.
Step 5: Verify the compacted state
After compaction, ask Claude to restate the critical facts:
Before continuing, state the current date, the approved decisions,
the deployment environment, and the next step. Use PROJECT_STATUS.md.
Compare the response with the file. If something is wrong, correct it before more work is completed.
Step 6: Put permanent rules in CLAUDE.md
If an instruction must apply throughout the project, do not leave it only in chat history.
Store it in CLAUDE.md. Anthropic specifically recommends this for instructions that should survive long sessions.
You can also add a section for compaction:
## Compact Instructions
Always preserve:
- The current date and timezone
- Approved architecture decisions
- Security and permission limits
- Rejected approaches and why they were rejected
- Current test and deployment status
- The next confirmed task
Keep this section selective. A long instruction file consumes context too.
Step 7: Start a new session for unrelated work
Do not keep one conversation alive forever.
If you move from fixing authentication to planning marketing content, start a separate session. Mixing unrelated work makes compaction harder and increases the chance that important details compete for space.
Treat dates as data, not memory
If a workflow depends on the current date, ask the system to verify it when the task runs.
Do not rely on a date mentioned 100 messages earlier. Read it from the environment, an approved calendar, a project file, or another reliable source.
The same principle applies to:
- Prices
- Deadlines
- Customer permissions
- Deployment targets
- Account balances
- Policy versions
- Approval status
Facts that can change should be retrieved again. Facts that must persist should be written down.
The three rules to remember
BEFORE YOUR AI RUNS OUT OF MEMORY
1. Compact between tasks, not mid-task
2. Say what to keep: /compact keep ...
3. Put anything important in a file
The larger lesson is simple. AI conversation history is useful working memory, but it is not a reliable system of record.
Use the chat to think. Use files to remember.
Need help building reliable AI workflows?
If your team is using AI for long projects, automation, or client work, I can help you design the context, files, approval steps, and verification checks around it.
Contact me through my website or send me a direct message on LinkedIn.
Source
Stay ahead of the curve
Join my private newsletter for exclusive insights, tools, and thoughts straight to your inbox. No spam, just value.