|
4 | 4 |
|
5 | 5 | Automatically reduces token usage in OpenCode by removing obsolete tool outputs from conversation history. |
6 | 6 |
|
7 | | -## What It Does |
8 | | - |
9 | | -This plugin automatically optimizes token usage by identifying and removing redundant or obsolete tool outputs from your conversation history. |
10 | | - |
11 | 7 |  |
12 | 8 |
|
13 | 9 | ## Installation |
14 | 10 |
|
15 | | -Add to your OpenCode configuration: |
16 | | - |
17 | | -**Global:** `~/.config/opencode/opencode.json` |
18 | | -**Project:** `.opencode/opencode.json` |
| 11 | +Add to your OpenCode config (`~/.config/opencode/opencode.json` or `.opencode/opencode.json`): |
19 | 12 |
|
20 | 13 | ```json |
21 | 14 | { |
22 | | - "plugin": [ |
23 | | - "@tarquinen/opencode-dcp" |
24 | | - ] |
| 15 | + "plugin": ["@tarquinen/opencode-dcp"] |
25 | 16 | } |
26 | 17 | ``` |
27 | 18 |
|
28 | | -> **Note:** OpenCode's `plugin` arrays are not merged between global and project configs—project config completely overrides global. If you have plugins in your global config and add a project config, include all desired plugins in the project config. |
29 | | -
|
30 | 19 | Restart OpenCode. The plugin will automatically start optimizing your sessions. |
31 | 20 |
|
32 | | -## How It Works |
| 21 | +> **Note:** Project `plugin` arrays override global completely—include all desired plugins in project config if using both. |
33 | 22 |
|
34 | | -DCP is **non-destructive**—your session data is never modified. Pruning state is kept in memory only and resets when OpenCode restarts. When requests are sent to your LLM provider, DCP intercepts them and replaces pruned tool outputs with a placeholder; original content remains intact in your session. |
| 23 | +## How It Works |
35 | 24 |
|
36 | | -**Trade-off:** LLM providers cache prompts for faster/cheaper responses. Since DCP modifies message content, it may reduce cache hit rates. Token savings typically outweigh this, but be aware if your workflow relies heavily on prompt caching. |
| 25 | +DCP is **non-destructive**—pruning state is kept in memory only. When requests go to your LLM, DCP replaces pruned outputs with a placeholder; original session data stays intact. |
37 | 26 |
|
38 | 27 | ## Configuration |
39 | 28 |
|
40 | | -DCP uses its own configuration file, separate from OpenCode's `opencode.json`: |
41 | | - |
42 | | -- **Global:** `~/.config/opencode/dcp.jsonc` |
43 | | -- **Project:** `.opencode/dcp.jsonc` |
| 29 | +DCP uses its own config file (`~/.config/opencode/dcp.jsonc` or `.opencode/dcp.jsonc`), created automatically on first run. |
44 | 30 |
|
45 | | -The global config is automatically created on first run. Create a project config to override settings per-project. |
| 31 | +### Options |
46 | 32 |
|
47 | | -### Available Options |
| 33 | +| Option | Default | Description | |
| 34 | +|--------|---------|-------------| |
| 35 | +| `enabled` | `true` | Enable/disable the plugin | |
| 36 | +| `debug` | `false` | Log to `~/.config/opencode/logs/dcp/` | |
| 37 | +| `model` | (session) | Model for analysis (e.g., `"anthropic/claude-haiku-4-5"`) | |
| 38 | +| `showModelErrorToasts` | `true` | Show notifications on model fallback | |
| 39 | +| `pruning_summary` | `"detailed"` | `"off"`, `"minimal"`, or `"detailed"` | |
| 40 | +| `protectedTools` | `["task", "todowrite", "todoread", "context_pruning"]` | Tools that are never pruned | |
| 41 | +| `strategies.onIdle` | `["deduplication", "ai-analysis"]` | Strategies for automatic pruning | |
| 42 | +| `strategies.onTool` | `["deduplication"]` | Strategies when AI calls `context_pruning` | |
48 | 43 |
|
49 | | -- **`enabled`** (boolean, default: `true`) - Enable/disable the plugin |
50 | | -- **`debug`** (boolean, default: `false`) - Enable detailed logging to `~/.config/opencode/logs/dcp/` |
51 | | -- **`model`** (string, optional) - Specific model for analysis (e.g., `"anthropic/claude-haiku-4-5"`). Uses session model or smart fallbacks when not specified. |
52 | | -- **`showModelErrorToasts`** (boolean, default: `true`) - Show notifications when model selection falls back |
53 | | -- **`pruningMode`** (string, default: `"smart"`) - Pruning strategy: |
54 | | - - `"auto"`: Fast duplicate removal only (zero LLM cost) |
55 | | - - `"smart"`: Deduplication + AI analysis (recommended, maximum savings) |
56 | | -- **`pruning_summary`** (string, default: `"detailed"`) - UI summary display mode: |
57 | | - - `"off"`: No UI summary (silent pruning) |
58 | | - - `"minimal"`: Show tokens saved and count only (e.g., "Saved ~2.5K tokens (6 tools pruned)") |
59 | | - - `"detailed"`: Show full breakdown by tool type and pruning method |
60 | | -- **`protectedTools`** (string[], default: `["task", "todowrite", "todoread"]`) - Tools that should never be pruned |
61 | | - |
62 | | -Example configuration: |
| 44 | +**Strategies:** `"deduplication"` (fast, zero LLM cost) and `"ai-analysis"` (maximum savings). Empty array disables that trigger. |
63 | 45 |
|
64 | 46 | ```jsonc |
65 | 47 | { |
66 | 48 | "enabled": true, |
67 | | - "debug": false, |
68 | | - "pruningMode": "smart", |
69 | | - "pruning_summary": "detailed", |
70 | | - "protectedTools": ["task", "todowrite", "todoread"] |
| 49 | + "strategies": { |
| 50 | + "onIdle": ["deduplication", "ai-analysis"], |
| 51 | + "onTool": ["deduplication"] |
| 52 | + }, |
| 53 | + "protectedTools": ["task", "todowrite", "todoread", "context_pruning"] |
71 | 54 | } |
72 | 55 | ``` |
73 | 56 |
|
74 | | -### Configuration Hierarchy |
75 | | - |
76 | | -Settings are merged in order: **Built-in defaults** → **Global config** → **Project config** |
77 | | - |
78 | | -After modifying configuration, restart OpenCode for changes to take effect. |
| 57 | +Settings merge: **Defaults** → **Global** → **Project**. Restart OpenCode after changes. |
79 | 58 |
|
80 | 59 | ### Version Pinning |
81 | 60 |
|
82 | | -If you want to ensure a specific version is always used or update your version, you can pin it in your config: |
83 | | - |
84 | 61 | ```json |
85 | | -{ |
86 | | - "plugin": [ |
87 | | - |
88 | | - ] |
89 | | -} |
| 62 | +{ "plugin": [ "@tarquinen/[email protected]"] } |
90 | 63 | ``` |
91 | 64 |
|
92 | 65 | ## License |
|
0 commit comments