Skip to content

Compact or restart? Keeping Claude Code sharp

Long coding sessions go stale for the same reason long chats do. Claude Code gives you two ways out, and picking the right one makes or breaks the afternoon.

By Nick

2 min read

Coding tools Intermediate
On this page

Before you start

An hour into a coding session, Claude Code has read forty files, run thirty commands and argued with you about a bug. All of that is on the desk, and the desk is full. The context page explains why that makes it worse. Here is what to do.

Compact: fold the pile

The compact command asks it to summarise everything so far into a short note and carry on from that note. The files it learned about, the decisions you made, the current task: kept. The forty dead ends: gone.

Use it at a natural break. You just fixed a bug and committed. Now compact, before starting the next thing. Doing it then means the summary is about a finished job, which is easy to summarise well.

Do not wait for it to compact itself. It will, when it runs out of room, and that is always mid-task, when the summary has to guess what matters.

Restart: start clean

Quit and start again. Everything in the conversation is gone. Everything on disk, including your CLAUDE.md, is still there.

Use it when the job changes. Fixing the login page and then building the newsletter form are two jobs. The second one does not need anything the first one learned, and carrying it over only makes the desk messier.

The rule I use

Same job, natural pause: compact. Different job: commit, restart. If I cannot tell which it is, it is a different job.

Before either, if the session learned something worth keeping, paste this:

Before we compact or restart: is there anything you learned about this project in this
session that I should add to CLAUDE.md so you do not have to learn it again? Give me the
lines to add, or say there is nothing.
Example reply (trimmed). Your app will word it differently.

End of a session fixing the login page, plus the prompt above

Yes, three things. Lines to add to CLAUDE.md:

  • Run npm test before every commit; the login tests are slow.
  • The login page uses the shared AuthForm component. Do not copy it.
  • Staging data resets nightly, so do not rely on test accounts.

If you are re-explaining the project every morning, the fix is that file, not a longer session.

Common questions

Does Claude Code compact on its own?

Yes, when it runs out of room. That is the worst moment for it to happen, in the middle of a job, so doing it yourself at a natural break is better.

Do I lose my work when I restart?

Nothing on disk. Your files and commits are safe. You lose the conversation, which is the point. Commit first and the restart costs nothing.

Is this the same in Codex and Cursor?

Same problem, similar tools. The habit transfers: compact at a milestone, restart when the job changes.

What to do next

Related reading

Last reviewed 9 October 2026 by Nick.

Software changes fast. If something here is out of date, tell me and I'll fix it.

Get new guides by email

Occasional and practical. No spam, no hype, unsubscribe whenever.

Occasional practical guides from UncomplicateAI. You will get a confirmation email before anything else is sent. Unsubscribe any time. Privacy

You are not subscribed until you confirm the email. Unsubscribe any time.