Skip to content

Sessions & context

A coding agent has a memory problem that cuts both ways. Close the terminal and it forgets everything — the files that mattered, the decisions you reached, the dead ends you’d already ruled out. But leave a single session running too long and it forgets just as badly, for the opposite reason: the context window fills with old turns and file dumps until the signal you care about is buried, and the agent starts going hazy and contradicting itself.

This chapter is about staying in control of both ends. There’s nothing exotic in it — six commands and, more importantly, the judgment of when to reach for each. To make that judgment concrete, we’ll follow a single thread of work rather than list features in the abstract.

You’re maintaining a small payments API. Over the next six lessons you’ll live a fairly ordinary week with it:

  • Monday morning you come back to a refactor you’d left half-finished on Friday, and pick it up without re-explaining a thing.
  • An hour in, an unrelated bug jumps the queue — and you learn to switch tasks cleanly instead of dragging the refactor along.
  • You let the agent run long on a feature and it quietly misreads a requirement; you rescue the session instead of starting over.
  • You hit a design fork — two ways to do validation — and explore both without losing either.
  • By Thursday afternoon the session has been running for hours and the agent is getting dull; you learn to see why.
  • And with the work still unfinished, you keep the session alive without letting it collapse under its own weight.

Each lesson adds one move, and each leaves you with the problem the next one solves. Read them in order and they’re a story; drop into one and it still stands.

By Friday you’ll treat the context window the way you treat memory in any program you write — a resource you watch, spend on purpose, and reclaim before it runs out. That habit, more than any single command, is what lets you run Claude Code for hours across days without the wheels coming off.

Start with Monday morning.