Keeping AI coding agents within scope
Keeping AI coding agents within scope: declare paths, approve them separately with an expiry, check writes during the run and compare the diff after.
Keeping AI coding agents within scope takes four separate steps: write the scope down as paths, approve it as a distinct decision, check writes while the agent runs and compare the final diff with what you approved. Most people only do the first step, usually as one line in a prompt ('only touch the invoice module'), and then find that the agent also reformatted a config file, renamed a helper used elsewhere and updated a lockfile. A prompt instruction is a request. It shapes behavior, but nothing holds the agent to it. The workflow below treats scope as data you can compare against, and it works with Claude Code, Codex CLI or any agent that edits a git working tree. It also spells out what a pattern-based check can and cannot catch, because a tripwire you overestimate is worse than one you understand. If an agent has already strayed, start with what to do when an agent changes files you did not ask for instead.
Step 1: Write the scope as paths, not intentions
Scope should be something a script can check. 'Keep changes small' cannot be checked. A list of paths can. For a task like 'Add a VAT line to the invoice PDF', a usable scope looks like this.
Editable: src/invoices/pdf.py, src/invoices/vat.py, tests/invoices/test_pdf.py. New files allowed: tests/invoices/fixtures/vat_invoice.json. Read only: src/billing/ (the agent may read it to understand totals, not change it). Out of scope: migrations, lockfiles, CI configuration.
The read-only list matters as much as the editable one. Agents often fix what they read, and a shared billing helper is exactly the file you do not want changed as a side effect. Put the scope in the task record, not only in the prompt, so it outlives the session and you can compare against it afterwards. If you cannot name the files yet, the task is not ready for edits: run a review-only session that proposes the file list first, then write the scope from its answer. For more on task wording, see writing tasks an agent can finish.
Step 2: Approve the scope separately, with an expiry
Whoever writes a task proposes a scope. Approving it is a different act, and it should be visible as one. If editing a task's file list is enough to let an agent work on those files, then anyone with edit rights (including an agent updating its own task) can widen its authority by accident.
A simple way to make approval concrete is to approve a fingerprint: a hash of the sorted path list together with the task's revision. If the list changes after approval, the fingerprint no longer matches and the approval has to be given again. Add an expiry, such as the end of today's working session, so an approval from last week does not quietly authorize a rerun next month. Keep revocation separate as well: ending a session is not the same as withdrawing permission, and you should be able to do either one without the other.
Write down who approved, when, the fingerprint and the expiry. That record is what you check later when the diff contains a surprise.
Step 3: Enforce what you can during the run
Use the strongest mode your tool offers for the job. For planning, there is no need to allow edits at all: Claude Code has a plan mode, and Codex CLI has sandbox and approval modes including read-only. For edit runs, a hook or guard can compare the target path of each file-editing tool call with the approved list and refuse anything outside it.
Be clear about what that is. A pattern check compares a path in a supported tool call with a list of allowed paths. It sees what the tool reports as a file edit. It does not see a shell command that writes a file: sed -i, an output redirect, a Python one-liner or a code generator can change any file the user account can reach. Some guards inspect shell commands too, but parsing arbitrary shell is heuristic and easy to get wrong in both directions. A pattern check is a tripwire, not containment and not an operating-system sandbox. If you need real isolation, run the agent in a separate checkout, container or user account, and still keep the path check, because it catches honest mistakes early.
Step 4: Compare the diff with the approved scope
After the run, list what actually changed: git status --porcelain for modified and untracked files, and git diff --name-only against the commit you started from. Compare that list with the approved paths. Untracked files count; agents often leave scratch scripts and generated fixtures behind.
For every path outside scope, make an explicit decision. Revert it if it is noise. If the change is genuinely needed, do not quietly widen the original task after the fact. Record it as separate work with its own scope and approval, as described in handling work an agent discovers mid-task. Retroactive widening is how a two-file task becomes a twelve-file change that nobody reviewed as such.
Keep the result with the task: approved paths, actual paths and what you did about the difference. Over a few weeks this record shows you which kinds of task drift and which agents need tighter scopes, and it gives a reviewer the context for a cross-file review.
HOW BRAIN FLUID DOES IT
BRAIN FLUID keeps proposed card scope separate from approved execution authority, so editing a card's scope does not by itself grant an agent permission to work [N09]. Configured command guards and scope controls check work against the declared boundaries [C5]. Starting the optional fence previews the scope, approves a fingerprint of it with an expiry and publishes it [C5]. Stopping the fence removes the interactive selection but does not revoke that approval, and with the fence off, hosted locks, revision checks and recovery fences stay active [C5]. Shell inspection is heuristic, and the Claude and Codex hooks are different adapters whose full parity is unverified [C5]. A card's review session runs Codex read-only or Claude in plan mode, while a work session needs a non-empty approved scope and refuses closed, blocked, held or decision-waiting cards [C1b, N09].
- N09 Execution grants
- Keep proposed card scope separate from approved execution authority. Evidence: Implemented; final authority/revocation tests retained
- C5 Protection hooks
- Use configured command guards and scope controls to check work against declared boundaries. Evidence: Implemented; final-candidate hook tests retained
- C1b Card-linked terminals
- Open Claude or Codex from a card, with its working context close at hand. Evidence: Implemented; retained synthetic native checks
QUESTIONS
- Can I stop an AI coding agent from editing files outside one folder?
- Partly. Hooks and permission settings can refuse file-edit tool calls aimed outside an approved list, and read-only modes stop edits entirely. A shell command can still write anywhere your user account can, so path checks are tripwires rather than containment. For hard isolation, run the agent in a separate checkout, container or account, and compare the final diff with the approved list either way.
- Is telling the agent which files to change in the prompt enough?
- It helps, but it is a request, not a limit. Agents follow scope instructions most of the time and drift when a nearby fix looks obviously useful. Treat the prompt as the first of several layers: a written path list in the task record, a separate approval, a check on edits during the run and a diff comparison afterwards.
- Why should an agent's scope approval expire?
- Because the situation it approved changes. The code moves, the task gets edited and the person who approved it forgets the details. An expiry, such as the end of a working session, forces a fresh look before the next run. Pair it with a fingerprint of the path list so any edit to the scope also requires a new approval.
RELATED GUIDES
RELATED HARNESS PAGES
BRAIN FLUID AI HARNESS
COMING SOON
Verified against the v1.8.5 development candidate (October 30, 2026 build) (reviewed October 30, 2026)
Free Windows software, not released yet. The download opens on the product page when the release is approved, with nothing to sign up for.