What is AGENTS.md?

AGENTS.md is an open standard for providing context to AI code agents. It's automatically loaded at the start of every conversation, giving the agent immediate understanding of your project.

A well-written AGENTS.md helps agents:

  • Understand your project's architecture and patterns
  • Follow your coding style and conventions
  • Use the right commands for building and testing
  • Avoid known pitfalls and antipatterns
  • Make decisions aligned with your preferences

Cross-platform: AGENTS.md is supported by multiple AI tools including Cursor, Zed, GitHub Copilot, and Autohand. Files you write are portable across agents.

File locations

Autohand looks for AGENTS.md files in several locations, with different scopes:

LocationScopeUse case
./AGENTS.mdProject rootPrimary project context
./src/AGENTS.mdDirectoryModule-specific context
../AGENTS.mdParent directoryMonorepo shared context
~/.autohand/AGENTS.mdGlobalPersonal preferences

Loading behavior

Autohand automatically loads:

  1. Global AGENTS.md (always)
  2. Parent directory AGENTS.md (if in subdirectory)
  3. Project root AGENTS.md (always)
  4. Current directory AGENTS.md (on demand)

Content from all files is merged, with more specific files taking precedence.

Quick start

Generate an AGENTS.md file automatically with the /init command:

/init

# Autohand will:
# 1. Analyze your project structure
# 2. Detect frameworks and languages
# 3. Find build scripts and commands
# 4. Generate an appropriate AGENTS.md

Review and customize the generated file - it's a starting point, not a finished product.

Recommended structure

An effective AGENTS.md typically includes these sections:

# AGENTS.md

## Project overview
Brief description of what this project does and its primary purpose.

## Tech stack
- Framework: Next.js 14 with App Router
- Language: TypeScript (strict mode)
- Database: PostgreSQL with Prisma ORM
- Styling: Tailwind CSS

## Architecture
Explain the codebase structure and key patterns.

## Commands
```bash
bun install        # Install dependencies
bun run dev        # Start development server
bun run test       # Run tests
bun run build      # Production build
```

## Code style
- Prefer functional components
- Use early returns
- Name files in kebab-case
- Write tests for business logic

## Patterns to follow
Document established patterns in the codebase.

## Things to avoid
List antipatterns and common mistakes.

Section guide

Project overview

Start with a concise description of what the project does. This helps agents understand the domain and make contextually appropriate suggestions.

## Project overview
Autohand is an AI-powered CLI for software development. It helps developers
write, review, and refactor code through natural language conversations.

Key features:
- Multi-provider AI support (Claude, GPT, Gemini)
- Skills system for specialized tasks
- Git integration for code changes
- Session management for context persistence

Tech stack

List the technologies used. Be specific about versions when they matter.

## Tech stack
- Runtime: Node.js 20+
- Framework: Express 4.x
- Database: MongoDB 6.x with Mongoose
- Auth: Passport.js with JWT
- Testing: Jest + Supertest
- CI: GitHub Actions

Architecture

Explain how the codebase is organized. Include directory structure if it helps.

## Architecture

```
src/
├── api/          # REST API routes
├── services/     # Business logic
├── models/       # Database schemas
├── utils/        # Shared utilities
└── middleware/   # Express middleware
```

### Key patterns
- Services handle all business logic
- Controllers are thin - just request/response handling
- All database access goes through models
- Middleware handles auth, logging, error handling

Commands

Document the commands agents need to build, test, and run the project.

## Commands

```bash
# Development
npm run dev              # Start with hot reload
npm run dev:debug        # Start with debugger

# Testing
npm test                 # Run all tests
npm run test:watch       # Watch mode
npm run test:coverage    # With coverage report

# Building
npm run build            # Production build
npm run typecheck        # TypeScript check only

# Database
npm run db:migrate       # Run migrations
npm run db:seed          # Seed test data
npm run db:reset         # Reset and reseed
```

Code style

Describe coding conventions that aren't captured by linters.

## Code style

### Naming
- Files: kebab-case (user-service.ts)
- Classes: PascalCase (UserService)
- Functions: camelCase (getUserById)
- Constants: SCREAMING_SNAKE_CASE (MAX_RETRIES)

### Functions
- Prefer arrow functions for callbacks
- Use named functions for top-level exports
- Max 30 lines per function
- Use early returns to reduce nesting

### Error handling
- Always use typed errors (AppError class)
- Log errors at the boundary, not inline
- Return Result types instead of throwing in services

Patterns to follow

Document patterns that are established in the codebase.

## Patterns to follow

### API responses
Always use the standard response format:
```typescript
{
  success: boolean;
  data?: T;
  error?: { code: string; message: string };
}
```

### Database queries
Use the repository pattern for complex queries:
```typescript
// Good
const users = await userRepository.findActiveWithProjects();

// Avoid
const users = await User.find({ active: true }).populate('projects');
```

### Feature flags
Check feature flags before new functionality:
```typescript
if (await features.isEnabled('new-checkout')) {
  // new implementation
}
```

Things to avoid

List antipatterns, known issues, and things that have caused problems.

## Things to avoid

### Don't
- Don't use `any` type - use `unknown` and narrow
- Don't mutate function parameters
- Don't use default exports (we use named exports)
- Don't commit .env files
- Don't use `console.log` - use the logger

### Known issues
- The legacy `/api/v1/users` endpoint has bugs - use `/api/v2/users`
- `OrderService.calculateTotal` has floating point issues on large orders
- MongoDB aggregations timeout after 10s - paginate large queries

### Security
- Never log user passwords or tokens
- Always sanitize user input before database queries
- Use parameterized queries, never string concatenation

Example files

React/Next.js project

# AGENTS.md

## Project overview
E-commerce platform built with Next.js 14 App Router.

## Tech stack
- Next.js 14 (App Router)
- TypeScript 5.x (strict)
- Prisma + PostgreSQL
- Tailwind CSS + shadcn/ui
- Stripe for payments

## Commands
```bash
bun install
bun run dev          # localhost:3000
bun run test
bun run build
```

## Architecture
```
app/
├── (auth)/          # Auth routes (login, register)
├── (shop)/          # Shop routes (products, cart)
├── api/             # API routes
└── layout.tsx       # Root layout
components/
├── ui/              # shadcn/ui components
└── features/        # Feature components
lib/
├── db.ts            # Prisma client
├── auth.ts          # Auth utilities
└── stripe.ts        # Stripe client
```

## Code style
- Use server components by default
- Add 'use client' only when needed
- Colocate components with routes
- Use Zod for form validation
- Prefer server actions over API routes

## Things to avoid
- Don't use `useEffect` for data fetching
- Don't put business logic in components
- Don't use `any` type

Python CLI project

# AGENTS.md

## Project overview
Data pipeline CLI for ETL operations.

## Tech stack
- Python 3.11+
- Click for CLI
- SQLAlchemy 2.0
- Pandas for data processing
- Poetry for dependencies

## Commands
```bash
poetry install
poetry run pytest
poetry run mypy src/
poetry run cli --help
```

## Architecture
```
src/
├── cli/             # Click commands
├── extractors/      # Data source extractors
├── transformers/    # Data transformations
├── loaders/         # Destination loaders
└── models/          # SQLAlchemy models
```

## Code style
- Type hints on all functions
- Docstrings in Google style
- Max line length 88 (Black)
- Use dataclasses for config objects

## Patterns
- Extractors yield records, don't load all in memory
- Transformers are pure functions
- Use context managers for database connections

## Things to avoid
- Don't use mutable default arguments
- Don't catch bare exceptions
- Don't use print() - use logging

Best practices

Keep it concise

AGENTS.md should be scannable. Aim for under 500 lines. If you need more detail, link to other docs.

Keep it current

Outdated AGENTS.md is worse than none at all. Update it when you make architectural changes or establish new patterns.

Be specific, not generic

Generic advice like "write clean code" doesn't help. Instead, show specific examples from your codebase.

# Bad
Write clean, readable code.

# Good
Use early returns to reduce nesting:
```typescript
// Prefer this
function process(user: User | null) {
  if (!user) return null;
  if (!user.active) return null;
  return user.process();
}

// Not this
function process(user: User | null) {
  if (user) {
    if (user.active) {
      return user.process();
    }
  }
  return null;
}
```

Focus on what's different

Don't repeat standard practices. Focus on what's unique to your project.

Include the "why"

When documenting patterns, explain why they exist:

# Good
We use server components by default because:
- Better performance (less JavaScript shipped)
- Direct database access without API layer
- Simplified data fetching with async components

Use 'use client' only for:
- Event handlers (onClick, onChange)
- Browser APIs (localStorage, geolocation)
- React hooks that need client state

Global configuration

Create a personal AGENTS.md for preferences that apply to all your projects:

# ~/.autohand/AGENTS.md

## My preferences

### Communication style
- Be concise, skip pleasantries
- Show code examples, not just explanations
- Ask clarifying questions before making assumptions

### Code style
- I prefer functional programming patterns
- Use TypeScript strict mode
- Prefer composition over inheritance

### Tools
- I use VS Code with Vim keybindings
- Terminal is iTerm2 with zsh
- Package manager preference: bun > pnpm > npm

### Commit messages
- Use conventional commits (feat:, fix:, docs:)
- Keep subject under 50 characters
- Include ticket number when available

Troubleshooting

Agent ignoring AGENTS.md

  • Check file is named exactly AGENTS.md (case matters on Linux)
  • Verify file is in the right location (project root)
  • Start a new session with /new

Context too large

If AGENTS.md is too large, the agent may truncate it. Keep files under 500 lines or split into directory-specific files.

Conflicting instructions

If multiple AGENTS.md files conflict, the most specific one wins. Project root overrides parent, directory-specific overrides project root.