DEV Community

Igor Irianto
Igor Irianto

Posted on Originally published at irian.to

Claude Code Context Is Like a Fridge - Put Only Perishable Items in It

Claude Code Fridge

I like my fridge. It can hold yummy foods. But its space is finite, and the fuller it gets, the worse it works. Food gets shoved to the back and forgotten until it smells. That chocolate mochi donut I got? It sat in the corner for 2 weeks. I had to throw it away. When the fridge gets full, I forget what I put inside.

Most of what I buy can go in the fridge. That doesn't mean it should. My Pocky could go in the fridge, but it doesn't need to. So it goes in the pantry, and the milk gets more room.

Claude Code works the same way. The main conversation is the fridge. Context is the milk. Many tasks drag in a lot of stuff that doesn't need to be cold.

Milk Goes In the Fridge

In the earlier milk post I said context is best served fresh and condensed. But every task costs context. You can't avoid spending it. What you can choose is where you spend it.

You need your dessert. Storing each dessert takes up space. But not all dessert goes into the fridge. Desserts that need to be cold like chocolate milk, boba tea, and cheesecakes, they go in the fridge. Non-perishables like pocky, chocolate prertzel, and choco pie, they go in the pantry to leave the fridge some room.

In Claude Code, there are four places where contexts are used and can be optimized: the main conversation, a subagent, a second session, or a headless loop. One fridge, three pantries.

The Fridge

The main conversation is where you and Claude talk. Everything said here stays here until you /clear it, or it gets compacted, either by /compact or automatically when the fridge is nearly full. Also, /rewind can also remove or summarize context.

What kind of prompt goes in the main conversation?

  1. Work that needs back-and-forth. "No, make the button smaller. Ok, now move it left." Or "what are the pros and cons of the strategy pattern here?" The kind of prompts that you can't hand off because you're the one steering.
  2. Quick, targeted changes. Start a session, make the change, get out.
  3. Anything where speed matters. A fresh subagent starts cold and has to gather context before it can do anything useful. The main conversation already has it.

These are your perishable items. Everything else, be picky about. They can go into the pantry.

The Subagent Pantry

A subagent is for the "go figure this out and tell me" kind of task. It's a separate Claude with its own fresh context and its own set of allowed tools. It goes off, does the work, and hands back a summary. The mess stays in its context, not yours. What happens in the subagent stays in the subagent.

The subagent reads 1,000 lines of noisy output. You get a three-line conclusion.

Delegate to a subagent when a task makes lots of output you don't need to see, like reading dozens of files, grepping logs, running test suites. Or when the work is self-contained enough to come back as a summary. Or when you want to limit its tools, like a reviewer that can read files but not edit them.

I used to tell Claude "investigate why X is slow" and let it run. It would obediently read hundreds of files. Then my context was full of stuff I didn't care about. In this case, you can do:

  • Scope the task: "look at src/cache/ only."
  • Hand the whole investigation to a subagent. "Go investigate X" is pantry work.

So how do you start a subagent?

This topic probably deserves its own blog post so I'll just touch on it briefly. There are multiple ways. One way is to ask explicitly: "Use a subagent to investigate why X is slow." If you've already defined subagents in .claude/agents/, mention one by name: @agent-code-architect plan the caching changes.

You can invoke the /subtask command, like /subtask Write a unit test for the authentication controller. A subtask is a subagent that inherits the whole conversation so far instead of starting fresh, so you don't have to re-explain anything. It runs in the background while you keep working, its tool calls stay out of your fridge. Only the result comes back to your conversation.

You can also run /fork, like /fork Write a unit test for the users controller. A fork copies your conversation into a separate background session that keeps working on its own. Unlike a subtask, it doesn't report back to you.

So /subtask is like asking your assistant to do a task: when he's done, he comes back with a brief report. /fork is like asking your assistant to do a task, and he wanders off to work on it and goes home when he's done. It's up to you to check on his work or assign him more.

One note, if you've turned off agent view, or you're on an older version of Claude Code, /subtask isn't available and /fork behaves like the subtask described above.

The New Session Pantry

The second pantry is a new session. This is when you spin up a new Claude session to use its main conversation instead of building on top of your current main conversation. For example, when you use Claude to write code and you want to review it, it's best to start a new session. Claude reviewing code it just wrote in the same session is like me proofreading my own essay. I see what I meant to write, not what I actually wrote. A fresh context has no attachment to the code. It just sees what's there. The Claude Code docs say the same: a fresh context improves code review, since Claude won't be biased toward code it just wrote.

Have two sessions. One writes, the other reviews, and the first one fixes.

Session A (Writer) Session B (Reviewer)
Implement a rate limiter for our API endpoints.
Review the rate limiter in @src/middleware/rateLimiter.ts. Look for edge cases, race conditions, and consistency with our existing middleware.
Here's the review feedback: {Session B output}. Address these issues.

You don't even have to copy-paste. Have Session B write its review to review.md, then tell Session A to address review.md.

Don't want to juggle two sessions? A subagent reviewer works too. It also starts with a fresh context, and its findings come straight back to the writer.

How do you run more than one session? You can run multiple tabs. I use Tmux and I like to see everything at once with panes.

Packing 3000 Lunchboxes

Say you have 3,000 files to migrate from one framework to another. If you try to do that in one session... don't try it. By file 100, your poor milk is shoved into the deepest, darkest corner of the fridge because your fridge is stuffed.

Don't use one session. Give each file its own fresh Claude. If you're packing for your class, don't pack one giant tub for the whole class! Instead, pack a lunchbox per kid. That's what a headless loop (claude -p) is for!

Here's one way to do it:

  1. Have Claude list the files: list all React components that need migrating → files.txt
  2. Loop over them in non-interactive mode (-p).
# claude_migrate.sh
for file in $(cat files.txt); do
  claude -p "Migrate $file from React to Angular. Return SUCCESS or FAIL." \
    --allowedTools "Edit,Bash(git commit *)" \
    --permission-mode dontAsk
done
Enter fullscreen mode Exit fullscreen mode
  1. Run it on 2-3 files first. Fix your prompt based on what goes wrong. Then run it on everything.

Each run starts clean. One failure doesn't poison the rest. Thousands of files is fine.

If you want them to be as autonomous as possible, use these flags:

  • --allowedTools pre-approves the tools each run needs, so you don't have to approve them a thousand times
  • --permission-mode dontAsk denies everything else instead of stopping to ask for approval.

You won't be around to answer anyway. Without dontAsk, a run that reaches for a tool you didn't list can stall or behave unpredictably. With it, that run is simply told no and moves on, and you'll see it in the SUCCESS/FAIL output. Keep the allowed list small. you don't want a thousand Claudes accidentally destroying things.

You can also pipe the output into your existing tools: claude -p "<prompt>" --output-format json | your_command.

If your bash scripting skill is half as bad as mine and can't write a simple loop without asking Claude / looking it up, don't fret! Claude can do this natively with /batch. It splits a change across 5-30 parallel subagents.

Clean Fridge, Happy You

Tape this to your fridge door.

Does it need back-and-forth with me, or share lots of context with what we're doing now?
├── Yes → main conversation
└── No
    ├── Is it one self-contained chunk (investigate, search, read lots of files)?
    │   └── Yes → SUBAGENT (comes back as a summary)
    ├── Do I want a second opinion on work Claude just did?
    │   └── Yes → SECOND SESSION or REVIEWER SUBAGENT (fresh eyes, no bias)
    └── Is it the same task repeated over many items?
        └── Yes → HEADLESS LOOP (claude -p per item, or /batch)
Enter fullscreen mode Exit fullscreen mode

Before you put anything in, ask whether it really needs to be cold. You'll be surprised at how many items don't need to go into the fridge. Put the Pocky in the pantry and leave room for the milk.

Top comments (0)