AI coding agents are only as good as the context you give them. Without guidance, an agent guesses your build system, invents conventions, and edits files it should never touch. An AGENTS.md file fixes that: it is a short, structured document at your project root that tells any compatible agent how your project works, which commands to run, and what to avoid.
This guide shows how to write an AGENTS.md that actually helps, with a template for Linux server projects, rules for keeping it maintained, and guardrails that protect production systems.

What AGENTS.md Is and Why Agents Read It
AGENTS.md is an open convention, supported by a growing set of coding agents, for placing agent instructions in a repository. When an agent starts work in a directory, it looks for AGENTS.md (and nested ones in subdirectories) and treats the contents as standing instructions for that project, similar to how a human contributor reads a README and CONTRIBUTING file before their first commit.
The value is leverage: every instruction you write once is applied to every future agent session, instead of being re-explained in each prompt. For server projects, where a wrong command can restart a service or delete data, that leverage is also a safety mechanism.
Prerequisites
- A project directory on a Linux server or workstation, ideally under version control with Git.
- An AI coding agent that reads AGENTS.md, such as Claude Code, Codex, or a compatible editor agent.
- Knowledge of your project’s build, test, and deploy commands.
Step 1: Create the File in the Right Place
Put AGENTS.md at the repository root so every agent session finds it:
cd ~/projects/myserver-tool
touch AGENTS.md
ls -la
Large monorepos can add nested AGENTS.md files in subdirectories for area-specific rules. The agent reads the root file first, then the nearest nested file for the directory it is working in, with more specific rules taking precedence.
Step 2: Write the Core Sections
A useful AGENTS.md for a server project covers five things and fits on one or two screens. Here is a template:
# AGENTS.md — myserver-tool
## Project overview
A Bash toolkit for managing nftables firewall rules on Debian and
Ubuntu servers. Entry point: `nft-manager.sh`. No web UI, no daemon.
## Build, test, and run
- Lint shell scripts before committing: `shellcheck nft-manager.sh`
- Run the test suite (safe, uses a network namespace):
`sudo ./tests/run.sh`
- Never run the full test suite on a production host; it flushes
firewall rules inside its own namespace only, but verify with
`ip netns list` first.
## Code conventions
- POSIX sh compatible; no bashisms. Target `/bin/sh`.
- Functions use lowercase names with a `nftm_` prefix.
- User-visible strings are plain ASCII unless NFTM_UTF8=1 is set.
- Keep functions under 50 lines; split larger ones.
## File layout
- `nft-manager.sh` — main menu and entry point.
- `lib/` — rule builders, one file per feature.
- `tests/` — bats tests, run inside a network namespace.
## Safety rules (do not skip)
- Never run commands that flush all firewall rules on the host.
- Never delete files outside the project directory.
- Never paste credentials, tokens, or private keys into code, logs,
or commit messages.
- Ask before restarting a service, changing a firewall rule on a
live host, or installing a package.
Notice what the file does not contain: a wall of prose, restated documentation, or aspirational rules nobody follows. Every line either saves the agent a guess or prevents a class of mistake.
Step 3: Make Commands Copy-Paste Ready
Agents execute commands literally, so write them exactly as they should run, including the working directory and any required environment variables. Compare a vague instruction with a precise one:
- Vague: “Run the tests before committing.”
- Precise: “Run
sudo ./tests/run.shfrom the repository root; it takes about 30 seconds and must exit 0.”
The precise version tells the agent where to run, how long to wait, and what success looks like. Add the same precision for build commands, deployment steps, and database migrations.
Step 4: Encode Guardrails, Not Just Conventions
For server projects, the safety section matters more than the style section. List destructive operations explicitly, and state the approval rule for each:
- Read-only by default: inspecting logs, configs, and system state needs no approval.
- Ask first: restarting services, changing firewall rules, installing packages, modifying databases.
- Never: flushing all firewall rules, deleting data outside the project, disabling authentication, or committing secrets.
Also record environment quirks the agent cannot discover by reading code: a broken default PHP binary, a host that reads SSH keys from an unusual path, or a proxy required for outbound traffic. One line about a quirk saves an entire debugging session.
Step 5: Keep AGENTS.md Maintained
An AGENTS.md file rots like any documentation. Review it whenever the project changes structurally: a new build tool, a moved directory, a changed deploy process. Three habits keep it fresh:
- Update it in the same commit as the change it describes, not in a later cleanup pass that never happens.
- Delete rules that no longer apply. Stale instructions are worse than missing ones, because the agent follows them confidently.
- Ask the agent to flag contradictions. When an agent reports that AGENTS.md disagrees with the code, treat that as a bug report, not an annoyance.
Keep the file short. If it grows past about 150 lines, split detailed references into docs files and link them from AGENTS.md, keeping only the rules and commands in the main file.
Troubleshooting AGENTS.md Problems
The agent ignores the file
Confirm the agent supports the convention and that the file sits at the repository root with exactly the name AGENTS.md. Some tools also read .claude/CLAUDE.md or similar tool-specific files; if your agent uses one, keep AGENTS.md as the canonical file and symlink or mirror the tool-specific one.
The agent follows outdated rules
Check for nested AGENTS.md files overriding the root file in the directory the agent is working in. Also check whether the agent cached an older version of the file at session start; long sessions may need a restart to pick up edits.
Instructions conflict with each other
Resolve conflicts by specificity: a rule in a nested file beats the root file, and a direct user instruction in the current prompt beats both. When you spot a conflict, fix the file immediately so the next session inherits the correction.
Conclusion
A good AGENTS.md is short, precise, and safety-aware: project overview, exact commands, conventions, file layout, and explicit guardrails. Write it once, update it with every structural change, and let every agent session benefit from the context you would otherwise repeat by hand. For related automation, see our guide to building an AI agent with LangChain on Linux and generating a daily server report with an LLM and cron. The open AGENTS.md specification documents the format and how agents discover these files.