Lesson 07 · 12 dk okuma

Mini-proje: PR review otomasyonu

agent + slash command + post-tool-use hook'u birlikte çalıştır.

3 primitive’i birleştir: /review-pr command, code-reviewer sub-agent, PostToolUse hook.

1. Sub-agent

.claude/agents/code-reviewer.md:

---
name: code-reviewer
description: Use when reviewing PR diffs for security and correctness
tools: Read, Grep, Bash(git diff:*)
model: sonnet
---

Sen bir code reviewer'sın. Görevin:
1. `git diff main...HEAD` çalıştır
2. Aşağıdaki kategoriler için bulgu üret:
   - Güvenlik
   - Hata yönetimi
   - Test eksiği
   - API kontratı bozulması
3. Çıktıyı şu format'ta dön:

## Bulgular
- [Kategori] dosya:satır — açıklama

KURALLAR:
- Yorum yapma, sadece bul
- Stil/format yorumu yapma (lint hallediyor)
- 0 bulgu varsa "no issues found"

2. Slash command

.claude/commands/review-pr.md:

---
description: Use when reviewing the current branch
---

`code-reviewer` sub-agent'ını dispatch et. Sonucu olduğu gibi döndür.
Kullanıcı feedback isterse priorize et: Güvenlik > Hata yönetimi > Test > API.

3. Hook

.claude/settings.json:

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [{ "type": "command", "command": "pnpm test --silent || echo 'TESTS FAILED'" }]
      }
    ]
  }
}

Test

Branch’te birkaç değişiklik yap, sonra:

/review-pr

Akış:

  1. code-reviewer dispatch olur
  2. git diff ile değişiklikleri okur
  3. Kategorize eder
  4. Sonra senin manuel Edit’in olursa pnpm test otomatik çalışır

Intermediate path tebrikler

Şimdi sub-agent + command + skill + hook + settings ile workflow tasarlayabilirsin. Sıradaki path Advanced — 27 hook tek tek, MCP server, agent teams, plugins, performance.