2026-02-10 01:34:35 +08:00
---
title: Eklentiler
2026-02-10 08:11:44 +08:00
description: opencode'u genişletmek için kendi eklentilerinizi yazı n.
2026-02-10 01:34:35 +08:00
---
2026-02-10 08:11:44 +08:00
Eklentiler, çeşitli olaylara bağlanarak ve davranı şı özelleştirerek opencode'u genişletmenize olanak tanı r. Yeni özellikler eklemek, harici hizmetlerle entegrasyon sağlamak veya opencode'un varsayı lan davranı şı nı değiştirmek için eklentiler oluşturabilirsiniz.
2026-02-10 01:34:35 +08:00
Örnekler için topluluk tarafı ndan oluşturulan [plugins](/docs/ecosystem#plugins)'a göz atı n.
---
## Bir eklenti kullanı n
There are two ways to load plugins.
---
### Yerel dosyalardan
JavaScript veya TypeScript dosyaları nı eklenti dizinine yerleştirin.
- `.opencode/plugins/` - Proje düzeyinde eklentiler
- `~/.config/opencode/plugins/` - Genel eklentiler
Bu dizinlerdeki dosyalar başlangı çta otomatik olarak yüklenir.
---
### npm'den
Yapı landı rma dosyanı zda npm paketlerini belirtin.
```json title="opencode.json"
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-helicone-session", "opencode-wakatime", "@my-org/custom-plugin"]
}
```
Hem normal hem de kapsamlı npm paketleri desteklenir.
[ecosystem](/docs/ecosystem#plugins)'daki mevcut eklentilere göz atı n.
---
### Eklentiler nası l kurulur?
**npm eklentileri** başlangı çta Bun kullanı larak otomatik olarak yüklenir. Paketler ve bağı mlı lı kları `~/.cache/opencode/node_modules/`'da önbelleğe alı nı r.
**Yerel eklentiler** doğrudan eklenti dizininden yüklenir. Harici paketleri kullanmak için, sisteminizin dizininde bir `package.json` oluşturmanı z (bkz. [Dependencies](#dependencies)) veya eklentiyi npm ve [add it to your config](/docs/config#plugins)'de yayı nlamanı z gerekir.
---
### Load order
Eklentiler tüm kaynaklardan yüklenir ve tüm kancalar sı rayla çalı şı r. Yükleme sı rası şöyledir:
1. Global config (`~/.config/opencode/opencode.json`)
2. Project config (`opencode.json`)
3. Global eklenti dizini (`~/.config/opencode/plugins/`)
4. Proje eklenti dizini (`.opencode/plugins/`)
Aynı ad ve sürüme sahip yinelenen npm paketleri bir kez yüklenir. Ancak benzer adlara sahip bir yerel eklenti ve bir npm eklentisinin her ikisi de ayrı ayrı yüklenir.
---
## Eklenti oluştur
Eklenti, bir veya daha fazla eklentiyi dı şa aktaran bir **JavaScript/TypeScript modülüdür**
işlevler. Her işlev bir bağlam nesnesi alı r ve bir kanca nesnesi döndürür.
---
### Dependencies
Yerel eklentiler ve özel araçlar harici npm paketlerini kullanabilir. İhtiyacı nı z olan bağı mlı lı kları içeren config dizininize bir `package.json` ekleyin.
```json title=".opencode/package.json"
{
"dependencies": {
"shescape": "^2.1.0"
}
}
```
2026-02-10 08:11:44 +08:00
opencode bunları yüklemek için başlangı çta `bun install` komutunu çalı ştı rı r. Eklentileriniz ve araçları nı z daha sonra bunları içe aktarabilir.
2026-02-10 01:34:35 +08:00
```ts title=".opencode/plugins/my-plugin.ts"
import { escape } from "shescape"
export const MyPlugin = async (ctx) => {
return {
"tool.execute.before": async (input, output) => {
if (input.tool === "bash") {
output.args.command = escape(output.args.command)
}
},
}
}
```
---
### Temel yapı
```js title=".opencode/plugins/example.js"
export const MyPlugin = async ({ project, client, $, directory, worktree }) => {
console.log("Plugin initialized!")
return {
// Hook implementations go here
}
}
```
Eklenti işlevi şunları alı r:
- `project`: Mevcut proje bilgisi.
- `directory`: güncel çalı şma dizini.
- `worktree`: Git çalı şma ağacı yolu.
2026-02-10 08:11:44 +08:00
- `client`: Yapay zeka ile etkileşime geçmek için opencode'lu bir SDK istemcisi.
2026-02-10 01:34:35 +08:00
- `$`: Bun'un komutları yürütmek için kullandı ğı [shell API](https://bun.com/docs/runtime/shell).
---
### TypeScript desteği
TypeScript eklentileri için türleri eklenti paketinden içe aktarabilirsiniz:
```ts title="my-plugin.ts" {1}
import type { Plugin } from "@opencode-ai/plugin"
export const MyPlugin: Plugin = async ({ project, client, $, directory, worktree }) => {
return {
// Type-safe hook implementations
}
}
```
---
### Olaylar
Eklentiler aşağı daki Örnekler bölümünde görüldüğü gibi etkinliklere abone olabilirler. Burada mevcut farklı etkinliklerin bir listesi bulunmaktadı r.
#### Komut Olayları
- `command.executed`
#### Dosya Olayları
- `file.edited`
- `file.watcher.updated`
#### Kurulum Etkinlikleri
- `installation.updated`
#### LSP Etkinlikler
- `lsp.client.diagnostics`
- `lsp.updated`
#### Mesaj Etkinlikleri
- `message.part.removed`
- `message.part.updated`
- `message.removed`
- `message.updated`
#### İzin Etkinlikleri
- `permission.asked`
- `permission.replied`
#### Sunucu Etkinlikleri
- `server.connected`
#### Oturum Etkinlikleri
- `session.created`
- `session.compacted`
- `session.deleted`
- `session.diff`
- `session.error`
- `session.idle`
- `session.status`
- `session.updated`
#### Yapı lacak Etkinlikler
- `todo.updated`
#### Kabuk Etkinlikleri
- `shell.env`
#### Araç Olayları
- `tool.execute.after`
- `tool.execute.before`
#### TUI Etkinlikler
- `tui.prompt.append`
- `tui.command.execute`
- `tui.toast.show`
---
## Examples
2026-02-10 08:11:44 +08:00
opencode'u genişletmek için kullanabileceğiniz bazı eklenti örneklerini burada bulabilirsiniz.
2026-02-10 01:34:35 +08:00
---
### Bildirim gönder
Belirli olaylar meydana geldiğinde bildirim gönderin:
```js title=".opencode/plugins/notification.js"
export const NotificationPlugin = async ({ project, client, $, directory, worktree }) => {
return {
event: async ({ event }) => {
// Send notification on session completion
if (event.type === "session.idle") {
await $`osascript -e 'display notification "Session completed!" with title "opencode"'`
}
},
}
}
```
MacOS'ta AppleScript'i çalı ştı rmak için `osascript` kullanı yoruz. Burada bildirim göndermek için kullanı yoruz.
:::note
2026-02-10 08:11:44 +08:00
opencode masaüstü uygulaması nı kullanı yorsanı z yanı t hazı r olduğunda veya oturum hataları oluştuğunda otomatik olarak sistem bildirimleri gönderebilir.
2026-02-10 01:34:35 +08:00
:::
---
### .env protection
2026-02-10 08:11:44 +08:00
opencode'un `.env` dosyaları nı okuması nı önleyin:
2026-02-10 01:34:35 +08:00
```javascript title=".opencode/plugins/env-protection.js"
export const EnvProtection = async ({ project, client, $, directory, worktree }) => {
return {
"tool.execute.before": async (input, output) => {
if (input.tool === "read" && output.args.filePath.includes(".env")) {
throw new Error("Do not read .env files")
}
},
}
}
```
---
### Ortam değişkenlerini enjekte etme
Ortam değişkenlerini tüm kabuk yürütmeye (AI araçları ve kullanı cı terminalleri) enjekte edin:
```javascript title=".opencode/plugins/inject-env.js"
export const InjectEnvPlugin = async () => {
return {
"shell.env": async (input, output) => {
output.env.MY_API_KEY = "secret"
output.env.PROJECT_ROOT = input.cwd
},
}
}
```
---
### Custom tools
Eklentiler ayrı ca opencode'a özel araçlar da ekleyebilir:
```ts title=".opencode/plugins/custom-tools.ts"
import { type Plugin, tool } from "@opencode-ai/plugin"
export const CustomToolsPlugin: Plugin = async (ctx) => {
return {
tool: {
mytool: tool({
description: "This is a custom tool",
args: {
foo: tool.schema.string(),
},
async execute(args, context) {
const { directory, worktree } = context
return `Hello ${args.foo} from ${directory} (worktree: ${worktree})`
},
}),
},
}
}
```
`tool` yardı mcı sı , opencode'un çağı rabileceği özel bir araç oluşturur. Bir Zod şeması işlevini alı r ve aşağı dakileri içeren bir araç tanı mı döndürür:
- `description`: Araç ne yapar?
- `args`: Aracı n argümanları için Zod şeması
- `execute`: Araç çağrı ldı ğı nda çalı şan fonksiyon
Özel araçları nı z, yerleşik araçları n yanı sı ra kod açmaya da hazı r olacaktı r.
---
### Günlüğe kaydetme
Yapı landı rı lmı ş günlük kaydı için `console.log` yerine `client.app.log()` kullanı n:
```ts title=".opencode/plugins/my-plugin.ts"
export const MyPlugin = async ({ client }) => {
await client.app.log({
body: {
service: "my-plugin",
level: "info",
message: "Plugin initialized",
extra: { foo: "bar" },
},
})
}
```
Seviyeler: `debug`, `info`, `warn`, `error`. Ayrı ntı lar için [SDK documentation](https://opencode.ai/docs/sdk)'e bakı n.
---
### Compaction hooks
Bir oturum sı kı ştı rı ldı ğı nda içerilen bağlamı özelleştirin:
```ts title=".opencode/plugins/compaction.ts"
import type { Plugin } from "@opencode-ai/plugin"
export const CompactionPlugin: Plugin = async (ctx) => {
return {
"experimental.session.compacting": async (input, output) => {
// Inject additional context into the compaction prompt
output.context.push(`
## Custom Context
Include any state that should persist across compaction:
- Current task status
- Important decisions made
- Files being actively worked on
`)
},
}
}
```
`experimental.session.compacting` kancası , LLM bir devam özeti oluşturmadan önce tetiklenir. Varsayı lan sı kı ştı rma isteminin kaçı racağı etki alanı na özgü bağlamı enjekte etmek için bunu kullanı n.
Ayrı ca `output.prompt` ayarı nı yaparak sı kı ştı rma istemini tamamen değiştirebilirsiniz:
```ts title=".opencode/plugins/custom-compaction.ts"
import type { Plugin } from "@opencode-ai/plugin"
export const CustomCompactionPlugin: Plugin = async (ctx) => {
return {
"experimental.session.compacting": async (input, output) => {
// Replace the entire compaction prompt
output.prompt = `
You are generating a continuation prompt for a multi-agent swarm session.
Summarize:
1. The current task and its status
2. Which files are being modified and by whom
3. Any blockers or dependencies between agents
4. The next steps to complete the work
Format as a structured prompt that a new agent can use to resume work.
`
},
}
}
```
`output.prompt` ayarlandı ğı nda, varsayı lan sı kı ştı rma isteminin tamamen yerini alı r. Bu durumda `output.context` dizisi dikkate alı nmaz.