Give an AI coding assistant useful repository instructions

Write reusable repository rules for Codex or GitHub Copilot, scope exceptions, and verify that the instructions reach the task and shape its changes.

Blue project folders and a short instruction sheet in a graphite file organizer

Put reusable project rules in an instruction file your coding assistant supports, then check that the file reaches a new session and affects the resulting work. Start with the repository's existing guidance and a few concrete conventions. I'd fix the file's location or scope before adding more instructions: a clear rule can't help a request that never receives it.

Choose the file for your assistant and working folder

Identify the assistant running the session, the editor or terminal you're using, and the repository folder it has open. In VS Code, the selected agent determines instruction support. Selecting a Claude model inside a Copilot session doesn't turn that session into Claude Code.

Look for existing instruction files before creating one. Preserve guidance maintained by other contributors, and review any proposed replacement as a change to the project. A copied template can introduce a different package manager or obsolete command even when its formatting looks sensible.

  • Codex: use AGENTS.md at the repository root for shared project guidance. Codex also has global guidance and directory-specific files, described below.
  • GitHub Copilot Chat in VS Code: .github/copilot-instructions.md supplies repository-wide guidance. VS Code Copilot also supports AGENTS.md, but check the active client's discovery rules before sharing a file across tools.

Plain project instruction files contain Markdown and don't need YAML frontmatter. The header used for Copilot's targeted .instructions.md files serves a different purpose. Support also varies between Chat, cloud agent, and code review; use GitHub's client-and-feature support table when moving the same guidance to another environment.

Write rules the repository can support

Read the project's current setup documentation, dependency manifests, and lockfile. Name the installed framework version when it changes the API the assistant should use. Find the existing implementation that demonstrates the convention you want repeated. Confirm the verification command with the project's documented workflow; don't copy a command from another project's template.

A useful rule names a decision the assistant would otherwise have to guess. “Keep the architecture clean” gives little direction. “Route handlers call the existing storage module instead of opening database connections” identifies a boundary you can inspect. Add the real module path so the assistant can find the example.

Here is a constructed example for a Python service with HTTP handlers in app/http/, storage helpers in app/storage/, and unit tests in tests/unit/. It uses pytest's documented directory selection and Python module invocation. Replace the example paths and command with verified details from your repository before using the file.

# Project instructions

- Add HTTP handlers under app/http/ and reuse app/storage/ for storage access.
- Preserve existing response fields unless the requested change names them.
- After changing behavior, update the relevant unit tests and run
  python -m pytest tests/unit/ from the repository root.
- Report the check command, its result, and any check that couldn't run.
- Keep unrelated files and other contributors' edits intact.

Keep today's feature request in the task prompt. A deadline, a particular button label, or the acceptance criteria for one bug fix can change independently of the repository's standing conventions. The brief for a single coding task helps separate that request from persistent project guidance.

I'd keep the shared file focused on decisions that need explanation. Let an existing formatter enforce formatting. Put a long specialist procedure in a separate document or supported reusable skill, while keeping essential rules in the instruction file. A Markdown link alone doesn't ensure the linked document reaches every request; attach an essential document or ask the assistant to read it and inspect the resulting evidence.

Leave credentials and private production data out of shared instructions. A sentence prohibiting access doesn't remove a tool's permissions. Use the project's access controls for that boundary, and review instruction changes through the same source-control process as other project changes.

Scope exceptions using the tool's own rules

Keep conventions that apply everywhere in the main file. Add narrower guidance when a directory genuinely needs different handling, such as a service with its own checks. Avoid maintaining two contradictory copies of the same rule.

Codex: check the session's working directory

Codex builds its instruction chain at startup. It reads global guidance from its Codex home, then searches from the project root down to the session's current working directory. Without a project root, it checks only the current directory.

Along that project path, Codex checks AGENTS.override.md, then AGENTS.md, then configured fallback filenames. It includes at most one instruction file from each directory. More specific guidance appears later in the combined instructions and overrides earlier project guidance. The default combined project-instruction limit is 32 KiB, controlled by project_doc_max_bytes.

For example, a repository-root AGENTS.md can describe shared conventions while tests/AGENTS.md adds testing guidance. Start a new Codex session with tests as its working directory to include that nested file in the native discovery chain. Opening a test file in the editor doesn't change the session's working directory. The example's repository-root test command would also need an explicit instruction to run from the root if the session starts inside tests.

If an override is masking the file you expected, inspect the override before changing it. Preserve the original and resolve the conflict with the people maintaining that guidance. Restart the session after changing the relevant files or configuration, then confirm the active sources again.

Copilot in VS Code: match the files being worked on

For path-specific Copilot instructions, create a file such as .github/instructions/python-tests.instructions.md. GitHub documents that matching path instructions and repository-wide instructions are both used. A testing rule should therefore remain compatible with the shared file.

This header scopes an instruction file to Python files under a root-level tests directory:

---
applyTo: "tests/**/*.py"
---

The pattern matches tests/test_app.py and tests/unit/test_app.py, but not src/app.py. Patterns are relative to the workspace or project root, using / separators across operating systems. Add the actual testing rules below the header. Don't put this Copilot-specific activation header in a Codex file and expect the same behavior.

There is no instruction precedence order that applies across every assistant. Resolve contradictory personal, repository, and organization rules at their sources, then repeat the relevant check. Adding an emphatic “always” to another copy leaves the conflict in place.

Verify discovery, inclusion, and the resulting work

Use a small, reversible task in an authorized working copy where the rule changes a visible decision. Preserve existing work and keep the test session in the folder containing the instruction changes. Review the proposed edits before committing them.

  1. Check discovery. In VS Code, run Chat: Open Customizations from the Command Palette and look in Instructions. For native Codex, start from the intended directory and ask it to identify the active instruction sources. Compare the named paths with the expected discovery chain.
  2. Check inclusion in a fresh session. Keep the same assistant and folder, then start a new chat or session. Ask for a representative change without repeating the standing rules. In Copilot Chat, inspect the response's References list where available. GitHub explains that the instruction file appears there when it was added to the request.
  3. Check behavior. Inspect the actual files and tool activity. In the constructed service example, the handler belongs in app/http/, storage access should reuse app/storage/, and the reported test result needs actual command output. An instruction summary or a promise to run checks doesn't establish any of those outcomes.
GitHub Copilot expanded references with copilot-instructions.md highlighted
The instruction file in References confirms inclusion in the request. Review the resulting changes separately. View larger image.

VS Code distinguishes discovering a file from including and following it. A file listed in the editor proves discovery. A reference helps establish inclusion. Review of the changed files and check output establishes whether this particular task followed the relevant rules. Keep tests, code review, and permission controls in place.

If a check can't start because its environment is missing a dependency, that check hasn't verified the change. Resolve the prerequisite using the project's approved setup, then rerun the check. Keep the failed attempt and the later result distinct when deciding whether the instruction worked.

Repair the failed stage and keep the file current

File missing from discovery: check the selected assistant, exact filename, supported location, and working folder. In Codex, inspect the root-to-working-directory path, empty files, overrides, configured fallback names, and the combined size limit. Confirm which Codex home the session uses if its global guidance differs from your expectation.

File found but absent from the request: check the targeted file pattern and header syntax. Confirm the client and feature support that instruction type. A supported manual attachment can help a particular request, but it doesn't prove automatic activation is fixed.

File included but the result breaks the rule: identify the conflicting or ambiguous instruction. Name the real path, command, or preserved behavior more clearly, then repeat the representative task in a new session. Verify a linked document was read when the decision depends on it. Don't expand the entire file to compensate for one unclear requirement.

Review the instruction diff, save it with the repository through the normal contribution process, and update it whenever its commands or architectural assumptions change. After changing tools or working folders, repeat the discovery and inclusion checks. Accept the resulting code only after reviewing the actual change and its verification evidence.