You told the agent "use pnpm, not npm" on Monday. On Tuesday it ran npm install again, because that rule lived in a chat that no longer exists.

Instruction files fix that, but every tool reads them a little differently. These are the CLAUDE.md, AGENTS.md and rules-file tricks I wish I'd known on day one, all checked against the official docs this week.

Start smaller than you think

1. Run /init, then delete half of it

In Claude Code, /init scans the repo and writes a starting CLAUDE.md with build commands and conventions it found (docs). The docs suggest keeping each CLAUDE.md under 200 lines, since longer files cost more context and get followed less consistently. On a Mac, wc -l CLAUDE.md tells you where you stand.

2. Only write down what you'd otherwise repeat

The same docs give a simple trigger: add a line when the agent makes the same mistake twice or you type the same correction you typed last session. "Use pnpm" earns a spot. A paragraph about your architecture philosophy usually doesn't.

One file for every agent

3. Make AGENTS.md the shared source

AGENTS.md is a plain markdown format that Codex, Cursor and GitHub Copilot all read, and recent Claude Code versions (v2.1.277 and later) read it too when the repo has no CLAUDE.md. One file at the repo root covers most of the agents you'll run on a Mac.

4. Keep a CLAUDE.md? Import AGENTS.md instead of copying it

If you need Claude-only notes, put @AGENTS.md on its own line in CLAUDE.md. Claude Code expands @path imports (up to four hops deep), so the shared rules stay in one place and never drift into two slightly different copies.

5. Watch out for CLAUDE.local.md

CLAUDE.local.md is the gitignored file for personal preferences like your sandbox URL. The catch from the docs: if it exists, Claude Code stops reading AGENTS.md by default, unless you set Project instructions to claude-md-and-agents-md in /config.

Load rules only where they matter

6. Scope Claude rules by path

Files in .claude/rules/ can start with a paths: frontmatter list, like "src/api/**/*.ts", and they load only when Claude reads or edits a matching file. Your API conventions stop taking up context while you're fixing CSS.

7. Cursor rules need .mdc, not .md

Cursor project rules live in .cursor/rules and must use the .mdc extension; a plain .md file there is ignored by the rules system. The frontmatter (alwaysApply, description, globs) decides whether a rule is always on, picked by relevance, attached to matching files, or only used when you @-mention it.

8. Keep an eye on what all that context costs

Every always-loaded instruction file rides along in every session, and retries add up fast when an agent ignores a rule. TokenBar is a Mac menu bar app (macOS 14+) that shows usage and reset times for Claude, Codex, Cursor, Gemini and Copilot, so you can see how fast a session is burning before deciding what to trim. It's $5 a month for Basic or $15 once for Pro lifetime, gives no extra quota, is built on Peter Steinberger's MIT-licensed CodexBar, and credits Pixel Agents. (Disclosure: TokenBar is made by the team behind this account.)

TokenBar spend overview window on a Mac with Codex, Claude, Cursor and Gemini listed in a provider sidebar, usage today and 30-day cost cards, a 30-day top model chart for gpt-5, and a system load row for CPU, memory, energy and heat

9. Codex: nest overrides and mind the 32 KiB cap

Codex walks from the repo root down to your working directory and joins one instruction file per folder, so the closest one wins. An AGENTS.override.md in services/payments/ replaces that folder's AGENTS.md, and the combined text stops at project_doc_max_bytes, which is 32 KiB by default.

Other agents, same files

10. Copilot: path-specific instruction files

Besides .github/copilot-instructions.md, Copilot reads NAME.instructions.md files under .github/instructions with an applyTo glob like "**/*.ts,**/*.tsx" (GitHub docs). Add excludeAgent: "code-review" if a file should only guide the cloud agent.

11. Gemini CLI: point it at AGENTS.md

Gemini CLI looks for GEMINI.md by default, but context.fileName in settings.json accepts a list such as ["AGENTS.md", "GEMINI.md"] (docs). Run /memory show to see the exact combined context it's sending.

Keep the files honest

12. Hide notes from the agent, then audit for contradictions

Block-level HTML comments in CLAUDE.md are stripped before Claude sees them, so <!-- why we pin Node 20 --> helps teammates without costing context. Every so often, run /doctor prompt-audit (Claude Code v2.1.283+) to flag stale or conflicting instructions; it proposes edits and changes nothing until you say so. For anything that must never happen, the docs point to a PreToolUse hook, because instruction files are context, not enforcement.

Which agent in your setup ignores its instruction file the most, and what finally made it listen?