01วางไฟล์ให้ Agent หาเจอ

repository structure
project/
├── AGENTS.md                         # Codex: project instructions
├── CLAUDE.md                         # Claude Code: project memory/instructions
├── DESIGN.md                         # architecture + decisions + invariants
├── docs/
│   └── feature-x/
│       ├── requirements.md
│       ├── plan.md
│       ├── tasks.md
│       └── STATUS.md
├── .agents/
│   └── skills/
│       └── project-graph/
│           └── SKILL.md              # Codex repository skill
└── .claude/
    ├── settings.json                 # Claude Code project settings/hooks
    └── skills/
        └── project-graph/
            └── SKILL.md              # Claude Code project skill
เครื่องมือAlways-on contextOn-demand workflow
Codex

AGENTS.md / AGENTS.override.md

.agents/skills/<name>/SKILL.md

Claude Code

CLAUDE.md และไฟล์ซ้อนตาม directory

.claude/skills/<name>/SKILL.md

Claude Code ใช้คำสั่ง /init เพื่อช่วยสร้าง CLAUDE.md ได้ สำหรับ Codex ให้สร้าง AGENTS.md ที่ root โดยตรง แล้วใช้ไฟล์ซ้อนใน subdirectory เมื่อกฎเฉพาะส่วนนั้นต่างจากกฎหลัก

02AGENTS.md และ CLAUDE.md ควรใส่อะไร

เก็บเฉพาะข้อมูลที่ต้องมีแทบทุก task ได้แก่ repository map, commands, coding conventions, safety boundaries และ Definition of Done หลีกเลี่ยง tutorial ยาว รายละเอียด API ทั้งหมด หรือข้อมูลที่เปลี่ยนบ่อย เพราะ instruction แบบ always-on ใช้ context ทุกครั้ง

AGENTS.md
# AGENTS.md

## Repository map
- src/app: routes and pages
- src/components: shared UI
- src/lib: domain data and utilities

## Working agreement
- Preserve unrelated user changes.
- Use rg before broad file reads.
- Run npm run typecheck and npm run lint after TypeScript edits.
- Do not add dependencies without approval.

## Definition of done
- Behavior matches the feature spec.
- Relevant tests and production build pass.
- Update DESIGN.md when architecture or an invariant changes.
CLAUDE.md
# CLAUDE.md

## Project commands
- Dev: npm run dev
- Typecheck: npm run typecheck
- Lint: npm run lint
- Build: npm run build

## Architecture rules
- Server-only secrets never enter client components.
- Reuse shared article components before adding new markup patterns.
- Read DESIGN.md before changing data flow or module boundaries.

## Delivery workflow
1. Confirm scope and Not Included.
2. Implement one verifiable task at a time.
3. Update docs/feature/STATUS.md before ending a long session.
เขียนให้ทำตามได้
  • ใช้คำสั่งและ path จริง ไม่ใช้คำว่า “ตรวจให้ดี”
  • ระบุเมื่อไรต้องถามก่อนและเมื่อไรทำต่อได้
  • แยก repository-wide rules ออกจาก module-specific rules
  • ลบ instruction ที่ CI หรือ formatter บังคับให้อยู่แล้ว
ตรวจว่าโหลดจริง
  • เริ่ม session ใหม่หลังเปลี่ยน instruction หลัก
  • ขอให้ agent สรุป active instruction sources
  • ทดสอบจาก subdirectory ที่มีกฎ override
  • ตรวจ conflict และขนาดไฟล์เป็นระยะ

03SKILL.md: โหลดความรู้เมื่อจำเป็น

Skill เหมาะกับ workflow ที่ใช้ซ้ำและต้องใช้เหตุผล เช่น release, incident review, database migration หรือการสำรวจ codebase ตัวระบบเห็นชื่อและ description ก่อน แล้วจึงโหลด SKILL.md เต็มเมื่อ task ตรงกับขอบเขต นี่คือ progressive disclosure

.agents/skills/project-graph/SKILL.md
---
name: project-graph
description: Query the project knowledge graph before broad codebase exploration. Use for architecture, dependency, impact, or file-relationship questions.
---

1. If graphify-out/graph.json exists, start with a focused graphify query.
2. Open the source files returned by the graph; do not treat inferred edges as facts.
3. After code changes, run graphify update .
4. Report node/edge counts and any stale or ambiguous relationships.

Instructions

ขั้นตอน เงื่อนไขหยุด และรูปแบบผลลัพธ์

scripts/

งาน deterministic ที่ควรรันซ้ำแทนการสร้างใหม่

references/

รายละเอียดที่โหลดเฉพาะเมื่อ workflow ต้องใช้

04DESIGN.md เป็น Architecture Source of Truth

README บอกวิธีเริ่มใช้งาน ส่วน DESIGN.md อธิบายว่าระบบประกอบอย่างไร มี invariant อะไร และทำไมจึงเลือกแบบนี้Agent ใช้เอกสารนี้ป้องกันการแก้เฉพาะหน้าแล้วทำลาย boundary ที่มองไม่เห็น

DESIGN.md
# DESIGN.md

## System context
Who uses the system, external dependencies, trust boundaries.

## Architecture
Modules, ownership, data flow, sync/async boundaries.

## Invariants
- A payment is captured at most once per idempotency key.
- Private user data never enters shared caches.

## Decisions
### ADR-007: Use SQS for email jobs
Context: request latency must not depend on the email provider.
Decision: enqueue an idempotent job; retry with DLQ.
Consequences: eventual delivery and queue observability are required.

## Verification
Commands, dashboards, alerts, recovery and rollback procedures.

อัปเดต DESIGN.md เมื่อ data flow, ownership, public contract, trust boundary หรือ operational invariant เปลี่ยน ไม่จำเป็นต้องแก้เมื่อ refactor ภายในที่ไม่เปลี่ยน behavior ภายนอก

05Token Optimization ด้วย Graphify

Graphify สกัด entity และความสัมพันธ์จาก code/docs เป็น knowledge graph เพื่อให้ agent เริ่มจาก subgraph ที่เกี่ยวข้องแทนการอ่าน repository ทั้งก้อน จากนั้นยังต้องเปิด source file จริงเพื่อยืนยัน โดยเฉพาะ edge ที่เป็น INFERRED หรือ AMBIGUOUS

terminal
# ติดตั้ง CLI
uv tool install graphifyy
graphify install

# สร้างและสำรวจกราฟ
/graphify .
graphify query "authentication flow" --budget 1500
graphify path "API" "Database"

# อัปเดตหลังโค้ดเปลี่ยน
graphify update .
ก่อนใช้กราฟหลังใช้กราฟข้อควรระวัง
อ่านไฟล์กว้าง

ใช้ token กับไฟล์ที่ไม่เกี่ยวข้อง

ถาม query ให้เฉพาะเจาะจงก่อน

ค้นจากคำอย่างเดียว

เห็น occurrence แต่ไม่เห็น relationship

ใช้ graph หา path แล้วตรวจ source จริง

เริ่มใหม่ทุก session

สำรวจ dependency ซ้ำ

อัปเดต graph หลัง structural change

06Setup ที่นำไปใช้ได้จริง

  1. 1
    Initialize

    สร้าง CLAUDE.md ด้วย /init และเขียน AGENTS.md จาก commands จริงของ repo

  2. 2
    Document boundaries

    สร้าง DESIGN.md พร้อม modules, data flow, invariants และ decisions

  3. 3
    Add one useful skill

    เริ่มจาก workflow ที่ทำซ้ำบ่อยและมี trigger ชัด

  4. 4
    Index selectively

    สร้าง Graphify graph แล้วใช้ query ก่อนอ่าน codebase กว้าง

  5. 5
    Measure friction

    ข้อผิดพลาดซ้ำให้แก้ instruction; workflow ซ้ำให้ย้ายเป็น skill

อ่านเอกสารทางการ: OpenAI Codex — AGENTS.md ↗อ่านเอกสารทางการ: OpenAI Codex — Skills ↗อ่านเอกสารทางการ: Claude Code — Extend Claude Code ↗อ่านเอกสารทางการ: Graphify Repository ↗