An agent running a multi-step task accumulates state: what it tried, what failed, which files it read, what it plans to do next. That state has to live somewhere on disk if it is going to survive a context reset. The mistake most teams make is letting the agent improvise, which is how you end up with notes.md, todo.txt and debug-20250301.log scattered across the repository root.
Anthropic's guidance on context engineering frames the problem precisely: an agent in a loop generates more and more data that could be relevant to the next turn, and that information has to be cyclically refined rather than simply dumped somewhere 1. In a key-notes-on-disk approach, you are externalizing that refinement. The agent writes its plan and progress to a file, and later reads it back instead of replaying the whole history.
Four locations work, and they trade off differently:
| Location | Committed? | Visible to teammates | Best for | Main risk |
|---|---|---|---|---|
.agent/ inside the repo | No (ignored) | No | Single-repo agent work, plans, scratchpads | Accidentally staged before the ignore rule exists |
.scratch/ inside the repo | No (ignored) | No | Throwaway output, logs, generated samples | Same as above, plus teams ignoring it inconsistently |
Sibling worktree (../repo-agent/) | Separate branch | Only if pushed | Long autonomous runs that need a clean main tree | Disk usage, and the worktree itself can be committed to if you forget |
Outside the repo ($TMPDIR/agent-<id>/) | No | No | Ephemeral runs, CI jobs | Lost between sessions, no easy diff for humans |
The decision rule is simple. If the note has value to a future session of the same agent, keep it inside the repo under .agent/ and ignore it. If it has value to a human reviewer, it belongs in a pull request description or a design doc, not in a working file. If it has no value after the run, put it outside the repo entirely so it can never be staged by accident.
The OpenDev paper on terminal coding agents describes exactly this pattern: an automated memory system that accumulates project-specific knowledge across sessions, paired with explicit session boundaries, so that memory lives separately from the codebase it describes 2. A dedicated note directory is the lightweight version of that idea.
A useful prompt to pin down the location, adapted from the practice of specifying exact files and constraints in agent instructions 3:
Write all progress notes, plans and scratch output to .agent/<task-slug>/.
Never create new top-level files. Never write notes into src/, tests/ or docs/.
Before you finish, print the contents of .agent/<task-slug>/plan.md so I can review it.
That last line matters. It turns the note from hidden state into something you can read without it ever touching the index.



