Back to Blog
Guide - Developer Productivity

Agent-Ready Preparing Your Codebase for Agentic Coding

The difference between a 10-minute task and a 2-hour struggle often comes down to whether your codebase speaks the same language as your AI agent. Here's how to make that happen.

01

The Reality Check

Why Most Codebases Fail with AI Agents

?!

The Tribal Knowledge Problem

Last week I asked Claude to add a new API endpoint. It created the file in the wrong directory, used the old authentication pattern we deprecated months ago, and imported a testing library we never use. The code was technically correct — but completely wrong for our project.

↻↻

The Repetition Tax

Every session starts the same way: "We use TypeScript strict mode", "Put API routes in /api/v2", "Always use the logger from @internal/logging". You're paying a repetition tax that compounds with every interaction.

🎯

The Context Window Crunch

AI agents have limited memory. When your project lacks clear structure, the agent wastes precious context tokens figuring out basics instead of solving your actual problem. A well-organized codebase means more room for what matters.

The Core Insight
AI Agents Are Junior Developers with Perfect Memory

Think of an AI agent as a brilliant junior developer who joined your team today. They can write excellent code, but they don't know your conventions, your architecture decisions, or why you chose PostgreSQL over MongoDB. The difference is: unlike a human, you only have to tell them once — if you write it down properly.

02

The Foundation

Instruction Files That Actually Work

📄

CLAUDE.md / AGENTS.md

This is your project's instruction manual for AI agents. Not a README — those are for humans and tend to be vague. This file contains specific, actionable rules: where files go, which patterns to use, what to avoid. I keep mine under 500 lines but packed with context.

🏠

Global vs Local Instructions

Put universal preferences in ~/.claude/CLAUDE.md (your preferred model, general coding style, tools you always use). Project-specific rules go in the repo's CLAUDE.md. The agent reads both — global first, then local overrides.

Example: A Real CLAUDE.md Structure
# Project: E-commerce API

## Tech Stack
- Node.js 20 with TypeScript 5.3 (strict mode)
- PostgreSQL 16 with Drizzle ORM
- Express.js with Zod validation
- Jest for testing, Biome for linting

## Project Structure
- /src/api/v2/* - All new endpoints go here
- /src/services/* - Business logic, one file per domain
- /src/db/schema/* - Drizzle schema definitions
- Tests are colocated: user.service.ts → user.service.test.ts

## Code Conventions
- Named exports only, no default exports
- Use Result<T, E> pattern for error handling
- All API responses use ApiResponse<T> wrapper
- Database queries go through repository layer

## What NOT to Do
- Never use console.log — use logger from @internal/logging
- Never use any type — always define interfaces
- Never commit .env files or hardcode credentials
- Don't use /api/v1/* — it's deprecated

## Running the Project
# Install: pnpm install
# Dev: pnpm dev (runs on port 3001)
# Test: pnpm test -- --watch
# DB migrations: pnpm db:migrate
03

Structure Matters

How AI Agents Navigate Your Code

📁

Predictable Directory Structure

When I ask Claude to create a new user service, it should know exactly where to put it without asking. /src/services/user.service.ts — not /lib/user/service.js or /backend/users/UserService.ts. Pick a convention and document it.

🏷️

Consistent Naming Patterns

Is it getUserById or findUserById or fetchUser? Pick one. AI agents learn from your existing code. If your naming is inconsistent, the generated code will be too. I grep my codebase quarterly to catch drift.

🔗

Clear Import Boundaries

Use path aliases and barrel exports to make imports obvious. When Claude sees import { UserService } from '@services' it understands the architecture instantly. Relative import spaghetti like ../../../services confuses everyone.

Aspect Agent-Hostile Agent-Friendly
File location "Put it wherever makes sense" /src/services/*.service.ts
Function naming get, fetch, find, retrieve (mixed) findById, findMany, create, update, delete
Error handling throw, return null, return -1 (mixed) Result<T, E> everywhere
Config access process.env scattered everywhere Config object from @config
Test files /tests/__tests__/unit/services/ Colocated: user.service.test.ts
04

Documentation as Code

The Parts AI Agents Actually Read

Tip 01

Type Definitions Are Documentation

AI agents read your types more carefully than your comments. A well-defined interface User { id: string; email: string; createdAt: Date } tells Claude more than a paragraph of prose. Invest in your type system.

Tip 02

JSDoc for Complex Functions

For functions with non-obvious behavior, JSDoc comments get parsed and understood. Not every function — just the ones where the name doesn't tell the whole story. Include @example blocks for common usage patterns.

Tip 03

Architecture Decision Records

Why did you choose Drizzle over Prisma? Put it in /docs/adr/. When Claude needs to make architectural decisions, these records prevent it from suggesting solutions you've already rejected.

Tip 04

Example Files Beat Descriptions

Instead of describing your API response format, show it. Keep a /examples directory with sample requests, responses, and data structures. Claude will pattern-match against these rather than inventing formats.

05

The Quick Wins

Do These Today

1

Create Your CLAUDE.md

Start with just 50 lines. Tech stack, directory structure, three things to always do, three things to never do. You can expand it over time as you notice the agent making the same mistakes.

2

Add Path Aliases

Configure @services, @utils, @types in your tsconfig.json. This makes imports self-documenting and helps Claude understand your module boundaries without traversing directories.

3

Standardize One Pattern

Pick your biggest inconsistency and fix it. If you have 5 different error handling approaches, standardize on one. The agent will then generate consistent code based on the pattern it sees most frequently.

4

Add a .cursorrules / Repo Instructions

If you use Cursor, create .cursorrules. For GitHub Copilot, add .github/copilot-instructions.md. Different tools, same idea. Your conventions should follow you everywhere.

5

Document Your "Why Nots"

Every project has anti-patterns. "We tried Redux but removed it because..." goes in CLAUDE.md. This prevents the agent from suggesting things you've already tried and abandoned.

6

Keep Scripts in package.json

pnpm test, pnpm lint, pnpm build — standardize these. AI agents look at your package.json to understand how to run things. Undocumented Makefiles or custom scripts get missed.

06

The Compound Effect

Why This Investment Pays Off

📈

Better First Attempts

Before my CLAUDE.md: 60% of generated code needed significant rework. After: 90% is usable with minor tweaks. The agent stopped guessing and started following rules. That's hours saved per week.

🔄

Consistent Team Output

When everyone on the team uses AI agents with the same instruction files, code reviews get easier. The AI generates code that matches your standards, not each developer's personal interpretation of "clean code".

🚀

Faster Onboarding

New team members can use AI agents effectively from day one. They don't need months of tribal knowledge — the CLAUDE.md file captures it all. Ask the agent "how do we handle authentication here?" and get an accurate answer.

🛡️

Reduced Technical Debt

When AI agents follow your conventions, they don't introduce new patterns that someone else has to clean up later. The code they generate fits your architecture instead of fighting against it.

Real Talk
This Isn't Just About AI

Everything that makes a codebase agent-friendly also makes it human-friendly. Clear structure, consistent patterns, documented decisions — these help new developers, future you, and anyone who touches the code. AI agents just make the ROI on these investments immediate instead of gradual.

Start Now
Your Codebase Will Thank You

Create a CLAUDE.md file in your project root today. Start with your tech stack, directory conventions, and three things the agent should never do. Iterate from there. The best time to make your codebase agent-ready was six months ago. The second best time is now.