# Sistem plugin

Sistem plugin Claude Code memungkinkan Anda memperluas kemampuan Claude dengan membuat slash command kustom, agen khusus, skill yang dapat digunakan ulang, dan hook otomatisasi. Dengan plugin, Anda dapat membakukan praktik terbaik dan alur kerja tim Anda.

## Apa itu plugin?

### Konsep inti

Plugin Claude Code adalah direktori dengan struktur file tertentu yang dapat menambahkan komponen berikut:

| Komponen | Deskripsi | Format file |
|-----------|-------------|-------------|
| **Commands** | Slash command kustom | File `.md` |
| **Agents** | Subagen tugas khusus | File `.md` |
| **Skills** | Pengetahuan dan kemampuan yang dapat digunakan ulang | Direktori + `SKILL.md` |
| **Hooks** | Otomatisasi yang dipicu peristiwa | `hooks.json` |

### Mengapa plugin?

- **Standardisasi tim**: Menjadikan standar coding dan kriteria review sebagai perintah yang dapat dieksekusi

- **Otomatisasi alur kerja**: Mengotomatiskan tugas berulang seperti commit, deployment, review

- **Berbagi pengetahuan**: Membagikan praktik terbaik dan keahlian antar anggota tim

- **Pengalaman kustom**: Menyesuaikan perilaku Claude untuk kebutuhan proyek

## Struktur direktori plugin

```
my-plugin/
├── .claude-plugin/
│   └── plugin.json          # Required: Plugin manifest
├── commands/                 # Slash commands (.md files)
│   ├── review.md
│   └── deploy.md
├── agents/                   # Subagent definitions (.md files)
│   └── code-reviewer.md
├── skills/                   # Agent skills (subdirectories)
│   └── coding-standards/
│       └── SKILL.md
├── hooks/
│   └── hooks.json           # Event handler configuration
├── .mcp.json                # MCP server definitions (optional)
└── scripts/                 # Helper scripts (optional)
```

## Mulai cepat

### Memasang plugin

```bash
# Install from marketplace
/plugin install plugin-name@claude-code-marketplace

# Install from local directory
claude --plugin-dir /path/to/my-plugin
```

### Menggunakan wizard pembuatan plugin

```bash
/plugin-dev:create-plugin
```

Perintah ini memandu Anda melalui 8 fase untuk membuat plugin lengkap.

## Membuat perintah kustom

### Format perintah dasar

Buat file `.md` di direktori `commands/`:

```markdown
---
description: Perform code review
argument-hint: [file-path]
allowed-tools: Read, Bash(git status:*), Bash(git diff:*)
---

Please review the code quality of: @$1

Focus on:
1. Code readability
2. Potential bugs
3. Performance issues
4. Security vulnerabilities
```

### Konfigurasi YAML frontmatter

| Field | Deskripsi | Contoh |
|-------|-------------|---------|
| `description` | Deskripsi perintah (ditampilkan di /help) | `Perform code review` |
| `argument-hint` | Petunjuk parameter | `[file-path] [options]` |
| `allowed-tools` | Tool yang diizinkan | `Read, Bash(git status:*), Bash(git diff:*)` |
| `model` | Menentukan model | `opus` atau `sonnet` |

### Menggunakan argumen dinamis

- `$1`, `$2`, `$3`... - Argumen posisional

- `$ARGUMENTS` - Semua argumen

- `@path/to/file` - Referensi file

- `!`command`` - Menjalankan perintah Bash

### Contoh perintah

**Perintah code review** (`commands/review.md`):

```markdown
---
description: Comprehensive code review
argument-hint: [file-or-directory]
allowed-tools: Read, Grep, Glob
model: opus
---

Perform a comprehensive code review of @$1.

Checklist:
- [ ] Code style follows project standards
- [ ] No potential security issues
- [ ] Error handling is complete
- [ ] Tests are needed

If it's a directory, first use Glob tool to find all relevant files.
```

**Perintah smart commit** (`commands/commit.md`):

```markdown
---
description: Smart commit with generated message
allowed-tools: Bash(git status:*), Bash(git diff:*), Bash(git add:*), Bash(git commit:*)
---

1. Run `git status` to see changes
2. Run `git diff --staged` to analyze staged changes
3. Generate a conventional commit message based on changes
4. Execute `git commit`

Commit message format:
- feat: New feature
- fix: Bug fix
- docs: Documentation update
- refactor: Refactoring
- test: Test related
```

> ⚠️ **Jangan pernah menulis `Bash(git:*)`**: wildcard itu mengizinkan setiap subperintah git sekaligus, termasuk yang destruktif seperti `git push --force`, `git reset --hard`, dan mengubah remote. Cantumkan hanya subperintah yang benar-benar Anda butuhkan (`git status` / `git diff` / `git add` / `git commit`), dan jangan menyelipkan `git push` ke dalam perintah commit.

## Membuat agen kustom

### Format definisi agen

Buat file `.md` di direktori `agents/`:

```markdown
---
description: Specialized code review agent
model: opus
tools: Read, Grep, Glob
---

You are a professional code review agent. Your task is to:

1. Carefully read the provided code
2. Identify potential issues
3. Provide specific improvement suggestions
4. Focus on security and performance

Always be constructive and specific.
```

### Jenis agen

| Jenis | Tujuan | Contoh |
|------|---------|---------|
| Agen review | Code review, review PR | `code-reviewer` |
| Agen test | Membuat dan menjalankan test | `test-generator` |
| Agen doc | Membuat dokumentasi | `doc-writer` |
| Agen refactor | Refactoring kode | `refactorer` |

## Membuat skill

### Struktur direktori skill

```
skills/
└── coding-standards/
    ├── SKILL.md              # Required: Skill definition
    ├── references/           # Reference materials
    │   └── style-guide.md
    └── examples/             # Example code
        └── good-practices.md
```

### Format SKILL.md

```markdown
# Coding Standards Skill

## Overview
This skill contains team coding standards and best practices.

## Knowledge Content

### Naming Conventions
- Variables: camelCase
- Constants: UPPER_SNAKE_CASE
- Classes: PascalCase
- Files: kebab-case

### Code Style
- Use 2-space indentation
- Max line width 100 characters
- Use semicolons

### Error Handling
- Always use try-catch
- Log errors
- Provide meaningful error messages
```

## Membuat hook

### Format hooks.json

`hooks.json` menggunakan bentuk yang sama dengan field `hooks` di `settings.json`: nama peristiwa → matcher → array `hooks`. Peristiwa harus berupa peristiwa siklus hidup yang nyata (seperti `PreToolUse` / `PostToolUse`); nama fiktif lama seperti `on_commit` tidak ada.

```json
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "echo \"$TOOL_INPUT\" | grep -qE 'rm -rf /|git push --force' && exit 2 || exit 0"
          }
        ]
      }
    ],
    "PostToolUse": [
      {
        "matcher": "Write|Edit",
        "hooks": [
          {
            "type": "command",
            "command": "npm run lint && npm run typecheck"
          }
        ]
      }
    ]
  }
}
```

### Peristiwa yang didukung

| Peristiwa | Dipicu saat | Dapat memblokir |
|-------|----------------|-----------|
| `PreToolUse` | Sebelum tool berjalan | Ya (exit 2) |
| `PostToolUse` | Setelah tool berjalan | Tidak |
| `UserPromptSubmit` | Pengguna mengirim prompt | Ya |
| `SessionStart` | Sesi dimulai | Tidak |
| `Stop` | Claude menyelesaikan respons | Tidak |
| `Notification` | Claude mengirim notifikasi | Tidak |

Untuk daftar peristiwa lengkap dan sintaks handler, lihat [Sistem hooks](/docs/advanced/hooks).

## Manifest plugin

### Format plugin.json

```json
{
  "name": "my-plugin",
  "version": "1.0.0",
  "description": "My custom plugin",
  "author": "Your Name",
  "components": {
    "commands": ["commands/*.md"],
    "agents": ["agents/*.md"],
    "skills": ["skills/*/SKILL.md"],
    "hooks": "hooks/hooks.json"
  },
  "mcpServers": ".mcp.json"
}
```

## Contoh praktis

### Contoh 1: Plugin code review tim

```
team-review-plugin/
├── .claude-plugin/
│   └── plugin.json
├── commands/
│   ├── review-pr.md          # PR review command
│   ├── security-check.md     # Security check command
│   └── perf-audit.md         # Performance audit command
├── agents/
│   ├── security-reviewer.md  # Security review agent
│   └── perf-analyzer.md      # Performance analysis agent
└── skills/
    └── team-standards/
        └── SKILL.md          # Team standards skill
```

### Contoh 2: Plugin otomatisasi deployment

```
deploy-plugin/
├── .claude-plugin/
│   └── plugin.json
├── commands/
│   ├── deploy-staging.md     # Deploy to staging
│   ├── deploy-prod.md        # Deploy to production
│   └── rollback.md           # Rollback command
├── hooks/
│   └── hooks.json            # Pre-deploy check hooks
└── .mcp.json                 # Kubernetes MCP config
```

## Praktik terbaik

### Desain perintah

1. **Tanggung jawab tunggal**: Setiap perintah melakukan satu hal

2. **Deskripsi jelas**: Jaga deskripsi tetap ringkas

3. **Dokumentasikan parameter**: Gunakan argument-hint untuk menjelaskan parameter

4. **Izin minimal**: Hanya sertakan tool yang diperlukan di allowed-tools

5. **Penanganan error**: Pertimbangkan skenario kegagalan

### Organisasi plugin

1. **Modular**: Kelompokkan fungsi terkait bersama

2. **Dapat digunakan ulang**: Skill harus dapat digunakan oleh beberapa perintah

3. **Terdokumentasi**: Tambahkan README dan petunjuk penggunaan

4. **Berversi**: Gunakan semantic versioning

### Pertimbangan keamanan

1. **Tanpa secret hardcoded**: Gunakan environment variable

2. **Batasi akses file**: Hanya akses path yang diperlukan

3. **Validasi input**: Validasi parameter

4. **Log audit**: Catat operasi sensitif

## Debugging plugin

```bash
# View plugin load status
/plugin list

# View command details
/help my-command

# Test command
/my-command test-argument
```

## Langkah berikutnya

- Pelajari [MCP server](/docs/advanced/mcp) untuk memperluas integrasi eksternal

- Lihat [Tips CLI](/docs/usage/cli-tips) untuk meningkatkan efisiensi

- Jelajahi [Tips alur kerja](/docs/usage/workflow-tips) untuk mengoptimalkan alur pengembangan