Skip to content

Split View: 2026년 AI 코딩 워크플로 베스트 프랙티스 — CLAUDE.md, AGENTS.md, .cursorrules, Skills, 서브에이전트, MCP 깊게 보기

|

2026년 AI 코딩 워크플로 베스트 프랙티스 — CLAUDE.md, AGENTS.md, .cursorrules, Skills, 서브에이전트, MCP 깊게 보기

"에이전트는 당신이 만든 환경을 그대로 닮는다. 좋은 환경을 만드는 것이 곧 좋은 에이전트를 만드는 일이다."

프롤로그 — 코드보다 컨텍스트가 먼저다

2026년 5월, 시니어 개발자의 하루는 2022년과 많이 달라졌습니다. 아침에 자리에 앉아 가장 먼저 여는 것은 IDE가 아니라 에이전트 세션입니다. PR의 절반 이상이 사람이 직접 친 줄보다 에이전트가 친 줄을 더 많이 포함합니다. 그리고 그 PR의 품질을 결정하는 가장 큰 변수는 에이전트의 모델 버전이 아니라 우리가 만들어 둔 컨텍스트입니다.

이 글은 한 가지 단순한 명제에서 출발합니다.

에이전트는 코드와 함께 있는 마크다운 파일들과 설정 파일들을 컴파일러처럼 읽는다. 그 파일들이 곧 당신의 에이전트다.

지난 2년 동안 일어난 일은 도구 폭발이었습니다. Claude Code의 CLAUDE.md, Cursor의 .cursorrules.cursor/rules, GitHub Copilot의 .github/copilot-instructions.md, 그리고 OpenAI Codex가 밀고 있는 범도구 표준 AGENTS.md — 이름은 다 다르지만 본질은 같습니다. "이 레포에서 일할 때 이렇게 행동해라" 라는 공유된 지시문입니다.

그 위에 도구별 고급 기능이 얹혀 있습니다. Claude Code의 Skills(.claude/skills/)와 서브에이전트(.claude/agents/)와 hooks(.claude/hooks/), MCP 서버 설정(.mcp.json), Cursor의 agent 정의(agents.json)와 permission 시스템. 각각은 사소해 보이지만, 합쳐 놓으면 개인 생산성의 10배 차이를 만듭니다.

문제는 이것을 가르치는 글이 의외로 드물다는 것입니다. 도구별 공식 문서는 있지만, 그 도구들이 한 레포에서 어떻게 공존하는지를 다룬 글은 별로 없습니다. 이 글은 그 빈자리를 채우려는 시도입니다.

이 글에서 다룰 내용:

주제
1장컨텍스트 파일 패밀리 — 무엇이 어디로 가는가
2장CLAUDE.md 잘 쓰기 — 길이, 구조, 계층
3장AGENTS.md — 범도구 표준의 등장
4장Cursor 규칙 — .cursorrules와 .cursor/rules
5장GitHub Copilot, README.dev, CONTRIBUTING의 역할
6장Claude Code Skills — 재사용 가능한 워크플로
7장서브에이전트와 hooks — 자동화의 두 축
8장MCP 서버 설정 — 에이전트의 도구 상자
9장Permission과 샌드박싱 — 안전한 자율성
10장에이전트 친화 코드베이스란 무엇인가
11장안티패턴 — 이렇게 하면 망한다
에필로그체크리스트 + 다음 글 예고

1장 · 컨텍스트 파일 패밀리

2026년 현재, 잘 세팅된 레포에는 보통 다음 파일들이 있습니다. 이름은 도구별로 갈리지만 역할은 명확히 분담됩니다.

1.1 파일 지도

파일누가 읽는가용도
CLAUDE.mdClaude Code (세션 시작 시 자동)이 레포에서 Claude가 따라야 할 규칙
AGENTS.mdOpenAI Codex, 그리고 점점 더 많은 도구범도구 공통 지시문
.cursorrules (구) / .cursor/rules/*.mdc (신)Cursor IDECursor 모드에서의 규칙
.github/copilot-instructions.mdGitHub Copilot ChatCopilot에 들어가는 시스템 프롬프트 보조
README.md사람 (그리고 에이전트가 컨텍스트로 사용)프로젝트 진입점
CONTRIBUTING.md사람 + 에이전트개발/PR/리뷰 규칙
README.dev.md시니어/온콜/에이전트내부 개발 가이드
.mcp.jsonClaude Code이 레포가 쓰는 MCP 서버 목록
.claude/agents/*.mdClaude Code서브에이전트 정의
.claude/skills/*/SKILL.mdClaude Code재사용 가능한 절차 묶음
.claude/hooks/*.tomlClaude Code세션 라이프사이클 훅
agents.jsonCursorCursor 에이전트 정의

1.2 계층의 원칙

이 모든 파일이 한 레포에 다 있을 필요는 없습니다. 다만 어떤 것을 어디에 둘지를 결정할 때 다음 세 가지 축을 따라가면 충돌이 줄어듭니다.

  1. 도구 범용성 축 — 한 도구에만 쓰이면 그 도구의 파일에, 여러 도구에서 공통이면 AGENTS.md 또는 README.md에.
  2. 범위 축 — 레포 전역이면 루트에, 특정 폴더만이면 그 폴더에 CLAUDE.mdAGENTS.md를 또 둡니다. Claude Code는 작업 중인 파일의 상위 디렉터리들을 거슬러 올라가며 모든 CLAUDE.md를 읽어 합칩니다.
  3. 휘발성 축 — 자주 바뀌는 것(현재 진행 중인 마이그레이션 메모, 회의 결정)은 별도 파일이나 CLAUDE.md의 짧은 절에. 거의 안 바뀌는 규칙(코드 스타일, 보안 원칙)은 본문에.

한 줄 요약: 공통 규칙은 AGENTS.md, 도구별 디테일은 각자의 파일, 폴더별 디테일은 폴더에.


2장 · CLAUDE.md 잘 쓰기

Claude Code는 세션이 시작되면 작업 디렉터리의 CLAUDE.md를 자동으로 읽어 시스템 프롬프트에 합칩니다. 또한 작업 중인 파일 경로의 상위들을 따라가며 CLAUDE.md를 더 찾고, 사용자 홈의 ~/.claude/CLAUDE.md(전역)와 머지합니다. 이 파일이 잘 쓰여 있으면 같은 모델로도 결과 품질이 눈에 띄게 올라갑니다.

2.1 좋은 CLAUDE.md의 구조

# Project: Acme Web

## Stack
- Next.js 15 (App Router), TypeScript strict, Tailwind v4
- Drizzle ORM + Postgres 16
- Vitest + Playwright

## Conventions
- All server actions live in `app/_actions/` and import zod schemas from `lib/schemas/`.
- Database access goes through `lib/db/repositories/`. Do NOT import drizzle directly in components.
- Error type: throw `AppError` (see `lib/errors.ts`); the global handler converts to JSON.

## Verification (do this before reporting "done")
- `pnpm typecheck`
- `pnpm test --run`
- `pnpm lint`

## Permissions
- You may run: pnpm scripts, git read commands, gh CLI for issues/PRs.
- You may NOT run: git push, gh pr merge, anything that mutates production.

핵심은 짧고 행동 지향적이라는 점입니다. "이 레포에서 다르게 행동해야 할 부분"만 적습니다.

2.2 길이 — 200줄 안에서 끝낸다

CLAUDE.md가 1000줄이 되면 두 가지 문제가 동시에 생깁니다. 첫째, 토큰 비용이 매 턴마다 발생합니다. 둘째, 모델이 그 모든 규칙을 균일하게 따르지 못합니다. 길이가 길어질수록 중간이 묽어집니다.

경험칙: 200줄을 넘으면 분리합니다. 두 가지 분리 패턴이 있습니다.

  • 폴더별 CLAUDE.md — 백엔드 규칙은 apps/api/CLAUDE.md에, 프런트 규칙은 apps/web/CLAUDE.md에. Claude Code가 자동으로 합칩니다.
  • 별도 문서 — 길고 자주 참조하지 않는 정책(보안 운영, 데이터 보존)은 별도 마크다운으로 두고 CLAUDE.md에서는 "필요할 때 docs/security.md를 읽어라"라고만 적습니다.

2.3 무엇을 적고 무엇을 빼는가

적을 것:

  • 이 레포의 비표준 컨벤션 (전역 규칙은 적지 않습니다 — "TypeScript는 strict 모드"는 거의 모든 레포에서 같으므로 굳이 안 적어도 됩니다)
  • 자주 틀리는 함정 ("이 레포에서는 dayjs가 아니라 date-fns만 쓴다")
  • 검증 절차 — 어떤 명령을 돌려야 "완료"인지
  • 금지 사항 — force push, 마이그레이션 자동 적용 등

뺄 것:

  • 모델의 기본 행동에 이미 포함된 일반론 ("코드는 깔끔하게 짜라" 같은 문장은 노이즈)
  • 자주 바뀌는 임시 메모 (그것은 티켓이나 PR 설명에)
  • 비밀 정보 (이 파일은 보통 커밋되므로 토큰이나 키를 절대 적지 않습니다)

2.4 폴더별 CLAUDE.md 예

apps/api/CLAUDE.md만 따로 두면 백엔드 작업 시에만 그 규칙이 합쳐집니다.

# apps/api

## Boundaries
- Controllers in `routes/` — only HTTP concerns.
- Business logic in `services/`.
- DB access in `repositories/` (Drizzle).

## Tests
- Unit tests next to the file (`*.test.ts`).
- Integration tests in `tests/integration/` — they spin up testcontainers Postgres.

3장 · AGENTS.md — 범도구 표준

2025년 후반부터 OpenAI Codex가 밀기 시작한 AGENTS.md는 "한 레포에 둔 마크다운을 모든 코딩 에이전트가 읽도록 하자"는 운동입니다. 2026년 현재 Codex, 일부 Cursor 모드, 그리고 여러 OSS 에이전트들이 이 파일을 인식합니다. 작성 방식은 마크다운 자유 형식입니다.

3.1 전형적인 AGENTS.md

# AGENTS.md

This file gives AI coding agents the context they need to work in this repository.

## What this repo is
A pnpm monorepo with `apps/web` (Next.js), `apps/api` (Fastify), and `packages/*` shared libs.

## Setup
- Node 20.18+, pnpm 9.
- `pnpm install` from root.
- `pnpm dev` runs all apps in parallel.

## Test
- `pnpm test` — unit tests across the workspace.
- `pnpm test:e2e` — Playwright; requires Docker for testcontainers.

## Coding rules
- TypeScript only. No JS files in `src/`.
- Public APIs go in `packages/*/src/index.ts` re-exports.
- New endpoints need a zod request schema and 1+ test.

## Don't
- Don't commit secrets. `.env.local` is gitignored on purpose.
- Don't change `pnpm-lock.yaml` without running `pnpm install`.

3.2 CLAUDE.md와의 관계

도구 두 개가 같은 파일을 읽지 않을 때, 같은 내용을 두 번 적기는 싫을 것입니다. 두 가지 패턴이 흔합니다.

  • AGENTS.md 일원화 — 모든 공통 규칙을 AGENTS.md에 적고, CLAUDE.md에는 한 줄만 둡니다.

    # CLAUDE.md
    Read AGENTS.md first. Anything below is Claude-specific addenda.
    
    ## Claude-only
    - When running shell commands, prefer pnpm over npm here.
    
  • CLAUDE.md 일원화 — Claude만 쓴다면 AGENTS.md를 두지 않거나 심볼릭 링크합니다. 단, 다른 에이전트가 들어왔을 때 작동을 보장하지 않습니다.

선택의 기준: 팀이 도구를 1개만 쓴다면 단일 파일, 2개 이상이면 AGENTS.md를 공통 진실의 원천으로 삼고 도구별 파일은 얇게 유지합니다.

3.3 실제 사례 둘러보기

공개된 잘 쓰인 사례들이 있습니다. Vercel 자체의 OSS 레포들(vercel/next.js, vercel/ai)은 비교적 짧고 직설적인 AGENTS.md를 두고, 빌드/테스트 커맨드와 "PR 전 체크리스트"를 중심으로 적습니다. Anthropic의 SDK 레포들(anthropics/anthropic-sdk-python 등)은 CLAUDE.md를 쓰며, 마이그레이션 시기에는 그 상단에 "이번 시즌 변경 사항" 절을 일시적으로 둡니다. 이런 패턴을 그대로 가져다 쓰면 됩니다.


4장 · Cursor 규칙

Cursor는 두 개의 규칙 파일 시스템을 갖고 있습니다. 옛 방식과 새 방식인데, 2026년 현재 둘 다 동작합니다.

4.1 옛 방식 — .cursorrules

레포 루트에 평문 마크다운으로 한 파일만 둡니다.

# Cursor Rules

- Use TypeScript strict mode and avoid `any`.
- Prefer named exports.
- React components: function components with explicit prop types.
- All API handlers must validate input with zod.

## When generating tests
- Use Vitest.
- Place test files adjacent to source as `*.test.ts`.

장점은 단순함, 단점은 분기 불가입니다. 모든 파일 작업에 같은 규칙이 들어갑니다.

4.2 새 방식 — .cursor/rules/*.mdc

.cursor/rules/ 아래에 여러 개의 *.mdc 파일을 두고, 각 파일이 헤더로 자기가 적용될 조건을 선언합니다.

---
description: "Backend API rules — Fastify routes"
globs:
  - "apps/api/src/routes/**/*.ts"
alwaysApply: false
---

# Backend API rules

- Every route declares its zod schema via `schema:` option.
- Use `app.log` not `console.log`.
- Error handling: throw `AppError` (see lib/errors.ts).

조건은 보통 두 가지로 갈립니다. globs에 매치되는 파일을 열고 있을 때만 적용되거나, 사용자가 명시적으로 슬래시 명령으로 호출했을 때만 적용되거나. 이 모듈식 접근이 .cursorrules보다 깔끔하므로, 새 레포에서는 처음부터 .cursor/rules/ 방식을 추천합니다.

4.3 Cursor agents — agents.json

Cursor의 "에이전트 모드"는 자체 에이전트 정의를 가질 수 있습니다. 레포 루트의 agents.json에 어떤 도구를 허용할지, 어떤 모드로 실행할지 등을 적습니다. 디테일은 Cursor 버전마다 빠르게 바뀌니 공식 문서 기준으로 가는 것이 좋고, 우리 글에서는 "이런 파일이 존재한다" 정도만 인지하면 충분합니다.


5장 · GitHub Copilot, README.dev, CONTRIBUTING

5.1 .github/copilot-instructions.md

GitHub Copilot Chat은 이 파일이 있으면 자동으로 자신의 시스템 프롬프트에 합칩니다. 사용 패턴은 CLAUDE.md와 비슷하지만 더 짧게 적는 것이 좋습니다. Copilot 모델은 보통 더 좁은 컨텍스트 윈도로 동작하기 때문입니다.

# Copilot Instructions

- This repo uses pnpm, Next.js 15, Drizzle, Vitest.
- Always type API responses (no `any`).
- For React components, prefer server components unless interactivity is required.
- New endpoints must validate input with zod.

5.2 README.dev.md

README.md가 외부에 보여주는 얼굴이라면, README.dev.md(또는 docs/dev.md)는 내부 개발자와 에이전트에게 보여주는 얼굴입니다. 들어갈 내용은 보통 다음입니다.

  • 로컬에서 처음 띄우는 절차 (의존성, env, DB 시드)
  • 자주 쓰는 명령어 목록 (pnpm dev, pnpm db:reset, pnpm e2e:headed)
  • 디렉터리 구조 한 그림
  • "처음 보는 사람이 자주 막히는 곳" 모음

이 파일은 에이전트에게도 좋고 신입에게도 좋습니다. 그래서 가장 비용 대비 효과가 높은 글 중 하나입니다.

5.3 CONTRIBUTING.md

OSS 레포라면 외부 기여자용이지만, 사내 레포에서도 "PR을 어떻게 여는가, 어떻게 리뷰하는가"의 규칙을 적어두면 에이전트가 그것을 따라갑니다. AGENTS.md와 겹친다면 한쪽에 두고 다른 쪽은 링크만 두는 편이 깔끔합니다.


6장 · Claude Code Skills — 재사용 가능한 워크플로

Skill은 Claude Code의 강력한 기능입니다. 여러 번 반복하는 작업의 절차를 마크다운으로 묶어 둔 것이고, 이름으로 호출할 수 있습니다. 위치는 .claude/skills/<name>/SKILL.md(레포 로컬) 또는 ~/.claude/skills/(전역).

6.1 SKILL.md의 모양

---
name: release-blog-post
description: Write, validate, and commit a trilingual blog post under data/blog/
when_to_use: User says "write a blog post" with a topic.
---

# Release Blog Post

1. Confirm filename slug: `data/blog/<category>/<YYYY-MM-DD>-<slug>.mdx`
2. Draft Korean version first.
3. Translate to en.mdx and ja.mdx, preserving structure.
4. Validate:
   ```bash
   npx tsx val.ts data/blog/.../<slug>.mdx data/blog/.../<slug>.en.mdx data/blog/.../<slug>.ja.mdx
   ```
5. Fix any reported issues, re-run until clean.
6. Stage and commit with message: `post: <topic> (ko/en/ja)`.

6.2 Skill을 잘 만드는 법

  • 트리거(when_to_use)를 분명히 — 모델이 언제 이 Skill을 부를지 결정합니다.
  • 절차는 번호 매긴 짧은 단계로. 한 단계가 한 문장 = 한 행동.
  • 검증 단계를 마지막에 둡니다. 그 단계가 실패하면 위로 돌아가 고치라고 명시.
  • Skill끼리 호출하지 않습니다 — 의존성이 생기면 디버깅이 어려워집니다.

6.3 Skill vs CLAUDE.md vs 서브에이전트

자산언제 호출되나무엇을 담는가
CLAUDE.md세션 시작 시 항상"이 레포에서는 이렇게 행동해라" 정적인 규칙
Skill모델이 트리거 조건을 보고 호출반복되는 절차, 체크리스트
서브에이전트메인 에이전트가 위임분리된 컨텍스트가 필요한 큰 작업

세 개를 혼동하지 않아야 깔끔한 설계가 나옵니다.


7장 · 서브에이전트와 hooks

7.1 서브에이전트 (.claude/agents/)

서브에이전트는 "이 작업은 다른 컨텍스트에서 다른 도구셋으로 처리하라"고 위임할 때 씁니다. 예를 들어 코드 리뷰, 보안 스캔, 대용량 검색 같은 것들. 정의는 다음과 같이 마크다운입니다.

---
name: security-review
description: Reviews code for security issues — secrets, injection, auth bypass.
tools: [Read, Grep, Bash]
---

You are a security reviewer.

Process:
1. Search for hardcoded secrets (regex on common patterns).
2. Look for SQL/command injection in user-input paths.
3. Check authn/authz boundaries.

Output: a markdown report with severity tags (P0/P1/P2).

서브에이전트의 가장 큰 가치는 컨텍스트 격리입니다. 메인 세션에 100k 토큰의 검색 결과가 쏟아져 들어오지 않습니다.

7.2 hooks (.claude/hooks/)

hook은 세션 이벤트에 자동으로 끼어드는 작은 스크립트입니다. 흔한 패턴:

  • pre_tool_use — 위험한 명령(예: rm -rf, git push --force)에 대해 알람을 띄움
  • post_tool_use — 파일을 수정한 직후 자동으로 포맷터를 돌림
  • session_start — 세션 시작 시 환경 정보를 출력해 모델에 컨텍스트 제공
  • notification — 외부 시스템(슬랙, 알림)으로 상태 푸시

훅 정의 예시는 다음과 같습니다.

[[hooks]]
event = "post_tool_use"
matcher.tool = "Edit"
matcher.path = "*.ts"
command = "pnpm prettier --write"

hook은 사용자 환경을 건드리므로 "이 레포에서만" 동작하도록 설계하는 것이 안전합니다.


8장 · MCP 서버 설정 — 에이전트의 도구 상자

MCP(Model Context Protocol)는 모델에 도구를 붙이는 표준 프로토콜입니다. Claude Code는 .mcp.json을 보고 그 레포에서 어떤 MCP 서버를 띄울지 결정합니다.

8.1 .mcp.json 예시

{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-postgres"],
      "env": {
        "POSTGRES_URL": "postgres://app:app@localhost:5432/app"
      }
    },
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_TOKEN": "${env:GITHUB_TOKEN}"
      }
    }
  }
}

이 파일이 있으면 모델에 postgres MCP의 쿼리 도구, github MCP의 이슈/PR 도구가 노출됩니다. 즉, 모델이 직접 SQL을 짜서 돌리거나, 깃허브 이슈를 열고 닫을 수 있습니다.

8.2 어떤 MCP를 둘 것인가

원칙은 "팀이 자주 하는 외부 호출을 도구화"입니다. 후보들:

  • 데이터베이스(Postgres, MySQL) — 디버깅 시 임시 쿼리에 무한히 유용
  • GitHub/GitLab — 이슈, PR, 코멘트
  • 관측 도구(Sentry, Datadog, Grafana) — 에러 컨텍스트를 자동으로 가져오게
  • 사내 API의 슬림 MCP — 위키, 디자인 시스템, RBAC 조회

너무 많이 붙이면 컨텍스트가 무거워지니, 세션당 5개 안쪽을 권장합니다. 자주 안 쓰는 것은 켰다 껐다 하는 것이 낫습니다.

8.3 시크릿 다루기

.mcp.json은 보통 커밋되지만, env 변수는 절대 그 안에 적지 않습니다. ${env:VAR} 문법을 쓰거나, 시크릿이 필요한 항목은 .mcp.local.json(gitignore된)에 별도로 둡니다. Claude Code는 두 파일을 자동으로 머지합니다.


9장 · Permission과 샌드박싱

자율성 있는 에이전트의 큰 위험은 "예상하지 못한 행동"입니다. 2026년의 도구들은 이를 막기 위해 두 가지 메커니즘을 제공합니다.

9.1 Claude Code의 permission 모드

Claude Code는 다음 모드들을 지원합니다 (이름은 버전마다 약간 다르지만 의미는 비슷).

  • default — 위험 명령마다 사용자에게 확인을 받습니다.
  • acceptEdits — 파일 편집은 자동 승인, 외부 명령(쉘, 네트워크)은 확인.
  • plan — 읽기 전용. 계획만 세우고 변경은 하지 않습니다.
  • bypassPermissions — 모든 확인을 건너뜁니다. 격리된 환경에서만 권장.

레포 단위로 권한 모드를 고정하려면 .claude/settings.json에 다음을 둘 수 있습니다.

{
  "permissions": {
    "allow": [
      "Bash(pnpm test*)",
      "Bash(pnpm typecheck)",
      "Bash(git status)",
      "Bash(git diff*)"
    ],
    "deny": [
      "Bash(git push*)",
      "Bash(gh pr merge*)"
    ]
  }
}

핵심 아이디어: 읽기와 빌드/테스트는 자동 허용, 외부에 변경을 일으키는 행동은 항상 명시적 승인. 이 규칙 하나만으로도 사고가 크게 줄어듭니다.

9.2 Cursor의 agent 허용 목록

Cursor 에이전트도 비슷하게 명령 허용/거부 목록을 갖습니다. 흔한 권장은 "테스트와 lint와 typecheck는 무제한 허용, 패키지 설치는 확인, 깃 푸시는 차단"입니다.

9.3 샌드박스 — 워크트리, 컨테이너, dev container

권한과 별개로, 작업 자체를 격리된 환경에 가두는 패턴이 빠르게 표준이 되고 있습니다.

  • git worktree — 한 레포의 여러 브랜치를 동시에, 별도 디렉터리에 체크아웃해 두는 기능. 에이전트가 그 워크트리 안에서만 일하게 하면 메인 작업과 충돌이 안 일어납니다.
  • dev container / Docker — 의존성과 네트워크가 통제된 컨테이너 안에서 에이전트가 동작합니다. Claude Code Docker 이미지가 공식으로 있고, 이걸 쓰면 호스트 OS와 분리됩니다.
  • 클라우드 샌드박스 — OpenAI Codex 등의 일부 모드는 클라우드 VM에서 동작합니다. 호스트는 절대 건드려지지 않습니다.

자율성을 늘리고 싶을수록 샌드박스를 강하게. 두 다이얼은 같은 축이 아니라 직교합니다.


10장 · 에이전트 친화 코드베이스란

설정 파일이 아무리 좋아도 코드가 따라주지 않으면 한계가 있습니다. "에이전트가 일하기 좋은 코드"라는 것이 따로 있습니다.

10.1 다섯 가지 특성

  1. 강한 타입 — TypeScript strict, Python typing 풀가동, Rust. 모델이 시그니처만 보고 의도를 짐작할 수 있어야 합니다.
  2. 명확한 경계 — 모듈 사이에 import 그래프가 단순하고, 한 모듈의 책임이 한 문장으로 설명됩니다.
  3. 빠른 테스트 — 단위 테스트가 10초 안에 끝나야 에이전트가 매 단계 검증할 수 있습니다. 분단위 테스트만 있으면 에이전트는 검증을 건너뜁니다.
  4. 좋은 에러 메시지Error: invalid input 같은 메시지는 모델에게 정보를 주지 않습니다. Error: 'email' must be a valid RFC 5322 address (got "foo@") 같은 에러가 에이전트에게는 디버깅 단서입니다.
  5. 명명 규칙의 일관성 — 비슷한 것이 비슷하게 이름지어져 있어야 모델의 일반화가 잘 작동합니다. userService.findByIdOrderRepository.get이 섞여 있으면 모델이 헷갈립니다.

10.2 "테스트를 에이전트의 검증자로"

가장 강력한 패턴은 "에이전트가 자신의 변경을 검증하는 방식을 미리 정해두는 것"입니다. CLAUDE.md/AGENTS.md의 "Verification" 절이 그 역할을 합니다. 모델이 코드를 바꾸고 — 테스트를 돌리고 — 실패하면 — 다시 고치는 루프를 자기 안에서 닫게 됩니다. 이 루프가 닫혀 있을수록 사람의 개입이 줄어듭니다.

10.3 작은 단위 = 작은 PR = 좋은 에이전트 출력

에이전트는 한 번에 너무 많은 것을 바꾸지 않을 때 가장 잘 동작합니다. 그래서 코드베이스 자체가 "작은 PR이 자연스럽게 나오게" 설계되어야 합니다. 모듈이 너무 크면, 에이전트의 한 작업이 자동으로 거대해집니다. 이건 그냥 좋은 엔지니어링 원칙인데, 에이전트 시대에 보상이 두 배입니다.


11장 · 안티패턴 — 이렇게 하면 망한다

11.1 너무 긴 컨텍스트 파일

가장 흔한 실수입니다. CLAUDE.md가 2000줄이 되면 매 턴 그만큼의 토큰을 태우면서 모델이 중간 규칙은 잊어버립니다. 200줄에서 잘리는 자기 절제가 필요합니다.

11.2 서로 충돌하는 지시문

CLAUDE.md에는 "pnpm 써라", AGENTS.md에는 "npm 써라"가 있는 경우. 모델은 무작위로 하나를 고릅니다. 단일 진실의 원천을 정하고 다른 파일은 그쪽을 참조만 하게 만들어야 합니다.

11.3 빈 placeholder, 옛 명령어

"This file is a stub — fill in your project details"가 그대로 남아 있는 CLAUDE.md를 본 적이 있을 것입니다. 모델은 그것을 진지하게 받아들입니다. 그리고 6개월 전의 명령어가 그대로 적혀 있으면 그 명령어를 실행하다 실패합니다. 컨텍스트 파일도 CI에서 lint할 수 있다면 가장 좋습니다(빈 placeholder 검출).

11.4 시크릿 누출

MCP 설정에 API 키를 직접 적거나, hook 스크립트에 토큰을 박아 둔 채로 커밋하는 사고. 절대 일어나서는 안 됩니다. env 변수, OS 키체인, 시크릿 매니저를 통해 주입합니다.

11.5 "에이전트가 알아서 하겠지" 권한

bypassPermissions를 디폴트로 두고 git push까지 자동 허용. 한 번의 사고로 메인 브랜치가 망가집니다. 디폴트는 항상 보수적으로, 풀 자율은 격리된 워크트리/컨테이너 안에서만.

11.6 Skill을 너무 잘게 자르거나 너무 크게 만들기

Skill이 5줄이면 그냥 시스템 프롬프트로 옮기는 게 낫고, 200줄이면 그건 더 이상 Skill이 아니라 별도 문서입니다. 한 Skill은 한 화면(50~80줄)이 적당합니다.

11.7 컨텍스트 파일을 사람만 보고 갱신하기

배포 절차, CI 명령어가 바뀌었는데 CLAUDE.md가 옛 명령어를 들고 있으면 에이전트는 헛수고를 합니다. 인프라 변경 PR에 "관련 컨텍스트 파일 갱신" 체크박스를 PR 템플릿에 박아두는 것이 가장 싸게 막는 방법입니다.


에필로그 — 환경에 투자한 시간은 복리로 돌아온다

좋은 에이전트 세팅의 본질은 단 한 가지입니다. 사람과 도구가 한 페이지를 보고 일하게 만드는 것. 사람에게 좋은 가이드는 에이전트에게도 좋고, 에이전트에게 좋은 절차는 신입에게도 좋습니다. 둘 사이에 다른 표준은 거의 없습니다.

매 시간을 컨텍스트 파일에 투자하는 것이 부담스러울 수 있습니다. 하지만 이건 한 번의 PR에 들어가는 시간이 아닙니다. 앞으로의 모든 세션에 누적되는 시간입니다. 잘 쓴 200줄짜리 CLAUDE.md는 1년 동안 수백 번 읽힙니다. 그 200줄에 한 시간을 더 쓰는 것은, 그 한 시간을 1000번 곱한 가치로 돌아옵니다.

베스트 프랙티스 체크리스트

  1. AGENTS.md — 도구 공통 규칙의 진실의 원천이 있다
  2. CLAUDE.md — 200줄 안, 비표준 컨벤션과 검증 절차 중심
  3. 폴더별 CLAUDE.md — 모노레포라면 앱·패키지별로 분리
  4. .cursor/rules/ — 글로브로 분기되는 모듈식 규칙
  5. .github/copilot-instructions.md — Copilot용 짧은 요약
  6. README.dev.md — 로컬 세팅과 자주 쓰는 명령
  7. .claude/skills/ — 반복되는 워크플로 묶음 (이름 트리거)
  8. .claude/agents/ — 컨텍스트 격리가 필요한 위임 작업
  9. .claude/hooks/ — 포맷터, 알람 등 자동화
  10. .mcp.json — 자주 호출하는 외부 시스템 도구화 (커밋), 시크릿은 .mcp.local.json
  11. permissions — 읽기/빌드/테스트 자동, 외부 변경 행동은 확인
  12. 샌드박스 — 자율 모드는 워크트리 또는 컨테이너 안에서만
  13. CI에서 컨텍스트 파일 lint — 빈 placeholder, 옛 명령어 검출
  14. PR 템플릿 — "관련 컨텍스트 파일 갱신" 체크박스
  15. 분기마다 리뷰 — 컨텍스트 파일도 코드처럼 살아 있다

피해야 할 안티패턴 요약

  • 2000줄 CLAUDE.md — 모델은 중간을 잊어버린다. 200줄에서 자른다
  • 충돌하는 지시문 — 단일 진실의 원천을 정한다
  • 시크릿 직접 기입 — env 변수와 .mcp.local.json을 쓴다
  • 풀 자율 디폴트 — 항상 보수적 디폴트 + 명시적 옵트인
  • 빈 placeholder — CI에서 검출, PR에서 차단
  • 인프라 변경 시 컨텍스트 미갱신 — 템플릿 체크박스로 강제
  • 너무 많은 MCP — 세션당 5개 이내, 사용 안 하는 것은 끈다
  • 너무 잘게 자른 Skill — 5줄짜리는 시스템 프롬프트로 옮긴다

다음 글 예고

다음 글은 **"AI 코드 리뷰 워크플로 — 사람 리뷰어와 에이전트 리뷰어를 함께 쓰는 법"**입니다. 좋은 컨텍스트 파일이 작성을 돕는다면, 좋은 리뷰 프로세스는 출력의 품질을 보장합니다. 사람 리뷰어가 봐야 하는 것, 에이전트 리뷰어가 잘 잡는 것, 둘을 PR 템플릿과 CI에 어떻게 엮을지 — 그리고 어떻게 하면 "에이전트가 단 PR을 사람이 리뷰만 하는 시스템"이 만들어지는지를 정리합니다.

도구는 매년 바뀐다. 표준은 더 천천히 바뀐다. 환경은 한 번 잘 짜두면 한 해를 간다. 당신의 다음 한 시간을 가장 비싼 코드에 쓰지 말고, 그 코드를 만드는 환경에 쓰라.

참고 / References

AI Coding Workflow Best Practices in 2026 — CLAUDE.md, AGENTS.md, .cursorrules, Skills, Subagents, MCP Deep Dive

"Agents take on the shape of the environment you build for them. Building a good environment is building a good agent."

Prologue — Context Before Code

In May 2026, a senior developer's day looks different than it did in 2022. The first thing you open in the morning is not your IDE but an agent session. More than half of all PRs contain more lines written by an agent than typed by a human. And the variable that most decides PR quality is not the agent's model version — it is the context you prepared.

This post starts from a single proposition.

Agents read the markdown and config files sitting next to your code as if they were a compiler. Those files are your agent.

The last two years have been an explosion of tooling. Claude Code's CLAUDE.md, Cursor's .cursorrules and .cursor/rules, GitHub Copilot's .github/copilot-instructions.md, and the cross-tool AGENTS.md standard that OpenAI Codex has been pushing — different names, same essence. They are shared instructions saying "when you work in this repo, behave this way."

On top of that sit tool-specific advanced features. Claude Code's Skills (.claude/skills/), subagents (.claude/agents/), hooks (.claude/hooks/), MCP server config (.mcp.json), Cursor's agent definitions (agents.json) and permission systems. Each looks small. Stacked together, they create a 10x difference in personal productivity.

The problem is that few guides cover all of this in one place. Official docs exist per tool, but how those tools coexist in a single repo is rarely written down. This post tries to fill that gap.

What you'll find:

ChapterTopic
1The context-file family — what goes where
2Writing CLAUDE.md well — length, structure, layering
3AGENTS.md — the rise of a cross-tool standard
4Cursor rules — .cursorrules and .cursor/rules
5GitHub Copilot, README.dev, CONTRIBUTING roles
6Claude Code Skills — reusable workflows
7Subagents and hooks — the two axes of automation
8MCP server config — the agent's toolbox
9Permissions and sandboxing — safe autonomy
10What makes a codebase agent-friendly
11Anti-patterns — how to ruin it
EpilogueChecklist + next post

1. The Context-File Family

A well-set-up 2026 repo typically has the files below. Names differ per tool, but roles are clearly divided.

1.1 The Map

FileReaderPurpose
CLAUDE.mdClaude Code (auto-loaded at session start)Rules Claude follows in this repo
AGENTS.mdOpenAI Codex, and increasingly more toolsCross-tool shared instructions
.cursorrules (legacy) / .cursor/rules/*.mdc (modern)Cursor IDECursor-mode rules
.github/copilot-instructions.mdGitHub Copilot ChatCopilot system-prompt addendum
README.mdHumans (and agents use it as context)Project entry point
CONTRIBUTING.mdHumans + agentsDevelopment/PR/review rules
README.dev.mdSenior devs / on-call / agentsInternal dev guide
.mcp.jsonClaude CodeMCP servers this repo uses
.claude/agents/*.mdClaude CodeSubagent definitions
.claude/skills/*/SKILL.mdClaude CodeReusable procedures
.claude/hooks/*.tomlClaude CodeSession lifecycle hooks
agents.jsonCursorCursor agent definitions

1.2 The Layering Principle

You do not need all of these in one repo. But three axes help you decide where to put a given rule.

  1. Tool generality — One-tool-only goes in that tool's file. Cross-tool goes in AGENTS.md or README.md.
  2. Scope — Repo-wide goes in the root. Folder-specific goes in another CLAUDE.md or AGENTS.md in that folder. Claude Code walks parent directories and merges every CLAUDE.md it finds.
  3. Volatility — Frequently changing things (an ongoing migration note, recent decisions) go in a separate file or a short section. Rarely changing rules (code style, security principles) belong in the main body.

One-line summary: shared rules in AGENTS.md, tool-specific details in their own files, folder-specific details in the folder.


2. Writing CLAUDE.md Well

Claude Code auto-loads CLAUDE.md from the working directory at session start and merges it into the system prompt. It also walks the parents of the file you're editing, finds more CLAUDE.md files, and merges them with the global ~/.claude/CLAUDE.md. A well-written file visibly improves results with the same model.

2.1 The Shape of a Good CLAUDE.md

# Project: Acme Web

## Stack
- Next.js 15 (App Router), TypeScript strict, Tailwind v4
- Drizzle ORM + Postgres 16
- Vitest + Playwright

## Conventions
- All server actions live in `app/_actions/` and import zod schemas from `lib/schemas/`.
- Database access goes through `lib/db/repositories/`. Do NOT import drizzle directly in components.
- Error type: throw `AppError` (see `lib/errors.ts`); the global handler converts to JSON.

## Verification (do this before reporting "done")
- `pnpm typecheck`
- `pnpm test --run`
- `pnpm lint`

## Permissions
- You may run: pnpm scripts, git read commands, gh CLI for issues/PRs.
- You may NOT run: git push, gh pr merge, anything that mutates production.

The point is that it is short and action-oriented. Only the things "this repo does differently."

2.2 Length — Cap at 200 Lines

A 1000-line CLAUDE.md causes two problems at once. First, you pay tokens for it every turn. Second, the model cannot uniformly follow that many rules — the middle gets watered down as length grows.

Rule of thumb: split at 200 lines. Two patterns:

  • Per-folder CLAUDE.md — backend rules in apps/api/CLAUDE.md, frontend in apps/web/CLAUDE.md. Claude Code merges them automatically.
  • Separate docs — long, rarely-referenced policies (security ops, data retention) go in their own markdown; CLAUDE.md just says "read docs/security.md when needed."

2.3 What to Include, What to Exclude

Include:

  • Non-standard conventions of this repo (don't restate universal rules — "TypeScript is strict" is the default almost everywhere, no need to spell it out)
  • Common pitfalls ("In this repo we use date-fns, never dayjs")
  • The verification procedure — which commands count as "done"
  • Prohibitions — no force-push, no auto-running migrations, etc.

Exclude:

  • Generalities the model already knows ("write clean code" is noise)
  • Volatile temporary notes (those belong in tickets or PRs)
  • Secrets (this file is committed; never put tokens or keys here)

2.4 A Per-Folder CLAUDE.md Example

Keeping apps/api/CLAUDE.md separately means its rules merge only when working on backend code.

# apps/api

## Boundaries
- Controllers in `routes/` — only HTTP concerns.
- Business logic in `services/`.
- DB access in `repositories/` (Drizzle).

## Tests
- Unit tests next to the file (`*.test.ts`).
- Integration tests in `tests/integration/` — they spin up testcontainers Postgres.

3. AGENTS.md — The Cross-Tool Standard

Starting in late 2025, OpenAI Codex began promoting AGENTS.md, a movement to "let every coding agent read the same markdown placed in the repo." As of 2026, Codex, some Cursor modes, and several OSS agents recognize this file. The format is free-form markdown.

3.1 A Typical AGENTS.md

# AGENTS.md

This file gives AI coding agents the context they need to work in this repository.

## What this repo is
A pnpm monorepo with `apps/web` (Next.js), `apps/api` (Fastify), and `packages/*` shared libs.

## Setup
- Node 20.18+, pnpm 9.
- `pnpm install` from root.
- `pnpm dev` runs all apps in parallel.

## Test
- `pnpm test` — unit tests across the workspace.
- `pnpm test:e2e` — Playwright; requires Docker for testcontainers.

## Coding rules
- TypeScript only. No JS files in `src/`.
- Public APIs go in `packages/*/src/index.ts` re-exports.
- New endpoints need a zod request schema and 1+ test.

## Don't
- Don't commit secrets. `.env.local` is gitignored on purpose.
- Don't change `pnpm-lock.yaml` without running `pnpm install`.

3.2 Relationship to CLAUDE.md

When two tools don't read the same file, you don't want to write the same content twice. Two common patterns:

  • AGENTS.md as the single source — All shared rules go in AGENTS.md. CLAUDE.md keeps one line.

    # CLAUDE.md
    Read AGENTS.md first. Anything below is Claude-specific addenda.
    
    ## Claude-only
    - When running shell commands, prefer pnpm over npm here.
    
  • CLAUDE.md as the single source — If you only use Claude, skip AGENTS.md or symlink it. The downside is no guarantee when another agent shows up.

How to choose: one tool only? Single file. Two or more? Treat AGENTS.md as the single source of truth and keep tool files thin.

3.3 Real Examples

There are good public examples. Vercel's OSS repos (vercel/next.js, vercel/ai) tend to keep a relatively short, direct AGENTS.md focused on build/test commands and a "before you PR" checklist. Anthropic's SDK repos (anthropics/anthropic-sdk-python etc.) use CLAUDE.md, often with a temporary "this season's changes" block at the top during migrations. Take these patterns directly.


4. Cursor Rules

Cursor maintains two rule systems — legacy and modern. As of 2026, both still work.

4.1 Legacy — .cursorrules

A single flat markdown at the repo root.

# Cursor Rules

- Use TypeScript strict mode and avoid `any`.
- Prefer named exports.
- React components: function components with explicit prop types.
- All API handlers must validate input with zod.

## When generating tests
- Use Vitest.
- Place test files adjacent to source as `*.test.ts`.

Pro: simple. Con: no branching. The same rules apply to every file.

4.2 Modern — .cursor/rules/*.mdc

Several *.mdc files under .cursor/rules/, each declaring its application conditions in a header.

---
description: "Backend API rules — Fastify routes"
globs:
  - "apps/api/src/routes/**/*.ts"
alwaysApply: false
---

# Backend API rules

- Every route declares its zod schema via `schema:` option.
- Use `app.log` not `console.log`.
- Error handling: throw `AppError` (see lib/errors.ts).

Conditions usually split two ways. Either the file matches a globs pattern of the open file, or the user invokes the rule explicitly via a slash command. This modular approach is cleaner than .cursorrules, so for new repos prefer .cursor/rules/ from the start.

4.3 Cursor Agents — agents.json

Cursor's "agent mode" can have its own agent definitions. The root agents.json declares which tools are allowed, which mode to run in, etc. Details shift quickly between Cursor versions, so follow official docs. For this post, knowing "this file exists" is enough.


5. GitHub Copilot, README.dev, CONTRIBUTING

5.1 .github/copilot-instructions.md

GitHub Copilot Chat automatically merges this file into its system prompt when present. The usage pattern resembles CLAUDE.md, but shorter is better — Copilot models usually work with a tighter context window.

# Copilot Instructions

- This repo uses pnpm, Next.js 15, Drizzle, Vitest.
- Always type API responses (no `any`).
- For React components, prefer server components unless interactivity is required.
- New endpoints must validate input with zod.

5.2 README.dev.md

If README.md is the face shown to the outside, README.dev.md (or docs/dev.md) is the face shown to internal developers and agents. Typical contents:

  • First-time local setup (deps, env, DB seeding)
  • A list of frequently used commands (pnpm dev, pnpm db:reset, pnpm e2e:headed)
  • One directory tree
  • "Common stumbling blocks for newcomers"

This file helps both agents and new hires, which makes it one of the highest-ROI docs you can write.

5.3 CONTRIBUTING.md

In OSS repos it's for external contributors, but in internal repos writing down "how do we open a PR, how do we review" still pays off — agents follow it. If it overlaps with AGENTS.md, put it on one side and link from the other.


6. Claude Code Skills — Reusable Workflows

Skills are a powerful Claude Code feature. A markdown bundle of a procedure you repeat often, callable by name. Location: .claude/skills/<name>/SKILL.md (repo-local) or ~/.claude/skills/ (global).

6.1 The Shape of a SKILL.md

---
name: release-blog-post
description: Write, validate, and commit a trilingual blog post under data/blog/
when_to_use: User says "write a blog post" with a topic.
---

# Release Blog Post

1. Confirm filename slug: `data/blog/<category>/<YYYY-MM-DD>-<slug>.mdx`
2. Draft Korean version first.
3. Translate to en.mdx and ja.mdx, preserving structure.
4. Validate:
   ```bash
   npx tsx val.ts data/blog/.../<slug>.mdx data/blog/.../<slug>.en.mdx data/blog/.../<slug>.ja.mdx
   ```
5. Fix any reported issues, re-run until clean.
6. Stage and commit with message: `post: <topic> (ko/en/ja)`.

6.2 How to Write Skills Well

  • Make the trigger (when_to_use) crisp — the model decides when to call this Skill.
  • Procedure as a short numbered list. One step = one sentence = one action.
  • Verification at the end. If that step fails, the spec must tell the model to go back and fix.
  • Skills don't call other Skills — dependencies make them hard to debug.

6.3 Skill vs CLAUDE.md vs Subagent

AssetWhen invokedWhat it holds
CLAUDE.mdAlways at session start"How to behave in this repo" — static rules
SkillModel decides based on triggerRecurring procedures, checklists
SubagentMain agent delegatesLarge tasks needing isolated context

Keeping the three distinct yields a clean design.


7. Subagents and Hooks

7.1 Subagents (.claude/agents/)

A subagent is what you delegate to when a task should run in a different context with a different toolset. Code review, security scans, large searches. The definition is markdown.

---
name: security-review
description: Reviews code for security issues — secrets, injection, auth bypass.
tools: [Read, Grep, Bash]
---

You are a security reviewer.

Process:
1. Search for hardcoded secrets (regex on common patterns).
2. Look for SQL/command injection in user-input paths.
3. Check authn/authz boundaries.

Output: a markdown report with severity tags (P0/P1/P2).

The biggest value of a subagent is context isolation. 100k tokens of search results don't dump into the main session.

7.2 Hooks (.claude/hooks/)

A hook is a small script that fires on session events. Common patterns:

  • pre_tool_use — Warn on dangerous commands (rm -rf, git push --force)
  • post_tool_use — Auto-run a formatter after a file edit
  • session_start — Print environment info so the model gets fresh context
  • notification — Push status to an external system (Slack, an alarm)

A typical definition:

[[hooks]]
event = "post_tool_use"
matcher.tool = "Edit"
matcher.path = "*.ts"
command = "pnpm prettier --write"

Because hooks touch your environment, design them to fire only in this repo.


8. MCP Server Config — The Agent's Toolbox

MCP (Model Context Protocol) is the standard protocol for attaching tools to a model. Claude Code reads .mcp.json to decide which MCP servers to start for a given repo.

8.1 .mcp.json Example

{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-postgres"],
      "env": {
        "POSTGRES_URL": "postgres://app:app@localhost:5432/app"
      }
    },
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_TOKEN": "${env:GITHUB_TOKEN}"
      }
    }
  }
}

With this file, the model gets the postgres MCP's query tool and the github MCP's issue/PR tools exposed. It can write SQL on the fly or open and close GitHub issues itself.

8.2 Which MCPs to Install

The rule is "tool-ify the external calls your team makes most." Candidates:

  • Databases (Postgres, MySQL) — infinitely useful for ad-hoc debugging queries
  • GitHub/GitLab — issues, PRs, comments
  • Observability (Sentry, Datadog, Grafana) — pulls error context automatically
  • A slim MCP wrapping your internal API — wiki, design system, RBAC lookups

Too many MCPs make context heavy. Aim for under 5 per session. Turn the rare-use ones off and on as needed.

8.3 Handling Secrets

.mcp.json is usually committed, but you never put env values there. Use ${env:VAR} syntax, or keep secret-bearing entries in a .mcp.local.json (gitignored). Claude Code merges the two automatically.


9. Permissions and Sandboxing

The biggest risk of an autonomous agent is "unexpected behavior." 2026 tools provide two mechanisms.

9.1 Claude Code Permission Modes

Claude Code supports modes like these (names vary slightly across versions; meaning is similar).

  • default — Asks for confirmation on every dangerous command.
  • acceptEdits — File edits auto-approve, external commands (shell, network) still confirm.
  • plan — Read-only. Plans but does not change anything.
  • bypassPermissions — Skips all confirmations. Only inside isolated environments.

To pin the permission mode at the repo level, drop this in .claude/settings.json.

{
  "permissions": {
    "allow": [
      "Bash(pnpm test*)",
      "Bash(pnpm typecheck)",
      "Bash(git status)",
      "Bash(git diff*)"
    ],
    "deny": [
      "Bash(git push*)",
      "Bash(gh pr merge*)"
    ]
  }
}

Core idea: reads and builds/tests auto-allow, anything that changes the outside world always asks. This rule alone removes a huge class of accidents.

9.2 Cursor Agent Allowlists

Cursor agents have similar allow/deny lists. The common recommendation is "tests and lint and typecheck unlimited, package install confirm, git push block."

9.3 Sandboxes — Worktrees, Containers, Dev Containers

Separately from permissions, isolating the work itself is becoming standard.

  • git worktree — A feature that checks out multiple branches of one repo into separate directories at once. Restrict the agent to a worktree and it cannot collide with your main work.
  • dev container / Docker — The agent runs in a container with controlled dependencies and network. Claude Code has an official Docker image; using it isolates the host OS.
  • Cloud sandboxes — Some modes (OpenAI Codex, others) run in cloud VMs. The host is never touched.

The more autonomy you want, the stronger the sandbox. The two dials are not the same axis — they are orthogonal.


10. What Makes a Codebase Agent-Friendly

Even with perfect config files, the code itself has to cooperate. There is such a thing as "code that's pleasant for agents to work in."

10.1 Five Traits

  1. Strong types — TypeScript strict, Python typing fully on, Rust. The model has to infer intent from signatures alone.
  2. Clear boundaries — A simple import graph between modules, and the responsibility of each module is one sentence.
  3. Fast tests — Unit tests need to finish in under 10 seconds for the agent to verify at every step. If tests take minutes, the agent will skip verification.
  4. Good error messages — A message like Error: invalid input gives the model nothing. Error: 'email' must be a valid RFC 5322 address (got "foo@") is a debugging clue.
  5. Naming consistency — Similar things should be named similarly so the model's generalization works. Mixing userService.findById with OrderRepository.get confuses it.

10.2 "Tests as the Agent's Verifier"

The single strongest pattern is "pre-decide how the agent verifies its own change." The "Verification" section in CLAUDE.md/AGENTS.md plays this role. The model changes code, runs tests, fixes on failure, loops — internally. The more closed that loop is, the less human intervention is needed.

10.3 Small Units = Small PRs = Good Agent Output

Agents do their best work when not asked to change too much at once. So the codebase itself needs to be shaped so that "small PRs come naturally." If modules are too large, an agent's one task automatically becomes huge. This is just good engineering — but it pays double in the agent era.


11. Anti-Patterns — How to Ruin It

11.1 Over-Long Context Files

The most common mistake. A 2000-line CLAUDE.md burns that many tokens every turn while the model forgets the rules in the middle. Self-restraint at 200 lines is essential.

11.2 Conflicting Instructions

CLAUDE.md says "use pnpm," AGENTS.md says "use npm." The model picks one at random. Designate a single source of truth and have the other files reference it.

11.3 Empty Placeholders, Stale Commands

A CLAUDE.md still containing "This file is a stub — fill in your project details" — the model takes that seriously. Or a command from six months ago that no longer works — the agent runs it and fails. Ideally, lint context files in CI (detect empty placeholders).

11.4 Leaked Secrets

API keys typed directly into MCP config, or tokens hard-coded into a hook script and committed. Never. Inject through env vars, OS keychain, or a secrets manager.

11.5 "The Agent Will Handle It" Permissions

bypassPermissions as the default plus git push auto-allowed. One accident wrecks the main branch. Default conservative, full autonomy only inside an isolated worktree/container.

11.6 Skills Too Small or Too Large

A 5-line Skill should just live in the system prompt; a 200-line Skill is no longer a Skill but a separate doc. One Skill = one screen (50–80 lines).

11.7 Updating Context Files Only by Humans

The deploy procedure or CI command changed but CLAUDE.md still holds the old command — the agent wastes effort. The cheapest fix is a checkbox in the PR template: "related context files updated."


Epilogue — Time Invested in the Environment Compounds

The essence of a good agent setup is one thing. Make humans and tools work off the same page. Good guides for humans are good for agents; good procedures for agents are good for new hires. There is barely a separate standard between the two.

Investing time in context files can feel heavy. But this isn't time spent on a single PR. It is time that accumulates across every future session. A well-written 200-line CLAUDE.md gets read hundreds of times a year. An extra hour spent on those 200 lines is an hour multiplied by a thousand.

Best-Practice Checklist

  1. AGENTS.md — a cross-tool single source of truth exists
  2. CLAUDE.md — under 200 lines, non-standard conventions and verification
  3. Per-folder CLAUDE.md — in a monorepo, split per app/package
  4. .cursor/rules/ — modular, glob-branched rules
  5. .github/copilot-instructions.md — a short summary for Copilot
  6. README.dev.md — local setup and frequent commands
  7. .claude/skills/ — bundled recurring workflows (name-triggered)
  8. .claude/agents/ — delegated tasks needing context isolation
  9. .claude/hooks/ — automation like formatters and alerts
  10. .mcp.json — frequently called external systems tool-ified (committed); secrets in .mcp.local.json
  11. permissions — auto-allow read/build/test, confirm anything mutating
  12. sandboxes — autonomous mode only inside a worktree or container
  13. CI lint on context files — detect empty placeholders and stale commands
  14. PR template — "related context files updated" checkbox
  15. Quarterly review — context files live like code

Anti-Patterns Recap

  • 2000-line CLAUDE.md — the model forgets the middle; cap at 200
  • Conflicting instructions — designate a single source of truth
  • Direct secrets — use env vars and .mcp.local.json
  • Full autonomy default — always conservative defaults + explicit opt-in
  • Empty placeholders — detect in CI, block in PR
  • No context update on infra change — enforce via PR-template checkbox
  • Too many MCPs — keep under 5 per session, off the rest
  • Skills sliced too thin — 5-line ones belong in the system prompt

Next Post

The next post is "AI Code Review Workflow — Using Human and Agent Reviewers Together." If good context files help authoring, a good review process secures output quality. What humans should review, what agents catch best, how to weave both into PR templates and CI — and how to arrive at a system where "the agent writes the PR and the human only reviews."

Tools change every year. Standards change more slowly. Environments, set up once, last a year. Don't spend your next hour on the most expensive code — spend it on the environment that produces that code.

References