I Spent 3 Months Battling Claude Code’s Memory Limits. Here Are 9 Fixes That Saved Me
You’ve been using it wrong. I did too.
For three months, I blamed the model. I thought my prompts weren’t sharp enough, or that I’d chosen the wrong settings. But the real problem was hiding in plain sight: the context window.
It’s the elephant in the room. Your AI assistant seems to get dumber over time. You think it’s losing capability. In reality, you’ve just filled up its whiteboard.
This article isn’t theory. It’s the playbook I built from three months of real failures and fixes. If you work with Claude Code, these nine strategies will save you dozens of hours of wasted effort.
Let’s get into it.
First, Understand What You’re Actually Fighting
Core question: Why does Claude seem to forget things after a while?
Imagine Claude has a physical whiteboard in its head. Every message you send gets written on it. Every file it reads gets added. Every command it runs takes up space.
That whiteboard has a fixed size. That’s the context window.
When the whiteboard fills up, Claude’s performance tanks. It forgets rules you gave it an hour ago. It makes silly mistakes. It starts repeating itself.
The AI isn’t getting dumber. It’s just run out of space.
Boris Cherny, who built Claude Code, put it bluntly: “Using Claude Code well is all about managing that whiteboard.”
Everything else flows from this idea.
Strategy 1: Stop Letting Claude Code Immediately
Core question: How do you stop Claude from writing the wrong code?
This is the trap almost every beginner falls into.
You describe what you want. Claude immediately starts writing code. Fifteen minutes later, you realize it solved the wrong problem. Or it missed the point entirely.
Worse, those fifteen minutes of code generation just ate up a huge chunk of your precious context window. By the time you want to correct course, the whiteboard is already half-full.
The fix: Use Plan Mode first.
Claude Code has a Plan Mode. Hit Shift+Tab and you’re in it. In this mode, Claude reads files and thinks through problems without touching a single line of code. It acts like an architect drawing diagrams, not a contractor swinging a hammer.
Here’s my current workflow:
-
Switch to Plan Mode. Have Claude read the relevant files and understand how everything connects. -
Ask for a complete plan. Which files need changes? What’s the right sequence? Where might things break? Is there a cleaner approach? -
I review the plan. If something’s off, we fix it here, when it costs nothing. -
Switch back to normal mode. Now we start coding, based on a plan I’ve already approved. -
Have Claude commit with clear messages. Makes future debugging way easier.
Spending ten extra minutes on planning saves hours of rework.
Boris’s team takes this further: they use one Claude to write the plan, and another Claude to review it like a senior engineer. They’re serious about this planning step.
Strategy 2: Use Subagents to Protect Your Main Session
Core question: How do you research complex problems without trashing your context?
Back to the whiteboard analogy.
When Claude investigates a problem, it reads a lot: logs, config files, source code. After all that reading, the whiteboard is nearly full. By the time it’s ready to actually write code, there’s barely any space left. The code quality suffers.
Subagents solve this cleanly.
A subagent is a separate Claude instance. It has its own whiteboard, its own context window. It does the heavy research and reports back, without taking up any space on your main session’s whiteboard.
The usage is simple: just add “use subagents” to any research task. Like this:
“
“Use subagents to investigate how the payment flow handles failed transactions.”
The subagent goes off, reads all the relevant data, and comes back with a clean report. Your main session stays fresh. You get the insights and still have plenty of space to actually write code.
This is my most-used technique, hands down.
As a backend developer working with distributed systems, I used to watch a single debugging task trash an entire session—logs scattered everywhere, call traces running through multiple services. Now I throw all the “read logs, dig through source, trace the call chain” work to subagents. My main session only makes decisions and writes code. The efficiency gap is enormous.
Strategy 3: CLAUDE.md Is Your Living Rulebook
Core question: How do you make Claude remember your preferences without repeating them?
If you use Claude Code daily but haven’t built a good CLAUDE.md file, you’re leaving efficiency on the table.
CLAUDE.md is a file Claude reads every time it starts up. Whatever rules you put in there, Claude follows.
Think about the things you say over and over:
- ◉
“Use ES modules, not CommonJS” - ◉
“Don’t use mocks in tests” - ◉
“Run the linter after changing code” - ◉
“Branch names should be feature/ticket-number”
Without CLAUDE.md, you repeat these every session. With it, you say them once.
But here’s the real trick: Every time Claude makes a mistake and you correct it, add this:
“
“Update
CLAUDE.mdto prevent this mistake in the future.”
Claude will write the lesson into its own rulebook. Over time, CLAUDE.md becomes a living document, perfectly tuned to you and your project.
I got one of my CLAUDE.md rules exactly this way. I noticed Claude kept creating .txt files in my Obsidian Vault—which Obsidian ignores completely. Useless. I corrected it once, told it to update the rules, and it never happened again.
⚠️ But watch out: CLAUDE.md can’t be a novel. If it hits 500 lines, Claude’s attention scatters and some rules get ignored. My rule: Every rule should answer the question “Would Claude make a mistake without this?” If the answer is no, delete it.
Strategy 4: Give Claude a Way to Check Its Own Work
Core question: How do you stop being the only quality checker?
Most people work like this: describe the task → hope Claude gets it right → read every line themselves to verify.
Congratulations, you’re now the QA department. It’s exhausting, and you’ll miss things.
The better way: Build verification into your prompt.
Say you want an email validation function. Don’t say:
❌ “Write a function to validate email addresses.”
Say this instead:
✅ “Write a function that checks if an email is valid. Test it with these cases: hello@gmail.com should pass, hello@ should fail, .com should fail. Run the tests after writing.”
Claude writes the code, then immediately tests it and shows you the results. You don’t have to read a single line.
Visual tasks work the same way. Need a button redesigned? Paste a screenshot and say: “Make it look like this. After you change it, show me a screenshot and tell me what’s different.”
Give Claude a clear comparison standard. Stop being the only feedback loop. This trick alone saves hours.
Strategy 5: Write Prompts Like Technical Documentation
Core question: Why does Claude keep misunderstanding what you want?
Claude can infer a lot from context, but it can’t read your mind.
Compare these two prompts:
❌ Vague: “Add tests for PaymentService.”
✅ Specific: “Write unit tests for PaymentService that cover cases where the user session expires mid-request. Don’t use mocks. Focus on edge cases where the token looks valid but has actually expired.”
Same task. Completely different results.
You can also point Claude exactly where to look:
❌ “Why is this function acting weird?”
✅ “Look at this file’s git history and find when this behavior was added and why.”
The difference is between Claude guessing and Claude giving you a real answer.
As a backend developer, I now treat prompts like API documentation: clear inputs, clear outputs, clear constraints, clear validation. Do the same.
Strategy 6: Reset Context Every 30-45 Minutes
Core question: What do you do when Claude starts rambling or forgetting?
Talk to Claude long enough, and you’ll see it drift. It repeats itself. It forgets early rules. Answer quality drops.
That’s context pollution. The whiteboard is full. Claude is overwriting old stuff to make room for new, and things are getting lost.
Boris’s team resets context every 30-45 minutes on complex tasks. Here’s how:
-
Ask Claude to summarize: “Summarize what we’ve done, what’s left, and what problems we’re still solving.” -
Start a new session. -
Paste the summary into the new session. Keep going.
This keeps Claude’s thinking sharp. No more “AI brain fog.”
People get attached to long sessions. “But all the context is in there!” they say. Here’s the truth: a bloated, messy context is worse than a clean, focused summary.
Strategy 7: Parallel Sessions + Git Worktree
Core question: How do you run multiple Claudes at once without them interfering?
This is the productivity trick Boris’s team swears by.
You can run multiple Claude Code sessions at the same time, each with its own git worktree (an independent working copy of your codebase). They work in parallel, completely separate.
Example:
🅰️ Session A writes a new feature.
🅱️ Session B reviews A’s code.
Feed A’s output to B. Have B find edge cases and bugs. Take the feedback back to A. One Claude writes, one Claude reviews. Code quality goes up. Speed goes up.
Some people run 3-5 sessions, name their worktrees, and set shell aliases (za, zb, zc) to switch instantly.
You can do the same for test-driven development: one Claude writes the tests, another writes code to pass them. TDD, with Claude doing the heavy lifting.
Strategy 8: Turn Repetitive Tasks Into Skills
Core question: How do you stop typing the same long prompts every day?
If you do something in Claude Code more than twice a day, turn it into a Skill.
A Skill is just a saved workflow. You write out the steps once, give it a name, and then just call the name. Claude runs the whole sequence.
I’ve built over a dozen Skills for myself: cover image generation, article publishing, image compression, web page to Markdown conversion. Every one started as a prompt I typed manually. Every one became a single command.
Boris’s rule is worth stealing: If you do it twice a day, Skill it.
His team built a Skill for BigQuery. Now team members run data analysis queries in Claude Code without writing a single line of SQL. One Skill, reusable across every project.
Strategy 9: Feed Real Data, Not Your Guesses
Core question: How do you let Claude understand bugs without you translating?
The traditional bug-fix loop: you describe the bug → Claude guesses wrong → you correct it → repeat until fixed. This burns through context like crazy.
The faster way: Give Claude the real data, then walk away.
Boris’s team hooked up Slack via MCP. When a bug report comes in, they paste the Slack thread to Claude and type one word: “fix.”
No explanation. No hand-holding. Claude reads the conversation, finds the problem, and fixes it.
Or: “Fix that failing CI test.” Then walk away. No telling Claude which test. No explaining why it failed. Claude figures it out.
The key is: Give Claude real data (Slack threads, error logs, Docker output), not your second-hand interpretation.
Claude is surprisingly good at reading distributed system logs and pinpointing failures. As a backend developer, this one genuinely impressed me.
Putting It All Together: My Daily Workflow
Here’s how I actually work now, stringing all these strategies together:
Before starting a task
- ◉
Check if CLAUDE.mdneeds updates - ◉
Decide if this needs Plan Mode
During the task
- ◉
Complex research → subagent - ◉
Writing code → main session + specific prompts + built-in verification - ◉
Code review → second session (parallel + worktree)
Every 30-45 minutes
- ◉
Ask Claude to summarize progress - ◉
Decide if we need a context reset (new session)
After the task
- ◉
Mistakes Claude made → update CLAUDE.md - ◉
Repetitive steps → turn into a Skill
This workflow tripled my effective output. Not because Claude got better. Because I learned how to manage its brain.
Final Thought: Managing AI Attention Is the New Skill
Back to that whiteboard.
The context window is fixed. You can’t make it bigger. But you can decide what gets written on it and when to wipe it clean.
Managing context is managing attention.
It’s a new skill. It has nothing to do with programming ability or domain knowledge. But it determines how much value you get from AI.
Learn it early. Benefit for years.
What’s the biggest context-window mistake you’ve made? Drop it in the comments 👇
Practical Summary / Action Checklist
-
Plan first, code second: Hit Shift+Tabfor Plan Mode. Think before you build. -
Research with subagents: Add “use subagents” to complex queries. -
Maintain CLAUDE.md: After every correction, ask for an update. Keep it lean. -
Build in verification: Put test cases or comparison images directly in prompts. -
Be specific: Write prompts like API docs—clear inputs, outputs, constraints. -
Reset regularly: Every 30-45 minutes, summarize and start a fresh session. -
Go parallel: Multiple sessions + git worktree = multiple Claudes, zero interference. -
Skill the repeatable: Anything twice a day becomes a saved command. -
Feed raw data: Give logs, threads, errors—not your interpretation.
One-Page Summary
Claude’s context window is a fixed-size whiteboard. To keep Claude smart, manage that whiteboard:
- ◉
Plan before coding - ◉
Research with subagents (saves main session space) - ◉
Lock in rules with CLAUDE.md - ◉
Add verification to prompts - ◉
Reset sessions before they get polluted - ◉
Run parallel sessions + git worktree - ◉
Turn repeats into Skills - ◉
Feed raw data, not guesses
FAQ
Q1: How do I use Plan Mode in Claude Code?
A: Press Shift+Tab in a session. Claude will analyze files and produce plans without modifying any code.
Q2: Do subagents cost extra?
A: They run as separate sessions and consume separate tokens. The cost is worth it to protect your main session’s context.
Q3: Where should I put CLAUDE.md?
A: In your project root. Claude reads it automatically on startup. Keep it short—every rule should prevent a real mistake.
Q4: How do I make Claude test its own code?
A: In your prompt, say “After writing, test with these cases” and provide the test inputs and expected outputs.
Q5: Won’t resetting context lose progress?
A: No. First ask Claude to summarize. Then paste that summary into a new session. Progress is fully preserved.
Q6: Does parallel work really help?
A: Yes, especially with git worktree. One Claude codes, another reviews. Or one writes tests, another writes implementation. It’s faster.
Q7: How do I create a Skill?
A: Save the complete prompt for a repetitive task, give it a name, and call that name in future sessions. Check Claude Code docs for exact steps.
Q8: Can Claude really understand raw error logs?
A: Yes. Claude is good at reading raw data—logs, Slack threads, CI output—and pinpointing issues. It’s often more accurate than human interpretation.
Sources
- ◉
Anthropic official best practices - ◉
Boris Cherny (Claude Code creator) talks - ◉
“Efficient AI” Claude Code deep dives
