跳到主要内容
    ↑↓ 选择↵ 打开esc 关闭
    中文English
    Ghilteras

    Reasoning Pruner

    v1.0.0记忆与上下文
    @ghilteras/opencode-reasoning-pruner

    Prunes historical reasoning parts from the message history sent to the LLM (keeping the last turn's), saving context window and tokens on reasoning models. Model-agnostic; uses the idiomatic experimental.chat.messages.transform hook.

    GitHub 星标

    1

    月装机量

    243

    近 7 天 24

    综合评分SCORE

    36.8

    生态多维模型

    最近提交

    12 天前

    2026-08-07

    快速安装与配置

    opencode.json

    写入当前项目的 opencode.json,只对这个仓库生效。

    opencode.json

    {
      "$schema": "https://opencode.ai/config.json",
      "plugin": ["@ghilteras/opencode-reasoning-pruner@1.0.0"]
    }

    opencode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。

    Prunes historical reasoning parts from the message history before it is re-sent to the LLM, keeping only the last turn's reasoning. Saves context window and tokens on reasoning models (DeepSeek, GLM, Kimi, Qwen, ...) without touching what the model sees in the current turn.

    • Model-agnostic: strips any part.type === "reasoning", regardless of provider key naming (reasoning_content vs reasoning / reasoning_details).
    • Zero regex, zero event-stream manipulation, zero system-prompt injection.
    • Reasoning is still visible in the TUI (/thinking) and still consumed during generation — only the historical copies are pruned.

    Install

    npm i @ghilteras/opencode-reasoning-pruner
    # or: bun add @ghilteras/opencode-reasoning-pruner
    

    Then add it to the plugin array of opencode.json:

    {
      "plugin": ["@ghilteras/opencode-reasoning-pruner"]
    }
    

    How it works

    Hooks experimental.chat.messages.transform: finds the index of the last KEEP_TURNS user message(s) and removes every reasoning part before that index. Default KEEP_TURNS = 1 (keeps the reasoning of the current turn, prunes everything older).

    Config

    Edit the KEEP_TURNS constant in plugin.js (default 1).

    Notes

    • opencode's built-in compaction.prune only trims tool-output bytes — it does NOT touch reasoning parts. This plugin complements it.
    • Adjacent plugins exist for tool-output pruning (DCP/ACP) and for the opposite direction (preserving reasoning to fix provider 400s); none strip reasoning parts from history.

    License

    MIT © 2026 Angelo Pantano