Skip to content

Sessions & context

A coding agent has a memory problem that runs in two directions. Close the terminal and it forgets everything — which files mattered, the decisions you reached, the dead ends you’d already ruled out. But leave one 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 thing you actually care about is buried under days of stale history, and the agent goes hazy and starts contradicting itself.

This chapter is about staying in control of both ends. Nothing in it is exotic — a handful of slash commands and one launch invocation, plus 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 inherited budgetcli last chapter — a friend’s weekend FastAPI budgeting service — and shipped your first reviewed fix. The real work starts now, and it spans days:

  • This morning you come back to yesterday’s session and pick it up without re-explaining a thing.
  • You hit a design fork — two ways to categorise transactions — and explore both off a shared starting point instead of betting on one.
  • A small tangent jumps the queue mid-task, and you handle it without derailing the thread you’re in.
  • You let the agent run long on a money-handling refactor, the window fills, and you reclaim it in place instead of starting over.
  • The agent starts feeling dull, and you learn to see exactly what’s eating the window.
  • And when a line of work is genuinely finished, you reset cleanly instead of dragging its residue into the next thing.

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

By the end 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 Codex across days of work on your own financial data without the wheels coming off.

Start where the week does — picking up yesterday’s session.