Complete analysis. Here are the findings.
OpenCode Plugin Ecosystem Analysis
1. caveman-opencode-plugin — Complete Breakdown
What it is
A caveman communication mode plugin for OpenCode. Adapts JuliusBrussee/caveman (54k+ stars) behavioral rules into an OpenCode hook-based plugin. Cuts ~75% output tokens by making AI respond in terse fragments.
Source: dantesCode/caveman-opencode-plugin — 71 stars, 9 commits, 6 npm releases (v0.1.0 → v0.1.5)
Repository Structure
code Copy code
src/
├── index.ts # Plugin entry — exports cavemanPlugin
├── config.ts # Config loader (caveman.json)
├── state.ts # Per-session mode state (Map<sessionId, CavemanState>)
├── setup.ts # Interactive setup wizard
├── commands/
│ ├── commit.ts # /caveman-commit handler
│ ├── mode.ts # /caveman (/caveman-mode) handler
│ └── review.ts # /caveman-review handler
├── skills/
│ ├── caveman.ts # System instruction generator (all modes + examples)
│ ├── commit.ts # Commit message instruction
│ └── review.ts # Code review instruction
└── __tests__/
├── commands.test.ts
├── config.test.ts
└── state.test.ts
build.ts # Bun build script
setup.sh # Bash setup wizard
caveman.json.example # Example config
Source: src/ directory at dantesCode/caveman-opencode-plugin/tree/main/src
Plugin API — How it registers
Entry point (src/index.ts):
typescript Copy code
import type { Plugin, Hooks } from '@opencode-ai/plugin'
const cavemanPlugin: Plugin = async () => {
const hooks: Hooks = {
// Hook implementations
}
return hooks
}
export default cavemanPlugin
Source: src/index.ts:1-3
Hooks Used (3 hooks)
Hook Purpose configRegisters slash commands (/caveman, /caveman-mode, /caveman-commit, /caveman-review) in opencode config experimental.chat.system.transformInjects caveman system instruction into every LLM call. Reads mode from state.ts per sessionID. Appends to output.system[] array command.execute.beforeIntercepts commands before model sees them. Handles /caveman <mode>, /caveman-commit, /caveman-review. Mutates output.parts directly
Source: src/index.ts:10-80
Dependencies
peerDependencies: @opencode-ai/plugin >=1.14.21
devDependencies: @opencode-ai/plugin@1.14.21, @types/node, typescript@6.0.3
Zero runtime dependencies — only imports fs, path, os, process (Node stdlib)
Source: package.json
Build/Publish
Build: bun run build.ts (Bun.build API) + tsc --emitDeclarationOnly
Output: ESM to dist/ directory
TypeScript config: target ES2022, module ESNext, bundler resolution
Published files: dist/ only
No CI/CD workflow visible (no .github/workflows/)
Source: build.ts , tsconfig.json
Relationship to DCP
Mentioned in README as companion plugin : "For context compression, pair with @tarquinen/opencode-dcp." No code dependency. They solve different problems — caveman reduces output tokens, DCP reduces input/context tokens.
Configuration
Two config sources, checked in order:
./caveman.json (project root)
~/.config/opencode/caveman.json (global)
Schema:
json Copy code
{
"enabled": true,
"defaultMode": "full",
"features": {
"caveman": true,
"commit": true,
"review": true
}
}
Source: src/config.ts:1-48 , caveman.json.example
2. @tarquinen/opencode-dcp — Dynamic Context Pruning
What it is
AGPL-3.0 plugin that optimizes token usage by pruning obsolete tool outputs from conversation context. 3.3k stars, 1,349 commits, v3.1.12. 10.5k weekly downloads. The most popular OpenCode plugin.
Source: Opencode-DCP/opencode-dynamic-context-pruning , npm
How context compression works
Uses OpenCode's experimental.chat.messages.transform hook to modify messages before they reach the LLM. Session history is never modified — pruned content replaced with placeholders. Three mechanisms:
Compress tool — LLM-callable tool that replaces stale conversation spans with technical summaries
range mode: compress contiguous spans into summary blocks
message mode (experimental): compress individual messages
Nested summaries: overlapping compressions preserve info through layers
Automatic cleanup — deduplication (remove duplicate tool outputs), error purging
AI nudges — reminds model to use compress after N tool results
Source: DCP index.ts
Hooks Used (5 hooks)
Hook Purpose experimental.chat.system.transformInject DCP system prompt instructions experimental.chat.messages.transformMain hook — prune, deduplicate, inject nudges, sync compression blocks experimental.text.completeStrip hallucinations from completed text command.execute.beforeHandle /dcp subcommands (stats, sweep, manual, compress, decompress, recompress) eventTrack compression timing via message.part.updated events configRegister dcp command, add compress to primary_tools, sync permissions toolRegister compress as a custom tool the model can call
Dependencies
peerDependencies: @opencode-ai/plugin >=1.4.3
runtime deps: @anthropic-ai/tokenizer, @opencode-ai/sdk, jsonc-parser
devDeps: tsup, tsx, prettier, typescript
Build
Build: tsup + tsc --emitDeclarationOnly (more mature than caveman's Bun-only approach)
Pre-publish check: scripts/verify-package.mjs
3. OpenCode Plugin API — Complete Reference
Plugin Architecture
A plugin is a TypeScript/JS module that exports a default function returning a Hooks object. The function receives a context object.
Source: opencode.ai/docs/plugins/
Context Object
typescript Copy code
{ project, client, $, directory, worktree }
project — Current project info
client — OpenCode SDK client for AI interaction
$ — Bun shell API for executing commands
directory — CWD
worktree — Git worktree path
Available Hooks
Command Events: command.execute.before, command.executed
File Events: file.edited, file.watcher.updated
Message Events: message.part.removed, message.part.updated, message.removed, message.updated
Session Events: session.created, session.compacted, session.deleted, session.diff, session.error, session.idle, session.status, session.updated
Tool Events: tool.execute.before, tool.execute.after
Experimental Chat Hooks:
experimental.chat.system.transform — Modify system prompt array per LLM call. Input: { sessionID?, model }, Output: { system: string[] }
experimental.chat.messages.transform — Modify message array before LLM sees it. Input: {}, Output: { messages: { info: Message, parts: Part[] }[] }
experimental.text.complete — Transform completed text output
experimental.session.compacting — Customize compaction context
Other: event (generic event handler), config (modify opencode config), tool (register custom tools), shell.env (inject env vars), tui.* hooks
Custom Tools
typescript Copy code
import { type Plugin, tool } from "@opencode-ai/plugin"
export const MyPlugin: Plugin = async (ctx) => {
return {
tool: {
mytool: tool({
description: "Description",
args: { foo: tool.schema.string() },
async execute(args, context) {
return `Result: ${args.foo}`
},
}),
},
}
}
Plugin Loading
Global config → Project config
npm packages installed via Bun at startup, cached in ~/.cache/opencode/node_modules/
Local files: .opencode/plugins/ (project), ~/.config/opencode/plugins/ (global)
4. Other OpenCode Plugin Examples
Plugin Author What it does Stars/Downloads @tarquinen/opencode-dcptarquinen Dynamic context pruning 3.3k stars, 10.5k/wk caveman-opencode-plugindantesCode Caveman communication mode 71 stars @mumme-it/opencode-cavemanMumme-IT Alternative caveman — uses experimental.chat.messages.transform, experimental.session.compacting, custom caveman_set_level tool, skills 0 stars opencode-cavemandxvapor Minimal caveman — no config, just install 200/wk opencode-sessionsmalhashemi Session management UI — opencode-smart-titletarquinen Auto-generate session titles 159/wk opencode-vimtarquinen Vim-style editing 269/wk oc-tpstarquinen Tokens-per-second display 161/wk opencode-helicone-session— Observability/tracing — opencode-wakatimeangristan Time tracking — opencode-magi— Multi-agent PR review 17k/wk opencode-subagent-statuslinejoaquinvesapa Subagent status in statusline 28k/wk @braintrust/trace-opencodebraintrust LLM tracing to Braintrust 88k/wk
5. How to Create a Similar Plugin — Recipe
Minimal plugin file structure
code Copy code
my-plugin/
├── package.json
├── tsconfig.json
├── build.ts # Bun.build or tsup
├── src/
│ ├── index.ts # Default export: Plugin function
│ ├── config.ts # Optional config loader
│ ├── state.ts # Optional runtime state
│ ├── commands/ # Command handlers
│ ├── skills/ # Prompt generators / system instructions
│ └── __tests__/
└── README.md
package.json template
json Copy code
{
"name": "my-opencode-plugin",
"version": "0.1.0",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": ["dist"],
"scripts": {
"build": "bun run build.ts && tsc --emitDeclarationOnly",
"dev": "opencode plugin dev"
},
"peerDependencies": {
"@opencode-ai/plugin": ">=1.14.21"
},
"devDependencies": {
"@opencode-ai/plugin": "1.14.21",
"typescript": "^6.0.0"
},
"keywords": ["opencode", "plugin"],
"license": "MIT"
}
Core plugin pattern
typescript Copy code
import type { Plugin, Hooks } from '@opencode-ai/plugin'
const myPlugin: Plugin = async (ctx) => {
const hooks: Hooks = {
// 1. Register commands
config: async (opencodeConfig) => {
opencodeConfig.command ??= {}
opencodeConfig.command['mycommand'] = {
template: '',
description: 'My custom command'
}
},
// 2. Inject system instructions every turn
'experimental.chat.system.transform': async (input, output) => {
output.system.push('My custom instruction for every LLM call')
},
// 3. Intercept commands before model sees them
'command.execute.before': async (input, output) => {
if (input.command === 'mycommand') {
output.parts = [/* custom response parts */]
}
},
// 4. Register custom tools the model can call
tool: {
mytool: {
description: 'My custom tool',
args: { param: { type: 'string' } },
async execute(args, context) {
return `Tool result for ${args.param}`
}
}
}
}
return hooks
}
export default myPlugin
Key patterns from the ecosystem
Config registration — Use config hook to register commands, skills paths, tools
System prompt injection — Use experimental.chat.system.transform to inject per-turn system instructions (like caveman rules)
Message transformation — Use experimental.chat.messages.transform to modify/reduce message context (like DCP pruning)
Command interception — Use command.execute.before to handle commands without LLM round-trips. Mutate output.parts directly
Compaction survival — Use experimental.session.compacting to ensure plugin state persists through /compact
Per-session state — Use Map<sessionID, State> (caveman pattern) or file-based persistence (DCP pattern via ~/.config/opencode/)
Config discovery — Check project then global config, use sensible defaults (both plugins follow this)
Key differences between plugins
Aspect caveman-opencode-plugin @tarquinen/opencode-dcp Complexity Simple (3 hooks, ~200 lines) Complex (5+ hooks, thousands of lines) Dependencies 0 runtime deps 3 runtime deps Build Bun.build tsup Config caveman.json dcp config in opencode.json State In-memory Map File-persisted + session sync License MIT AGPL-3.0 Test framework bun test Node built-in test runner + tsx