npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@vikrant82/opencode-context-truncate

v0.1.0

Published

Lightweight OpenCode plugin for prompt-only truncation of recent user-turn windows

Readme

opencode-context-truncate

An OpenCode plugin for hiding old conversation context from future model requests without deleting your visible OpenCode history.

Use it when a recent part of a session has gone down the wrong path and you want future prompts to behave as if that part of the conversation never happened — without starting a new session and without paying for an LLM summarization step.

What it does

opencode-context-truncate adds three slash commands:

/truncate_user_turns 5
/truncate_status
/truncate_clear

When you run /truncate_user_turns N, the plugin:

  1. Looks at the current session history.
  2. Counts backward by real user messages.
  3. Stores a fixed hidden range from the Nth most recent user message through the current latest message.
  4. Removes that range from future model prompts.

Your OpenCode UI and session history remain unchanged. Only future LLM requests are filtered.

When to use it

Good fits:

  • You tried an approach and want the model to forget it.
  • A long debugging branch is no longer relevant.
  • You pasted large context that should not be sent again.
  • You want a cheap alternative to summarization/compression.

Not a fit:

  • You want a summary of the hidden content.
  • You want to physically delete messages from OpenCode history.
  • You want token accounting or automatic pruning.

Installation

Local development install

Clone or keep this project somewhere on disk, then install and build it:

npm install
npm run build

Add the plugin path to your OpenCode config:

{
  "$schema": "https://opencode.ai/config.json",
  "plugin": ["/Users/chauv/vibe-tools/opencode-context-truncate"],
}

Then fully quit and restart OpenCode. OpenCode loads plugins at startup and does not hot-reload plugin config.

npm package install

If this package is published to npm, configure it by package name instead of a local path:

{
  "$schema": "https://opencode.ai/config.json",
  "plugin": ["@vikrant82/opencode-context-truncate"],
}

Restart OpenCode after changing the config.

Commands

/truncate_user_turns N

Hide the last N real user-turn windows from future model prompts.

Example:

/truncate_user_turns 3

Important details:

  • N counts user messages, not assistant replies, tool calls, or ignored plugin notifications.
  • The hidden range is fixed at command time.
  • New messages sent after the command remain visible to the model.
  • If fewer than N user messages exist, the plugin hides from the oldest real user message it can find and reports the actual count.
  • The command itself does not call the model.

/truncate_status

Show active hidden ranges for the current session.

/truncate_status

/truncate_clear

Clear active hidden ranges for the current session.

/truncate_clear

After clearing, future model prompts can see the full session context again.

Persistence

Hidden ranges are persisted and survive OpenCode restarts until you clear them.

State is stored as JSON under OpenCode's data directory:

$XDG_DATA_HOME/opencode/storage/plugin/context-truncate/state.json

If XDG_DATA_HOME is unset, the plugin uses:

~/.local/share/opencode/storage/plugin/context-truncate/state.json

Writes are atomic. If the state file is corrupt, the plugin renames it aside and starts with empty state.

Example workflow

  1. Work normally in an OpenCode session.

  2. Realize the last few user turns led the model in the wrong direction.

  3. Run:

    /truncate_user_turns 4
  4. Optionally check what is hidden:

    /truncate_status
  5. Continue with a new prompt. The model will not see the hidden historical range, but your OpenCode history remains visible.

  6. Undo the filtering if needed:

    /truncate_clear

Development

Useful commands:

npm install
npm run typecheck
npm run build
npm run format:check

Format files with:

npm run format

Current limitations

  • State is per OpenCode session ID.
  • There is no automatic cleanup for stale sessions yet.
  • There is no summarization or token accounting.
  • The plugin depends on OpenCode's experimental chat message transform hook.

Troubleshooting

The commands are not available

  • Confirm the plugin is listed in your OpenCode config.
  • Confirm the local path is correct, or that the npm package is installed and resolvable.
  • Restart OpenCode after changing config.

Hidden context still appears to be used

  • Run /truncate_status in the same session.
  • Make sure you cleared or truncated the intended session.
  • Remember that only future model prompts are filtered; existing visible history is intentionally unchanged.

I want to reset all persisted state manually

Delete the state file:

rm ~/.local/share/opencode/storage/plugin/context-truncate/state.json

If you use XDG_DATA_HOME, delete the file under that directory instead.