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
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.
End of a session fixing the login page, plus the prompt above
Yes, three things. Lines to add to CLAUDE.md:
- Run
npm testbefore every commit; the login tests are slow. - The login page uses the shared
AuthFormcomponent. 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.