# Panduan konfigurasi CLAUDE.md

`CLAUDE.md` adalah **file konfigurasi tingkat proyek** Claude Code. Setiap kali Claude Code dimulai, ia otomatis membaca `CLAUDE.md` proyek untuk mempelajari arsitektur proyek, konvensi coding, dan kesepakatan khusus, sehingga dapat memahami proyek Anda dengan lebih akurat.

## Mengapa Anda memerlukan CLAUDE.md

Tanpa CLAUDE.md, Anda mungkin perlu menjelaskan berulang kali di setiap percakapan:
- "Proyek ini menggunakan pnpm, bukan npm"
- "Perintah test adalah `yarn test:unit`, bukan `npm test`"
- "Semua komponen menggunakan TypeScript — tidak boleh ada tipe `any`"

Tulis informasi ini ke dalam CLAUDE.md dan Claude akan membacanya otomatis setiap kali mulai, sehingga Anda tidak perlu mengulanginya lagi.

## Hierarki file

Claude Code membaca dan menggabungkan file CLAUDE.md dari beberapa tingkat:

| Lokasi | Cakupan |
|----------|-------|
| `~/.claude/CLAUDE.md` | Konfigurasi global, berlaku untuk semua proyek |
| `<project root>/CLAUDE.md` | Konfigurasi proyek, di-commit ke Git untuk dibagikan ke tim |
| `.claude/CLAUDE.md` | Konfigurasi proyek privat, dapat ditambahkan ke `.gitignore` |
| `CLAUDE.md` di subdirektori | Hanya dibaca saat Claude beroperasi di direktori tersebut |

## Penyiapan cepat

Gunakan perintah `/init` untuk membuatnya secara otomatis:

```
/init
```

Claude akan menganalisis struktur proyek saat ini dan otomatis membuat CLAUDE.md yang berisi informasi proyek.

## Struktur dasar

```markdown
# Project Name

## Overview
Brief description of the project's purpose and tech stack.

## Tech Stack
- Runtime: Node.js 20
- Framework: Next.js 15
- Styling: Tailwind CSS
- Database: PostgreSQL + Prisma

## Common Commands
- Start dev server: `npm run dev`
- Run tests: `npm test`
- Build for production: `npm run build`
- Lint code: `npm run lint`

## Coding Conventions
- Use TypeScript; no `any` types allowed
- Components use functional style
- Styling with Tailwind only — no inline styles
- Commit message format: `feat:` / `fix:` / `docs:` prefixes, etc.

## Project Structure
- `src/app/` — Next.js App Router pages
- `src/components/` — Reusable components
- `src/lib/` — Utility functions
- `prisma/` — Database schema and migrations

## Notes
- Do not modify `prisma/migrations/` — only create new migrations
- All API routes are under `src/app/api/`
- Image assets go in `public/images/`
```

## Tips praktis

### 1. Tentukan package manager

```markdown
## Package Management
Use pnpm — do not use npm or yarn.
Install dependencies: `pnpm install`
Add a dependency: `pnpm add <package>`
```

### 2. Dokumentasikan konvensi testing

```markdown
## Testing
- Unit tests: `vitest`, files end in `.test.ts`
- E2E tests: `playwright`, located in `tests/e2e/`
- Run unit tests: `pnpm test:unit`
- Run E2E: `pnpm test:e2e`
- New features must include tests
```

### 3. Tentukan tindakan yang dilarang

```markdown
## Prohibited Actions
- Do not use `console.log` — use the project's `logger` module instead
- Do not modify `package-lock.json` directly
- Do not commit directly to `main` — use feature branches
```

### 4. Berikan konteks arsitektur

```markdown
## Architecture Overview
This project follows Hexagonal Architecture:
- `domain/` — Business logic, no external framework dependencies
- `application/` — Use cases, coordinating domain and infrastructure
- `infrastructure/` — External adapters for databases, HTTP, etc.
- `interfaces/` — Entry points such as web controllers and CLI

New features should follow this layering — do not introduce external dependencies in the domain layer.
```

### 5. Rujuk dokumen lain

```markdown
## Further Reading
- API documentation: `docs/api.md`
- Deployment process: `docs/deploy.md`
- Database schema: `prisma/schema.prisma`
```

## CLAUDE.md dan pengelolaan konteks

Isi CLAUDE.md memakan ruang konteks. Rekomendasi:
- Jaga CLAUDE.md tetap ringkas dan fokus pada informasi terpenting
- Untuk dokumentasi arsitektur yang detail, berikan rujukan path file di CLAUDE.md alih-alih menyalin isinya langsung
- Dalam sesi panjang, CLAUDE.md selalu tetap terlihat (tidak akan dihapus oleh `/compact`)

## Template proyek

Struktur di bawah ini adalah titik awal CLAUDE.md yang sudah teruji untuk tipe proyek umum. Salin yang sesuai dengan stack Anda dan sesuaikan detailnya.

### Template 1: Frontend React + TypeScript

```markdown
# MyApp Frontend

## Tech Stack
- React 19 + TypeScript 5.x
- Build tool: Vite 6
- Styling: Tailwind CSS v4 (utility-first, no inline styles)
- State management: Zustand (global), TanStack Query (server state)
- Routing: React Router v7
- Testing: Vitest + Testing Library + MSW

## Commands
- Dev: `pnpm dev` (port 3000)
- Test: `pnpm test` (Vitest watch mode)
- Single run: `pnpm test:run`
- Build: `pnpm build`
- Lint: `pnpm lint` (ESLint + Prettier)
- Type check: `pnpm typecheck`

## Coding Conventions
- Components: functional components + Hooks, no class components
- Props: define with `interface` (not `type`)
- File names: components in PascalCase (UserProfile.tsx), utilities in camelCase (formatDate.ts)
- Import order: React → third-party → internal → styles
- No `any` type; explicit type annotations are required
- Async work goes through TanStack Query, not direct `useEffect` + `fetch`

## Project Structure
- src/components/ — reusable UI components
- src/pages/ — route pages
- src/hooks/ — custom Hooks
- src/api/ — API request wrappers (TanStack Query queryFn)
- src/stores/ — Zustand stores
- src/lib/ — utility functions
- src/types/ — global type definitions

## Notes
- Package manager: pnpm (not npm or yarn)
- Node.js 22+
- All API requests go through src/api/client.ts (with interceptors)
- Images live in public/images/, referenced via the /images/ path
```

### Template 2: Backend Python + FastAPI

```markdown
# MyApp Backend

## Tech Stack
- Python 3.12 + FastAPI
- ORM: SQLAlchemy 2.0 (async) + Alembic migrations
- Database: PostgreSQL 16
- Cache: Redis 7
- Testing: pytest + httpx + factory_boy

## Commands
- Dev: `uvicorn app.main:app --reload --port 8000`
- Test: `pytest -xvs`
- Migrate: `alembic upgrade head`
- New migration: `alembic revision --autogenerate -m "description"`
- Lint: `ruff check .`
- Format: `ruff format .`
- Type check: `mypy app/`

## Coding Conventions
- Type hints: all function parameters and return values must have type hints
- async/await: all I/O operations use async
- Pydantic v2: request/response schemas use Pydantic BaseModel
- Dependency injection: inject database connections, auth, etc. via FastAPI Depends()
- Error handling: business exceptions inherit from app.exceptions.AppError

## Project Structure
- app/main.py — application entry point
- app/api/ — routes (one file per resource)
- app/models/ — SQLAlchemy models
- app/schemas/ — Pydantic schemas
- app/services/ — business logic
- app/core/ — config, database, security, and other core modules
- tests/ — test files (mirror the app/ structure)
- alembic/ — database migrations

## Notes
- Do not modify existing migration files under alembic/versions/
- The .env file is not committed to Git; it is loaded via the Settings class in app/core/config.py
- Virtual environment: `python -m venv venv && source venv/bin/activate`
```

### Template 3: Microservice Go

```markdown
# MyService

## Tech Stack
- Go 1.23
- HTTP framework: Echo v4
- Database: PostgreSQL + sqlc (type-safe SQL)
- Message queue: NATS JetStream
- Containerization: Docker + docker-compose

## Commands
- Run: `go run ./cmd/server`
- Test: `go test ./...`
- Build: `go build -o bin/server ./cmd/server`
- Generate sqlc: `sqlc generate`
- Lint: `golangci-lint run`

## Coding Conventions
- Error handling: always check err, never ignore it with _
- Interface naming: single-method interfaces take the -er suffix (Reader, Writer)
- Package naming: lowercase words, no underscores
- Logging: use slog for structured logging
- Context: pass context.Context as the first parameter of every function

## Project Structure (standard Go layout)
- cmd/server/ — main program entry point
- internal/handler/ — HTTP handlers
- internal/service/ — business logic
- internal/repository/ — data access layer
- internal/model/ — data models
- sql/ — SQL query files (used by sqlc)
```

### Template 4: Monorepo (Turborepo)

```markdown
# MyPlatform Monorepo

## Tech Stack
- Package management: pnpm workspace
- Build system: Turborepo
- Language: TypeScript across the stack

## Commands
- Global dev: `pnpm dev`
- Global test: `pnpm test`
- Global build: `pnpm build`
- Single-package dev: `pnpm --filter @myplatform/web dev`
- Add a dependency: `pnpm --filter @myplatform/api add express`

## Package Structure
- apps/web/ — Next.js frontend
- apps/api/ — Express backend
- apps/admin/ — admin dashboard
- packages/ui/ — shared UI component library
- packages/config/ — shared config (eslint, tsconfig)
- packages/types/ — shared type definitions

## Notes
- Shared code goes in packages/; do not import directly between apps
- When creating a new package, follow the format of packages/ui/package.json
- Turborepo cache: build artifacts are cached in node_modules/.cache/turbo
```

### Template 5: Proyek Data Science / ML

```markdown
# ML Pipeline

## Tech Stack
- Python 3.12
- Framework: PyTorch 2.5 + Lightning
- Data processing: Polars (not Pandas)
- Experiment tracking: MLflow
- Dependency management: uv

## Commands
- Train: `python -m src.train --config configs/experiment.yaml`
- Evaluate: `python -m src.evaluate --checkpoint runs/latest`
- Preprocess data: `python -m src.preprocess --data-dir data/raw`
- Jupyter: `jupyter lab`
- Test: `pytest tests/`

## Coding Conventions
- Use YAML for configuration (do not hard-code hyperparameters)
- Use Polars for data processing (faster than Pandas, type-safe)
- All experiments must be logged to MLflow
- Notebooks are for exploration only; production code must live in src/

## Project Structure
- configs/ — experiment configuration YAML
- data/raw/ — raw data (not committed to Git, managed with DVC)
- data/processed/ — processed data
- src/ — core code (model, data, train, evaluate)
- notebooks/ — exploratory analysis
- runs/ — training outputs (checkpoints, logs)
```

## Praktik terbaik kolaborasi tim

### Strategi Git

```
CLAUDE.md          → commit to Git (shared by the team)
.claude/CLAUDE.md  → add to .gitignore (personal configuration)
```

Tambahkan ini ke `.gitignore`:

```gitignore
# Personal Claude Code configuration
.claude/CLAUDE.md
.claude/settings.local.json
```

### Daftar periksa peninjauan kode

Pada setiap peninjauan PR, periksa:
- Apakah CLAUDE.md diperbarui saat teknologi baru diperkenalkan?
- Apakah bagian “Project Structure” diperbarui saat tata letak berubah?
- Apakah bagian “Commands” diperbarui saat perintah penting ditambahkan?

### Panduan orientasi

CLAUDE.md juga berfungsi sebagai dokumen orientasi terbaik untuk sebuah proyek:
1. Setelah melakukan clone, developer baru membaca CLAUDE.md untuk memahami gambaran besarnya
2. Mereka menjalankan `claude` → Claude sudah mengetahui semua konvensi proyek
3. Mereka mulai menjelajahi proyek dengan `> help me understand this project`

---

## Tips lanjutan

### Rujuk, jangan sisipkan

CLAUDE.md tidak seharusnya menjadi terlalu panjang. Untuk dokumen yang terperinci, rujuk path-nya alih-alih menyisipkan isinya:

```markdown
## Architecture
Detailed architecture doc: `docs/architecture.md`.
API design conventions: `docs/api-design.md`.
Database schema: `prisma/schema.prisma`.
```

Claude membaca file tersebut secara otomatis saat membutuhkannya.

### Hubungan dengan AGENTS.md

| | CLAUDE.md | AGENTS.md |
|---|---|---|
| Alat | Claude Code | Codex CLI |
| Format | Markdown | Markdown |
| Isi | 80%+ dapat digunakan kembali | 80%+ dapat digunakan kembali |

Jika Anda menggunakan Claude Code dan Codex, kedua file dapat digunakan bersamaan:
- **Konten bersama**: tumpukan teknologi, perintah, standar coding, struktur proyek
- **Khusus alat**: panduan `/model` dan `/plan` untuk Claude ditempatkan di CLAUDE.md; konfigurasi mode persetujuan Codex ditempatkan di AGENTS.md

> Lihat [Panduan AGENTS.md](/docs/usage/agents-md).

### Mengendalikan pemakaian konteks

Isi CLAUDE.md selalu ada dalam konteks (`/compact` tidak pernah menghapusnya). Rekomendasi:

- **Jaga totalnya di bawah 500 baris**
- Rujuk path alih-alih menyisipkan dokumen terperinci
- Jangan letakkan informasi yang sering berubah di sana (seperti progres saat ini)
- Jangan letakkan contoh kode di sana (Claude dapat membaca kode sumbernya sendiri)

---

## Kesalahan umum dan debugging

### CLAUDE.md tidak dibaca

```bash
# Confirm the file is in the project root
ls -la CLAUDE.md

# Confirm Claude sees it
claude
> Do you see CLAUDE.md? What tech stack does it describe?
```

### Terlalu panjang dan menguras konteks

```bash
# Check the line count
wc -l CLAUDE.md
# Over 500 lines: trim it

# Check context usage
/cost
```

### Perilaku anggota tim berbeda-beda

File global `~/.claude/CLAUDE.md` setiap orang berbeda. Jika tim mengalami perilaku yang tidak konsisten, periksa:
1. Apakah CLAUDE.md di root proyek sudah cukup spesifik?
2. Apakah seseorang telah menimpa aturan tim di `.claude/CLAUDE.md`?

---

## CLAUDE.md vs AGENTS.md — Cara memilih

Claude Code membaca `CLAUDE.md` secara bawaan (beserta file memori dan aturan yang berlaku untuk path tertentu). Sebagian besar alat **lain** — Cursor, Codex, GitHub Copilot, Cline, Gemini / Antigravity, Aider, Zed, dan lainnya — membaca `AGENTS.md` sebagai gantinya. File yang Anda kelola bergantung pada jumlah alat yang digunakan tim Anda.

| Skenario | Rekomendasi |
|----------|----------------|
| **Satu alat (hanya Claude Code)** | `CLAUDE.md` sudah cukup — AGENTS.md tidak diperlukan |
| **Tim dengan beberapa alat** | Gunakan `AGENTS.md` sebagai sumber acuan bersama, ditambah `CLAUDE.md` ringkas yang mengimpornya |

### Satu alat: cukup CLAUDE.md

Jika semua anggota tim menggunakan Claude Code, letakkan semuanya di `CLAUDE.md`. Tidak ada manfaatnya menambahkan file kedua.

### Beberapa alat: AGENTS.md sebagai sumber acuan

Ketika tim menggunakan Claude Code bersama Cursor, Codex, Copilot, atau alat lain, letakkan aturan bersama — tumpukan teknologi, perintah, konvensi coding, struktur proyek — di `AGENTS.md`, lalu buat `CLAUDE.md` sebagai file ringkas yang mengimpornya dan menambahkan hal khusus Claude:

```markdown
# Project Rules

@AGENTS.md

## Claude Code specifics
- Use /model to switch to Opus 5.5 for large refactors
- Reference docs/architecture.md instead of pasting it
```

Baris `@AGENTS.md` memasukkan konten bersama ke dalam konteks Claude Code, sehingga Claude mendapatkan aturan tim **ditambah** hal khusus Claude. **Hindari mengelola dua salinan berbeda** dari aturan yang sama — itulah masalah utamanya, karena kedua file pada akhirnya akan menjadi tidak sinkron.

> Untuk detail tentang format AGENTS.md dan alatnya, lihat [Panduan konfigurasi AGENTS.md](/docs/usage/agents-md).

## Langkah selanjutnya

- Pelajari [Manajemen konteks](/docs/usage/context-management) — kuasai teknik untuk mengelola jendela konteks
- Pelajari [Konfigurasi izin](/docs/usage/permissions) — kendalikan operasi yang boleh dilakukan Claude
- Pelajari [Tips alur kerja](/docs/usage/workflow-tips) — bangun alur kerja Claude Code yang efisien