@moritakaaz/opencode-apc

Opencode plugin for aggressive automatic context pruning - triggers compression at 15k tokens to save costs


Keywords
opencode, opencode-plugin, context-pruning, dcp, token-saving, auto-compress
License
ISC
Install
npm install @moritakaaz/opencode-apc@1.2.0

Documentation

@moritakaaz/opencode-apc

An opencode plugin that wraps @tarquinen/opencode-dcp with aggressive auto-compression defaults. Triggers context pruning at 7k tokens to maximize token savings.

Installation

opencode plugin @moritakaaz/opencode-apc@latest --global

What it does

This plugin automatically manages your conversation context by:

  • Compressing stale conversation content into high-fidelity summaries
  • Triggering compression early (7k tokens) to save costs
  • Deduplicating repeated tool calls
  • Pruning errored tool inputs after 2 turns
  • Nudging the model to compress every 3 turns with strong force

On first run, it creates dcp.jsonc config files (global and project-level) with aggressive defaults. Existing configs are never overwritten unless they were generated by APC (detected via _apcVersion field) and have an outdated version — in that case, they are automatically upgraded.

Configuration

The plugin writes .opencode/dcp.jsonc with these defaults:

Setting Value Purpose
maxContextLimit 7000 Triggers compression early
minContextLimit 3500 Floor for compression target
nudgeFrequency 3 Nudge every 3 turns
nudgeForce "strong" Assertive nudging
deduplication enabled Remove duplicate tool calls
purgeErrors turns: 2 Prune errored inputs after 2 turns

To customize, edit .opencode/dcp.jsonc in your project — the plugin won't overwrite it.

Git and .opencode/ directory

The plugin creates a .opencode/dcp.jsonc file in your project. This file is safe to commit — it only contains DCP configuration and helps keep settings consistent across machines or collaborators.

The plugin also generates a .opencode/.gitignore that excludes runtime files (node_modules/, package.json, etc.), so only dcp.jsonc ends up tracked by git.

TL;DR: You can git add .opencode/ without worry. Only the config file will be committed.

Requirements

  • opencode with plugin support (@opencode-ai/plugin >=1.4.3)
  • Node.js with ESM support

Development

npm install
npm run build    # tsc -> dist/
npm test         # node:test unit tests

Error Handling

The plugin is designed to be resilient:

  • If config files can't be written (permission denied, disk full), a warning is logged but the plugin continues
  • If an existing config is malformed or missing required fields, a warning is logged but it's never overwritten
  • If @tarquinen/opencode-dcp fails to load, the plugin returns empty hooks so opencode doesn't crash

CI

GitHub Actions runs build + tests on Node 20 and 22 for every push/PR to master.

License

ISC