|
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 | | -## Configuration |
| 21 | +> **Note:** Project `plugin` arrays override global completely—include all desired plugins in project config if using both. |
| 22 | +
|
| 23 | +## How It Works |
33 | 24 |
|
34 | | -DCP uses its own configuration file, separate from OpenCode's `opencode.json`: |
| 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. |
35 | 26 |
|
36 | | -- **Global:** `~/.config/opencode/dcp.jsonc` |
37 | | -- **Project:** `.opencode/dcp.jsonc` |
| 27 | +## Configuration |
38 | 28 |
|
39 | | -The global config is automatically created on first run. Create a project config to override settings per-project. |
| 29 | +DCP uses its own config file (`~/.config/opencode/dcp.jsonc` or `.opencode/dcp.jsonc`), created automatically on first run. |
40 | 30 |
|
41 | | -### Available Options |
| 31 | +### Options |
42 | 32 |
|
43 | | -- **`enabled`** (boolean, default: `true`) - Enable/disable the plugin |
44 | | -- **`debug`** (boolean, default: `false`) - Enable detailed logging to `~/.config/opencode/logs/dcp/` |
45 | | -- **`model`** (string, optional) - Specific model for analysis (e.g., `"anthropic/claude-haiku-4-5"`). Uses session model or smart fallbacks when not specified. |
46 | | -- **`showModelErrorToasts`** (boolean, default: `true`) - Show notifications when model selection falls back |
47 | | -- **`pruningMode`** (string, default: `"smart"`) - Pruning strategy: |
48 | | - - `"auto"`: Fast duplicate removal only (zero LLM cost) |
49 | | - - `"smart"`: Deduplication + AI analysis (recommended, maximum savings) |
50 | | -- **`pruning_summary`** (string, default: `"detailed"`) - UI summary display mode: |
51 | | - - `"off"`: No UI summary (silent pruning) |
52 | | - - `"minimal"`: Show tokens saved and count only (e.g., "Saved ~2.5K tokens (6 tools pruned)") |
53 | | - - `"detailed"`: Show full breakdown by tool type and pruning method |
54 | | -- **`protectedTools`** (string[], default: `["task", "todowrite", "todoread"]`) - Tools that should never be pruned |
| 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` | |
55 | 43 |
|
56 | | -Example configuration: |
| 44 | +**Strategies:** `"deduplication"` (fast, zero LLM cost) and `"ai-analysis"` (maximum savings). Empty array disables that trigger. |
57 | 45 |
|
58 | 46 | ```jsonc |
59 | 47 | { |
60 | 48 | "enabled": true, |
61 | | - "debug": false, |
62 | | - "pruningMode": "smart", |
63 | | - "pruning_summary": "detailed", |
64 | | - "protectedTools": ["task", "todowrite", "todoread"] |
| 49 | + "strategies": { |
| 50 | + "onIdle": ["deduplication", "ai-analysis"], |
| 51 | + "onTool": ["deduplication"] |
| 52 | + }, |
| 53 | + "protectedTools": ["task", "todowrite", "todoread", "context_pruning"] |
65 | 54 | } |
66 | 55 | ``` |
67 | 56 |
|
68 | | -### Configuration Hierarchy |
69 | | - |
70 | | -Settings are merged in order: **Built-in defaults** → **Global config** → **Project config** |
71 | | - |
72 | | -After modifying configuration, restart OpenCode for changes to take effect. |
| 57 | +Settings merge: **Defaults** → **Global** → **Project**. Restart OpenCode after changes. |
73 | 58 |
|
74 | 59 | ### Version Pinning |
75 | 60 |
|
76 | | -If you want to ensure a specific version is always used or update your version, you can pin it in your config: |
77 | | - |
78 | 61 | ```json |
79 | | -{ |
80 | | - "plugin": [ |
81 | | - |
82 | | - ] |
83 | | -} |
| 62 | +{ "plugin": [ "@tarquinen/[email protected]"] } |
84 | 63 | ``` |
85 | 64 |
|
86 | 65 | ## License |
|
0 commit comments