Sub topic 5
Scoping Work So a Task Fits One Session
This chapter assumes you have used a coding agent in a terminal or editor, know basic git, and understand that a model has a limited input size. It covers how to cut a large goal into tasks that finish inside one context window.
Why scoping comes first
A crowded context degrades the agent's work. It forgets earlier decisions, repeats itself, and contradicts its own plan. You can compact or restart a session, but the cheapest fix is to avoid a bloated session in the first place. Scoping does that by deciding, before you start, how much the session has to hold.
A well-scoped task has three properties:
- One goal. You can state it in a sentence.
- A bounded set of files. You can name the files or directories involved.
- A checkable finish. A test, command, or diff tells you it is done.
Sizing a task
Estimate the work by what the agent must read, change, and run. Reading many files and running long test suites cost more context than writing code does.
| Signal | Likely fits one session | Likely too big |
|---|---|---|
| Files to read | A handful | Dozens, or "the whole module" |
| Goal | "Add retry to the HTTP client" | "Modernize the networking layer" |
| Verification | One test file or one command | Full suite plus manual checks |
| Dependencies | Self-contained | Needs several earlier decisions |
If you cannot name the files, spend a short first step finding them. Then decide whether the task fits.
Splitting a large goal
Split along seams where one piece can be finished and checked without the next one. Good seams are:
- Layers: data model, then logic, then interface.
- Modules: one package or directory at a time.
- Phases: investigate, change, then clean up.
- Behavior-preserving steps: refactor first, add the feature afterward.
Each piece should end in a committed, passing state. A commit is a clean boundary. If a session goes wrong, you lose one piece, not the whole effort.
Writing the task statement
State the scope in your first message. Include the goal, the files in play, what is out of scope, and how to verify. For example:
Goal: make load_settings() read TOML instead of INI.
Files: src/config.py, tests/test_config.py.
Out of scope: docs, CLI flags, other modules.
Done when: pytest tests/test_config.py passes and the public signature is unchanged.The "out of scope" line matters. Without it, the agent may follow a tangent into unrelated files, and each file it reads stays in the context.
Common errors
- Vague goals. "Clean up the project" leads to wide exploration and no clear end.
- Mixing unrelated work. A bug fix, a refactor, and a new feature in one session leave three sets of file contents competing for space.
- Scope creep mid-session. When you notice a side issue, write it down and handle it in a later session instead of fixing it now.
- No checkable finish. Without a test or command, you cannot tell whether to stop, so the session keeps growing.
When the scope turns out wrong
Sometimes a task proves larger than estimated. Signs include a growing list of touched files and a plan that keeps expanding. Stop and act early. Commit what works, record the remaining steps in a notes file, and continue in a fresh session with a narrower scope. The next chapters cover notes and handoffs in detail.
Exercise
You are asked to "upgrade the project's logging." Name three steps you would take to scope this into sessions that each fit one context window.
Show answer
Any three of these: (1) find the files that use logging with a capped search and count them; (2) state one goal per session, such as "replace the logging setup in the api package"; (3) split by module or layer so each piece ends in a commit; (4) list what is out of scope, such as other packages; (5) define a check, such as the package's tests passing; (6) record remaining pieces in a notes file for later sessions.