AI Summary:
CLAUDE.mdis the specialized operational scratchpad for Anthropic's Claude Code CLI, optimized for shell shortcuts, test suites, and terminal-specific subagent memory. In contrast,AGENTS.mdacts as the universal repository constitution governing multi-agent interactions across any editor, IDE, or CI pipeline.
With the release of Anthropic's Claude Code (an autonomous, terminal-native agent capable of directly executing shell commands, file edits, and git operations), developers gained an extraordinary tool for codebase manipulation. Claude Code automatically looks for a CLAUDE.md file upon initialization in any directory.
However, many engineering teams mistakenly duplicate their architectural guidelines across both CLAUDE.md and AGENTS.md, creating maintenance debt and conflicting rules.
Understanding how to structure and separate these two manifests is essential for high-performance agent workflows.
Functional Differentiation Matrix
| Characteristic | CLAUDE.md (Terminal Agent Memory) | AGENTS.md (Universal Constitution) | Architectural Purpose |
|---|---|---|---|
| Target Runtime | Claude Code CLI (claude) in terminal environments | Universal (Cursor, Claude Code, Cline, Codex, Operator) | Runtime environment scope |
| Execution Primitives | Shell aliases, test commands, compact lint flags | Architecture patterns, schema contracts, hard boundaries | Execution verbs vs governance rules |
| Memory Lifespan | Updated interactively via /learn or /init | Curated, versioned via pull requests by human leads | Dynamic memory vs immutable law |
| Scope of Authority | Operational efficiency for command line runs | Hard negative constraints across all contributors | Local performance vs global safety |
| Token Budget | Highly compact (under 1,000 tokens recommended) | Comprehensive (under 2,500 tokens) | Minimizing prompt overhead on every turn |
| Tool Calling Hints | Custom bash commands, subagent spawn triggers | Coding conventions, directory invariants, API schemas | Tool invocation speed |
The Role of CLAUDE.md: Operational Velocity
Claude Code operates directly against your machine's shell. It does not possess a graphical user interface; it perceives your repository through tool calls: Bash, GlobTool, FileEdit, and GrepTool.
Therefore, CLAUDE.md must be engineered as an Operational Cheat Sheet. It tells the agent the exact flags to run so it does not waste turns guessing your package manager or test framework:
# CLAUDE.md: Operational Cheatsheet
## Primary Commands
- Build: `pnpm build`
- Fast Unit Test: `pnpm test --run --filter=core`
- Full E2E Test: `pnpm exec playwright test --workers=3`
- Lint & Fix: `pnpm lint --fix`
- Typecheck: `pnpm tsc --noEmit`
## Shell Guardrails
- Never run `rm -rf` on root directories.
- Always run `git status` before committing changes.
- If a test fails due to port 3000 collision, use `PORT=3001`.
## Architectural Reference
- For repository invariants and code standards, strictly follow AGENTS.md.
Notice how concise this is. It takes fewer than 300 tokens, loads instantaneously into the Claude Code prompt, and eliminates trial-and-error shell executions.
The Role of AGENTS.md: Architectural Governance
While CLAUDE.md focuses on how to run commands, AGENTS.md focuses on how to write software in this specific repository. It defines architectural invariants that apply whether the code is being written by Claude Code in a terminal, Cursor in a desktop window, or an external contractor using VS Code:
# AGENTS.md: Repository Governance
## Non-Negotiable Invariants
1. Single Source of Truth: All database mutations must pass through `src/services/db.ts`. Direct SQL queries inside UI routes are strictly prohibited.
2. Error Handling: Never use empty catch blocks (`catch (e) {}`). All errors must be wrapped in `AppError` and logged with a correlation ID.
3. Test Coverage: Every new API route in `src/app/api/` must have a corresponding integration test in `tests/api/`.
Symbiotic Integration Pattern
To avoid drift, production repositories link CLAUDE.md directly to AGENTS.md:
[Repo Root]
├── AGENTS.md <--- Authoritative Rules (Read by all agents)
└── CLAUDE.md <--- Points to AGENTS.md + Adds Terminal Commands
When Claude Code initializes, it reads CLAUDE.md, learns the exact shell commands needed to build and test the project, and is explicitly directed to respect the invariants in AGENTS.md.
Security Best Practices and Hard Negative Constraints
- Never Store Secrets or API Keys in CLAUDE.md: Even though
CLAUDE.mdresides in your repository, never put production credentials or tokens in it. Use environment variables. - Do Not Allow Claude to Auto-Overwrite AGENTS.md: Use branch protection rules so that an autonomous agent cannot arbitrarily rewrite
AGENTS.mdvia pull requests without human review. - Keep Commands Deterministic: In
CLAUDE.md, avoid interactive commands (likepnpm initor commands that prompt for user input), as they will hang terminal subagent execution loops.
Need to optimize your entire site for AI search visibility? Run a comprehensive audit with Geolify AI.
References
- Anthropic Claude Code Overview: Official documentation for the Claude Code research preview CLI.
- AGENTS.md Specification Proposal: Emerging community standard for vendor-neutral agent governance.
- CommonMark Specification: Standard for Markdown syntax parsing across terminal tools.