Repository Layout & Setup

Recommended repository structure and setup checklist for implementing token optimization across all five tools

Token Optimization Guide / Repository Layout & Setup
your-repo/
β”œβ”€β”€ AGENTS.md                   # canonical, cross-tool: conventions, commands, guardrails
β”œβ”€β”€ CLAUDE.md                   # Claude-Code-only additions (compaction guidance, subagent routing)
β”œβ”€β”€ GEMINI.md                   # Antigravity-only overrides (kept thin)
β”œβ”€β”€ .codex/agents/               # Codex subagent definitions (model/sandbox per role)
β”œβ”€β”€ .antigravity/agents/          # Antigravity subagent YAML definitions
β”œβ”€β”€ .claude/skills/               # Claude Code skills (progressive disclosure)
β”œβ”€β”€ .cursor/
β”‚   β”œβ”€β”€ rules/
β”‚   β”‚   β”œβ”€β”€ 000-project.mdc      # thin, always-apply, points back to AGENTS.md
β”‚   β”‚   └── 200-high-risk-paths.mdc  # scoped, glob-matched, loads only near risky code
β”‚   β”œβ”€β”€ agents/                   # Cursor subagent personas (review/verify/test)
β”‚   └── skills/                   # Cursor skills (or point at .claude/skills/)
└── playbooks/
    β”œβ”€β”€ dependency-upgrade.devin.md   # general SDLC: incremental dep upgrades, PR per risk group
    └── hugo-docs-check.devin.md      # narrower example: docs build + link check

AGENTS.md is the only file all five tools read natively or near-natively. Everything else exists purely to hold one tool’s extra, tool-specific capability β€” none of it should restate what’s already in AGENTS.md. That’s the drift-prevention mechanism: one canonical file for shared rules, thin or scoped tool-specific files layered on top.

Concrete File Examples

AGENTS.md - Canonical Cross-Tool Rules

# AGENTS.md β€” Canonical Project Rules

<!--
  Single source of truth, read natively (or near-natively) by Claude Code,
  Codex CLI, Antigravity CLI, and Devin CLI.

  Keep this file lean: every line here loads into every agent's context,
  every session, regardless of task. Anything task-specific, infrequently
  needed, or only relevant to one tool belongs in a Skill, a Playbook, or
  a tool-specific override file (CLAUDE.md, GEMINI.md) β€” not here.
-->

## Stack

- [Language/framework β€” e.g. TypeScript, Next.js 15 App Router]
- [Database / ORM]
- [Package manager] β€” state it explicitly; agents default to whichever is
  most common in training data if you don't.

## Commands

Run these before considering any task complete:

```bash
[lint command]
[test command]
[typecheck command]

Conventions

  • One responsibility per function/class/file. If a file exceeds roughly [300] lines or a function exceeds roughly [40] lines, split it before adding more β€” don’t append.
  • Keep dependency fan-out low: depend on an interface/abstraction rather than a concrete deep chain, so a small change doesn’t require pulling a wide dependency graph into context to verify.
  • [Naming conventions, export style, etc.]
  • Never modify files in [/legacy/ or other frozen paths].

Skills

See .claude/skills/, .codex/ skill config, .gemini/config/skills/ (or wherever each tool discovers them) for task-specific instructions β€” deployment, migrations, code review, release notes. This file intentionally does not duplicate skill content; it only points at where to find it.

Guardrails

  • Never force-push or rewrite shared git history without explicit confirmation.
  • Never commit secrets, credentials, or .env files.
  • Ask before running destructive database operations.
  • Stop and report on the first build/test failure rather than attempting speculative fixes.

### CLAUDE.md - Claude Code Specific Additions

```markdown
# CLAUDE.md β€” Claude Code Additions

<!--
  Shared conventions, commands, and guardrails live in AGENTS.md β€” Claude
  Code reads that file too. This file holds only what's specific to how
  Claude Code itself operates a session.
-->

See `AGENTS.md` for project conventions, commands, and guardrails.

## Compaction guidance

When compacting (`/compact`), preserve:

- Any failing test output and the diff that produced it
- Open TODOs and unresolved questions from the user
- The current task's acceptance criteria

Discard exploratory file reads that didn't lead to a change.

## Subagent routing

- Default subagent model: Haiku β€” for test runs, log triage, and doc
  lookups.
- Escalate to Sonnet only when the subagent's task requires code
  generation, not just retrieval or summarization.
- Reserve Opus for the primary session on architecture-level decisions.

## Session hygiene

- Before starting an unrelated task, prefer `/clear` over letting stale
  context linger through auto-compact.
- Flag any MCP server unused for two or more weeks for removal from this
  project's config β€” it still costs prefix tokens every turn even if
  nothing calls it.

## Effort

- Default to a lower `/effort` setting for routine edits; only raise it
  for multi-file refactors or architecture-level reasoning.

Key Pattern: Notice how CLAUDE.md starts with a pointer to AGENTS.md and only contains Claude-specific operational details (compaction, subagent routing, session hygiene). This avoids duplication while providing tool-specific guidance.

Tool-Specific File Examples

The previous sections contain detailed examples for:

  • Cursor .mdc rules: See Part V for 000-project.mdc and 200-high-risk-paths.mdc examples
  • Devin Playbooks: See Part IV for dependency-upgrade.devin.md example
  • Subagent configurations: Each tool’s section contains configuration patterns

File Purpose Summary

FilePurposeTool(s)Loading Behavior
AGENTS.mdCanonical cross-tool rulesAll 5 toolsAlways loaded (except Cursor scoped)
CLAUDE.mdClaude-specific additionsClaude CodeAlways loaded
GEMINI.mdAntigravity-specific overridesAntigravity CLIAlways loaded
.codex/agents/*.tomlCodex subagent definitionsCodex CLIPer-subagent configuration
.antigravity/agents/*.yamlAntigravity subagent definitionsAntigravity CLIPer-subagent configuration
.claude/skills/Claude Code skillsClaude CodeLoad on match
.cursor/rules/*.mdcCursor scoped rulesCursorGlob-based activation
.cursor/agents/*.mdCursor subagent personasCursorPer-subagent configuration
.cursor/skills/Cursor skillsCursorLoad on match
playbooks/*.devin.mdDevin workflowsDevin CLILoad on invocation

Setup Checklist

Initial Setup

  • Write AGENTS.md first: Conventions, build/test/lint commands, guardrails, a pointer to your skills index. Keep it lean β€” strip anything that reads like an auto-generated architecture overview or README duplication; agents can already read the README and discover file-level detail themselves.

  • Add CLAUDE.md with Claude-specific additions only, plus a one-line pointer to AGENTS.md. Don’t duplicate content that belongs in the shared file.

  • Add GEMINI.md with Antigravity-only overrides; confirm it isn’t also being loaded by a separate Gemini CLI install on the same machine (both write to ~/.gemini/GEMINI.md).

  • Confirm Devin’s read_config_from setting (~/.config/devin/config.json) has agents_standard: true so it’s actually reading your AGENTS.md.

Skills and Playbooks

  • Move any repeatable multi-step workflow into a Skill (Claude/Codex/Antigravity/Cursor) or a Playbook (Devin) instead of a paragraph in a Rules file. This is the primary mechanism for reducing token overhead through progressive disclosure.

  • In Cursor specifically, split any always-apply rule that’s grown past a screen or two into scoped .mdc rules with real globs β€” an always-apply rule that’s really only relevant to src/api/** is paying the always-loaded tax for no reason.

Model Configuration

  • Set per-subagent model tiers in each tool’s subagent config β€” not just the primary session model. Reserve expensive models (Opus, GPT-4, etc.) for high-value tasks, use cheaper models for routine operations.

Maintenance

  • Re-audit all five tools’ config quarterly. The biggest silent cost driver in these files isn’t any single bad line β€” it’s accumulated, never-pruned instructions nobody remembers adding.

  • Monitor for rule drift: Ensure tool-specific files don’t gradually accumulate content that belongs in AGENTS.md. The shared file should remain the single source of truth for cross-tool rules.

Common Pitfalls

Path Conflicts

  • Gemini CLI + Antigravity CLI: Both write to ~/.gemini/GEMINI.md, causing silent context pollution. Separate deliberately using ~/.gemini/AGENTS.md for shared rules.

Duplication

  • Copying content between AGENTS.md and tool-specific files: Defeats the purpose of having a shared canonical file. Reference AGENTS.md from tool-specific files instead of duplicating.

Always-Loaded Bloat

  • Over-sized always-apply rules: Especially problematic in Cursor where scoped rules are the native primitive. Split large always-apply rules into glob-matched scoped rules.

Missing Progressive Disclosure

  • Putting task-specific instructions in always-loaded files: Move these to Skills or Playbooks that load on-demand instead.

Assumed Parity

  • Assuming AGENTS.md parity across tools: Claude Code only gained AGENTS.md support in spring 2026 and still treats CLAUDE.md as richer for Claude-specific features. Don’t assume full parity.

Key Takeaways

  1. One Canonical Source: AGENTS.md is the single source of truth for cross-tool rules. Everything else should reference it, not duplicate it.

  2. Progressive Disclosure: Use Skills, Playbooks, and scoped rules to load instructions only when relevant. This is the primary token optimization mechanism.

  3. Tool-Specific Layers: Each tool has unique capabilities (Cursor’s scoped rules, Devin’s Playbooks, etc.). Leverage these rather than fighting against them.

  4. Regular Maintenance: Token optimization isn’t set-and-forget. Quarterly audits prevent the accumulation of redundant instructions.

  5. Model Tier Strategy: Per-subagent model routing is as important as file organization. Reserve expensive models for high-value tasks.

The concrete examples provided in this guide (AGENTS.md, CLAUDE.md, Cursor .mdc rules, Devin Playbooks) demonstrate these principles in action. Adapt them to your project’s specific needs while maintaining the core discipline: small always-loaded rules, large on-demand instructions.

Interactive Tools

Practical tools to help you think systematically, build better AI agents, and master prompt engineering.

Software Engineering Playbooks

Practical, End-to-End implementation guides for building Production-ready Software. Each playbook includes working code, architecture diagrams, and step-by-step instructions.

πŸ€–

Research Agent with Gateway

Build a production-ready AI research agent using Agent Gateway for unified traffic management, authentication, and observability across LLM providers.

Agent Gateway A2A Protocol Multi-Agent
πŸ”—

RAG Pipeline with Vector Database

Implement a complete Retrieval-Augmented Generation pipeline with vector embeddings, semantic search, and context injection for accurate AI responses.

RAG Vector DB Embeddings
πŸ”„

Multi-Agent Orchestration

Create a coordinated multi-agent system with specialized agents, task distribution, and result synthesis for complex problem-solving.

Orchestration Task Distribution Synthesis
1 / 2

Future References

Explore these resources for deeper learning on AI agent development, spec-driven development, and prompt engineering tools.

Spec-Driven Development

Comprehensive guide on Spec-Driven Development practices and methodologies.

Awesome Copilot

Curated list of GitHub Copilot resources, extensions, and best practices.

Promptfoo

Tool for testing, evaluating, and improving LLM prompts and applications.

Prompts.chat

Collection of prompt engineering resources and templates.

Agent Skills

Agent skills resources and documentation for building AI agent skills.

Awesome Skills

Curated list of awesome skill repositories and collections.

Agent Skills Topic

GitHub topic for discovering agent-related skills and repositories.

AI Agent Topic

Trendshift topic for discovering AI agents.

AI Skills Topic

Trendshift topic for discovering AI skills.

Agent Governance Toolkit

Agent governance toolkit.

Pattern Sources

Our patterns are curated from industry-leading sources with proper attribution and licensing compliance.

Refactoring.Guru

Classic GoF design patterns, code smells catalog, and refactoring techniques (https://refactoring.guru).

Enterprise Integration Patterns

65 messaging patterns for integrating enterprise applications by Gregor Hohpe and Bobby Woolf (CC BY 4.0).

Microservices.io

Comprehensive patterns for microservice architectures by Chris Richardson.

Agent Catalog Patterns

Patterns for agentic systems from agentpatternscatalog.org (CC BY 4.0).

OWASP Foundation

Security patterns from OWASP Top 10 for Web Applications, LLM Applications, and Agentic Applications (CC BY-SA 4.0).

Industry Research

ML/AI patterns from Microsoft, Google, Anthropic, and academic research.

AI Agent Patterns

Spec-driven development patterns from Claude, Gemini, OpenAI, and GitHub Copilot on github/spec-kit and OpenSpec.

Data Engineering Leaders

Data platform patterns from Martin Fowler (Data Mesh), Kimball Group (Dimensional Modeling), and cloud providers.

MLOps Best Practices

Data science patterns from MLflow, Great Expectations, and MLOps practitioners.

Streaming & Analytics

Real-time patterns from Confluent/Kafka, Apache projects, and serverless analytics platforms.

Academic Papers

Rigorous ML patterns from peer-reviewed research including data leakage prevention and active learning.

5-Day AI Agents Course

Intensive Vibe Coding Course With Google by Brenda Flynn et al. (2026) on Kaggle.

The Agent Loop

Foundational Agent Definition (Perceive + Act):
Russell, S. J., & Norvig, P. (1995). Artificial Intelligence: A Modern Approach. Prentice Hall. (Current edition: 4th Ed., Pearson, 2020)

Modern Iterative LLM Agent Loop:
Yao, S., Zhao, J., Yu, D., et al. (2022). ReAct: Synergizing Reasoning and Acting in Language Models. arXiv:2210.03629.

Historical Context:
Incorporating AIMA's perceive/act model, Classical robotics' Sense-Plan-Act loop (Brooks, 1986), and ReAct's Thought→Action→Observation cycle.