Skip to content
    ↑↓ select↵ openesc close
    English中文
    moritakaaz

    Apc

    v1.2.2Other
    @moritakaaz/opencode-apc

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

    GitHub stars

    0

    Monthly installs

    47

    13 in 7 days

    Composite scoreSCORE

    26.6

    Multi-signal model

    Last commit

    2 months ago

    2026-06-07

    Install and configure

    opencode.json

    Writes to this project's opencode.json — applies to this repository only.

    opencode.json

    {
      "$schema": "https://opencode.ai/config.json",
      "plugin": ["@moritakaaz/opencode-apc@1.2.2"]
    }

    opencode loads npm dependencies through its embedded runtime on startup and caches them locally — no manual global install needed.

    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 and remove the _apcVersion field — the plugin won't overwrite configs without this field.

    Important: Config changes require an opencode restart. DCP reads config at session start — edits to dcp.jsonc won't take effect until you close and reopen opencode.

    When to customize

    Workflow Recommendation
    Quick tasks, simple Q&A, small fixes Use defaults (7k/3500) — maximum token savings
    Multi-file refactoring, iterative debugging Raise to 10k/5000 — more working memory
    Complex code analysis, large codebases Raise to 10k/5000 + moderate nudge — retain cross-references longer
    Very long sessions with deep context Raise to 12k/6000 — but costs more tokens

    Custom config example

    For further optimization with more balanced context retention:

    // .opencode/dcp.jsonc — custom config (no _apcVersion = plugin won't overwrite)
    {
      "$schema": "https://raw.githubusercontent.com/Opencode-DCP/opencode-dynamic-context-pruning/master/dcp.schema.json",
      "compress": {
        "mode": "range",
        "permission": "allow",
        "maxContextLimit": 10000,
        "minContextLimit": 5000,
        "nudgeFrequency": 4,
        "nudgeForce": "moderate"
      },
      "manualMode": {
        "enabled": false,
        "automaticStrategies": true
      },
      "strategies": {
        "deduplication": {
          "enabled": true
        },
        "purgeErrors": {
          "enabled": true,
          "turns": 3
        }
      }
    }
    

    Differences from defaults:

    Setting Default Custom Why
    maxContextLimit 7000 10000 More working memory for cross-referencing multiple files
    minContextLimit 3500 5000 Higher floor retains more detail after compression
    nudgeFrequency 3 4 Less frequent nudging — more room for iterative work
    nudgeForce "strong" "moderate" AI uses its own judgment on when to compress
    purgeErrors.turns 2 3 Error messages stay longer — useful for debugging

    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 (schema-only configs created by DCP are silently accepted)
    • 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