Kanji
・Cloud engineer / freelance ・Born in 1993 ・From Ehime / Living in Shibuya, Tokyo ・5 years AWS experience Profile details
Table of Contents
In my daily software engineering workflow, I orchestrate multiple AI coding agents side-by-side—Google Antigravity, Anthropic Claude Code, Kiro, and OpenAI Codex. Yet, the single most frustrating bottleneck I repeatedly encountered was “rule definition collapse and prompt drift across agent harnesses.”
Initially, I assumed that writing comprehensive coding guidelines and safety constraints into a single AGENTS.md or CLAUDE.md would allow every tool to behave intelligently. However, as my projects expanded into enterprise-scale multi-repo architectures, I ran into severe operational failure modes:
AGENTS.md
CLAUDE.md
git push origin main
In this deep dive, I share the hard-won architectural patterns that resolved these pain points across all four major AI agents.
We will delineate what constitutes the Universal Foundation (open standards that apply everywhere) versus the Specialized Superpowers (vendor-specific extensions) , culminating in a robust, production-tested Federated Rules Architecture .
Engineers frequently stumble into three classic traps when authoring agent instructions.
Attempting to document test conventions, commit message formats, deprecated library versions, and cloud IAM policies in a single root instruction file.
Because agents inject this entire document into the prompt window on every single tool call, a 1,000-line monolith drains your token budget and saturates the model’s attention mechanism, exponentially increasing instruction neglect.
Maintaining separate CLAUDE.md and AGENTS.md files by manual copy-pasting. Inevitably, one gets updated while the other remains stale, leading to conflicting instructions and code regressions.
Relying solely on descriptive natural language text to prevent high-risk operations ( “Do not execute dangerous commands” ). Because LLMs are probabilistic, prompts get overridden during complex multi-step reasoning. Critical constraints must be mechanically enforced via hooks, permissions, or sandboxes—never polite prose.
Here is how the four major coding agents process and load operational rules:
~/.gemini/config/rules/*.md
<repo>/AGENTS.md
~/.kiro/steering/*.md
.kiro/steering/*.md
~/.claude/rules/*.md
~/.codex/AGENTS.md
AGENTS.override.md
config.toml
glob
model_decision
manual
#[[file:...]]
@path/to/file
settings.json
Regardless of which tool you use, three architectural principles remain universal:
Following /etc/ → ~/.config/ → ./ , agent instructions must cascade from broad to granular, where local workspace settings strictly override global configurations :
/etc/
~/.config/
./
~/.gemini/config/rules/
~/.claude/rules/
./AGENTS.md
./src/api/AGENTS.md
Target under 150--200 lines for root AGENTS.md files. Apply the litmus test to every sentence: > “If I delete this line, will the agent make a catastrophic or unrecoverable error?”
Prune anything that linters, formatters, or typecheckers enforce automatically. Keep only non-obvious project idiosyncrasies and exact build commands.
Never embed lengthy deployment runbooks or multi-step migration scripts inside rule files: - Rules ( AGENTS.md ) : Invariant constraints, boundaries, and evaluation criteria. - Skills ( SKILL.md ) / Runbooks : Operational step-by-step procedures loaded on-demand only when triggered.
SKILL.md
Even when teams understand the 3-tier cascade, the most common engineering stumbling block is scoping boundary design : “Exactly which instructions belong in global user config, and which belong inside the repository?”
Confusing this boundary leads to disastrous cross-contamination—such as an agent accidentally deploying a personal test app to a corporate client’s AWS account, or leaking local Mac file paths into public GitHub CI builds.
Here is the production scoping boundary matrix I enforce across all enterprise agent workflows:
~/.gemini/...
./.agents/...
です/ます
features/
components/
/tmp
npm run build
pytest
npm run dev
tsc --noEmit
ruff check
SPONSORED
feat:
fix:
develop
main
When these boundaries blur, agents inevitably introduce subtle bugs and operational friction:
Hardcoding project-specific identifiers—such as AWS_PROFILE=client-prod or absolute paths like /Users/user01/workspace/client-a/... —into global configuration files ( ~/.gemini/config/rules/ or ~/.claude/rules/ ). When switching to a personal repository or a different client’s codebase, the agent unconsciously attempts to invoke client A’s credentials, causing permission failures or, worse, deploying code into the wrong infrastructure .
AWS_PROFILE=client-prod
/Users/user01/workspace/client-a/...
Committing local machine paths ( file:///Users/kanji/... ), private SSH aliases, or personal credentials directly into a repository’s AGENTS.md . The moment CI/CD (GitHub Actions), Docker containers, or Windows teammates pull the repository, automated pipelines immediately crash due to missing paths, while private machine configurations leak permanently into git history .
file:///Users/kanji/...
Stuffing specialized best practices for every conceivable technology (Next.js, Python, Terraform, Docker, Go, Rust, Tailwind) into global rules because “they might come in handy.” The agent gets loaded with 10,000+ tokens of irrelevant rules at the start of every session—even for a simple one-line shell script— choking its attention window and drastically increasing the likelihood of hallucination .
Whenever you write a new rule, run it through these two quick tests:
When a rule applies across multiple projects but is only relevant during specific tasks (e.g. Terraform naming conventions), use Antigravity’s trigger: glob: "**/*.tf" or Kiro’s Conditional Steering. This stores the rule globally while injecting it into context only when matching files are actively opened .
trigger: glob: "**/*.tf"
Once the universal foundation is in place, you can leverage vendor-specific features for maximum leverage.
Antigravity’s standout capability is fine-grained frontmatter triggering in ~/.gemini/config/rules/*.md :
--- trigger: glob globs: "**/*.tf, **/*.tfvars, infra/**/*.yaml" description: Terraform naming conventions and provider requirements --- # Infrastructure Rules - Resource names must include environment prefixes (prd, stg, dev).
Using glob and model_decision , frontend coding tasks are never polluted by heavy infrastructure or migration rules.
Kiro enables embedding dynamic file contents directly into steering documents without code duplication:
# API Response Contract All error payloads must strictly comply with our central schema: #[[file:src/types/api_errors.ts]]
When the underlying schema updates, the agent’s steering context automatically synchronizes. Furthermore, /context show allows real-time inspection of active context.
/context show
When CLAUDE.md exists at the repository root, Claude Code prioritizes it over AGENTS.md . While macOS and Linux engineers often resort to a quick local symlink ( CLAUDE.md -> AGENTS.md ), this introduces a catastrophic failure mode in multi-platform or enterprise team environments.
CLAUDE.md -> AGENTS.md
On Windows machines, Git disables symlinks by default ( core.symlinks = false ). When a Windows developer clones a repository containing a symlink, CLAUDE.md is materialized not as a valid link, but as a plain 9-byte text file containing the literal string "AGENTS.md" . Claude Code silently ingests this 9-byte stub as the entire instruction set without throwing any warnings— effectively stripping every safety rule and architectural guideline in total silence.
core.symlinks = false
"AGENTS.md"
The Native @AGENTS.md Inclusion Syntax (Recommended) Commit CLAUDE.md as a lightweight plain text file starting with an @ import directive:
@AGENTS.md
@
@AGENTS.md # Claude-Specific Directives - (Append Claude-only behaviors or specialized subagent roles here)
Because it is standard markdown text, it works deterministically across Windows, macOS, Linux, and containerized CI runners.
Zero-Config Fallback (Omit CLAUDE.md Entirely) Claude Code natively falls back to parsing AGENTS.md whenever CLAUDE.md is absent. If your project does not require Claude-specific prompts, keeping a solitary AGENTS.md file is the cleanest zero-maintenance pattern.
Additionally, enforce non-negotiable boundaries mechanically via deterministic PreToolUse hooks in .claude/settings.json rather than polite prose:
.claude/settings.json
{ "hooks": { "PreToolUse": [ { "matcher": ".*", "hooks": [ { "type": "command", "command": "python3 scripts/secret_guard.py" } ] } ] } }
Production Gotcha 1: Avoid the PreToolUse Hook “Self-Lockout Trap” When scanning for secrets (e.g. OpenAI/Anthropic keys) in pre-tool execution hooks, using naive patterns without word boundaries (like sk-[A-Za-z0-9_-]+ ) will trigger false positives on kebab-case markdown text (e.g. risk-assessment-workflow... ). Exiting with code 2 on these false alarms causes Claude Code to block all subsequent tools —locking the agent in a loop where it cannot even read or edit files to fix the issue. Always enforce strict word boundaries ( \b ) and ensure local development .env files and test mocks are safely bypassed in a fail-open design.
sk-[A-Za-z0-9_-]+
risk-assessment-workflow...
\b
.env
Production Gotcha 2: Guarding Against Overwrite Accidents ( install.py ) When distributing standardized rule packs across an engineering organization, manual cp commands frequently overwrite existing team members’ AGENTS.md or CLAUDE.md without warning. Using an automated installer script ( install.py ) that backs up existing rules to .bak before writing ensures smooth, conflict-free adoption.
install.py
cp
.bak
In large monorepos, Codex allows isolating sub-packages by placing AGENTS.override.md . This halts parent directory traversal, giving the agent a clean, uncluttered context slate. Note Codex’s 32 KiB default limit ( project_doc_max_bytes in config.toml ) to avoid silent truncation.
project_doc_max_bytes
Here is the standardized repository layout I use to orchestrate all four agents without conflict:
my-project/ ├── AGENTS.md # [SSOT] Universal core rules (< 200 lines) ├── CLAUDE.md # Claude-specific (@AGENTS.md import, 100% Windows-safe) ├── .kiro/ │ └── steering/ # Kiro-specific file-match rules & #[[file:...]] ├── .gemini/ (or global) │ └── rules/ # Antigravity glob & model_decision rules ├── .codex/ │ └── config.toml # Codex byte limits & sandbox policies └── .agents/ └── hooks.json # PreToolUse / PostToolUse deterministic guardrails
Managing AI agent guidelines has evolved beyond casually tossing reminders into a prompt box.
By anchoring your setup in these 5 pillars, you eliminate agent regressions and prompt fatigue, unlocking a truly predictable, high-velocity multi-agent engineering workflow.
Get the complete configuration pack featured in this article: universal AGENTS.md, deterministic hooks.json, Git safety guardrails, and validation scripts tested across Antigravity, Kiro, Claude Code, and Codex.
Powered by the frontier LLM orchestration and automated pipelines featured on this blog. Daily quantitative scoring, macro signals, and market analytics.
Hands-on engineering advisory for AI coding agent standardization, hybrid LanceDB/SQLite memory hubs, and AWS / Google Cloud infrastructure modernization.