# How to constrain an AI coding agent's scope

> Constrain a coding agent's scope with path fences, forbidden actions, exact verify commands, and a done-when stop rule.

Source: https://fullbytedeveloper.com/blog/constrain-ai-coding-agent-scope
Published here: 2026-11-16

Part 2 of 2 in the Guide the agent series. Part 1 is [how to stop an AI coding agent from over-engineering](/blog/stop-ai-coding-agent-over-engineering).

Constrain a coding agent's scope by writing four constraints into the instruction file it reads: path fences, forbidden actions, verify commands, and a done-when stop rule. Claude Code docs target under 200 lines per `CLAUDE.md` [1]. Codex loads instruction files up to 32 KiB combined by default [3]. In Claude Code, use a PreToolUse hook for hard blocks [1].

## Write four cards into the memory file

Put four blocks in `CLAUDE.md` or `AGENTS.md` before the next task:

1. **Paths.** Name folders the agent may edit, and folders it must leave alone.
2. **Forbidden.** Ban new dependencies, new top-level folders, and drive-by refactors unless the request asks for them.
3. **Verify.** Paste the exact lint and test commands for this repo. Do not let the agent invent a parallel check.
4. **Done when.** The request is met, the checks pass, then stop. If the request is ambiguous in a way that changes the design, ask one question and wait.

The `CLAUDE.md` docs ask for instructions concrete enough to verify, for example "Use 2-space indentation" instead of "Format code properly" [1]. Claude Code best practices put a rule that only matters in one part of the codebase in `.claude/rules/` with a `paths:` filter, so it loads only when Claude works there [2]. Codex best practices say add rules after repeated mistakes rather than dumping a novel up front [4]. Anthropic's overeagerness prompting still belongs in the request when you need a one-shot scope fence; put durable rules in the repo file [5].

A teaching composite (not an official Anthropic or OpenAI template):

```text
## Done when
- Only modify paths under: src/ and tests/ for this task
- Do not add dependencies, new packages, or new top-level folders
- Run: <exact test command> and <exact lint command>
- If the request is ambiguous in a way that changes the design, ask one question and wait
- Stop after the request is met; do not also improve nearby code
```

## Keep the file under the product size cap

Validate that a draft constraints file stays small before you paste a bigger one:

```bash
python3 - <<'PY'
sample = '''## Scope
- Edit only files under src/
- No new dependencies
## Done when
- pytest -q passes for tests/ touched
- Do not refactor unrelated modules
'''
print('lines', sample.count('\n')+1)
print('bytes', len(sample.encode()))
assert len(sample.encode()) < 32*1024
print('under_codex_default_cap OK')
PY
```

You should see a small line count, a byte count under 32768, and `under_codex_default_cap OK`. Claude Code's under-200-lines target is separate guidance for `CLAUDE.md` [1]. Codex's 32 KiB default caps the combined size of the instruction files it loads, and you can raise it [3].

## Catch vague rules before they ship

Claude Code best practices warn that if you fix every review finding, you end up with extra abstraction layers and tests for cases that can't happen [2]. The `CLAUDE.md` docs say that if two instructions contradict each other, Claude may pick one arbitrarily [1]. If a line keeps getting ignored, either the file has grown long enough that the line gets lost, or the rule belongs in a hook [2].

Pair this page with Part 1 for the paste-ready stop block and the bloated-vs-small diff review [how to stop an AI coding agent from over-engineering](/blog/stop-ai-coding-agent-over-engineering). For the loop definition behind these tools, see [what is an AI agent](/blog/what-is-an-ai-agent).

Paste the four cards, keep the file short, and reject the next diff that invents work outside the request.

Send this to the friend whose coding agent keeps editing files it was never asked to touch.

Image: Four constraint cards for a coding agent, titled Four constraints that stay small. 01 Paths: only edit listed folders. 02 Forbidden: no new dependencies, no new top-level folders, no drive-by refactors. 03 Verify: give the exact test and lint commands. 04 Done when: request met, checks pass, then stop; ask before changing the design. Footnote: CLAUDE.md under 200 lines per file; Codex AGENTS.md files 32 KiB combined by default; checked 2026-11-12.
https://fullbytedeveloper.com/media/constrain-ai-coding-agent-scope/constraint-cards.webp
Four constraints to write down before the agent starts. A coding agent treats these as guidance, not a lock.

Image: A code panel titled A teaching AGENTS.md excerpt, labeled as a teaching example and not an official vendor template. The file lists Paths (edit src/ and tests/; do not edit .github/, infra/, or package-lock.json), Forbidden (do not add dependencies or create new top-level folders), Verify (npm test and npm run lint), and Done when (the request is met, then stop, and ask before changing the design).
https://fullbytedeveloper.com/media/constrain-ai-coding-agent-scope/agents-md-excerpt.webp
A short, generic AGENTS.md you can adapt. This is a teaching example, not an official vendor template.

## Sources

1. [Claude Code: CLAUDE.md, accessed 2026-11-13](https://code.claude.com/docs/en/claude-md)
2. [Claude Code best practices, accessed 2026-11-13](https://code.claude.com/docs/en/best-practices)
3. [OpenAI: AGENTS.md guide, accessed 2026-11-13](https://learn.chatgpt.com/docs/agent-configuration/agents-md)
4. [OpenAI Codex best practices, accessed 2026-11-13](https://learn.chatgpt.com/guides/best-practices)
5. [Anthropic: Claude prompting best practices, accessed 2026-11-13](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/claude-prompting-best-practices)
