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

opencode-context-watch

v0.1.3

Published

OpenCode plugin to warn when a session's context window usage crosses a configurable threshold

Readme

opencode-context-watch

Warn when a session's context window usage crosses a configurable threshold. An opencode plugin that injects a warning into the conversation so the agent can wrap up the current step or prepare for compaction before the window is full.

Install

Install locally for the current OpenCode project:

opencode plugin opencode-context-watch

Install globally:

opencode plugin -g opencode-context-watch

OpenCode detects both package entrypoints and writes the plugin into the server and TUI config targets.

Configuration

Config file (optional): ~/.config/opencode/opencode-context-watch.json

{
  "warnPercent": 0.75,
  "warnTokens": 150000,
  "rearmPercent": 2,
  "postCompactContinue": true,
  "postCompactMsg": "[context-watch] Session context was compacted. Continue your work from where you left off, keeping replies concise.",
  "message": "[context-watch] Context window usage is at {percent}% ({tokens}/{window} tokens). The session is getting full: wrap up the current step soon, keep replies concise, avoid re-reading large files, and be ready to prepare for compaction if you continue."
}

Options

| Option | Default | Description | |--------|---------|-------------| | warnPercent | 0.77 | 0..1, or percent (e.g. 77) if > 1. Warn when usage reaches this fraction of the model window | | warnTokens | 150000 | Warn when session reaches this many tokens | | rearmPercent | 5 | Re-warn after this many percentage-point rise | | rearmTokens | 5000 | Re-warn after this many more tokens | | toast | true | Show a TUI toast when a band is crossed | | verbose | false | Log context estimates to the opencode log | | message | — | Template; placeholders {percent} {tokens} {window} | | postCompactContinue | false | Send a message after compaction | | postCompactMsg | [context-watch] Session context was compacted. Continue your work from where you left off, keeping replies concise. | Text of the post-compaction message |

Env overrides

CONTEXT_WATCH_PERCENT, CONTEXT_WATCH_TOKENS, CONTEXT_WATCH_WINDOW, CONTEXT_WATCH_REARM, CONTEXT_WATCH_REARM_TOKENS, CONTEXT_WATCH_MESSAGE, CONTEXT_WATCH_NO_TOAST, CONTEXT_WATCH_POST_COMPACT_CONTINUE, CONTEXT_WATCH_POST_COMPACT_MSG

Notes

  • The warning fires when either threshold is crossed (whichever comes first). Both thresholds can be active at once.
  • The percent threshold requires the model window to be known (cached by system.transform in the live TUI; pass CONTEXT_WATCH_WINDOW when using opencode run). When the window is unknown, only the tokens threshold applies; {percent}/{window} render 0/unknown.

Configuration errors

If the config file or an env override is invalid — bad JSON, wrong types, out-of-range values, or unknown keys — the plugin falls back to the default for each bad value and shows a TUI error toast listing exactly what is wrong. The full list is also written to the opencode log. The plugin keeps running with the defaults for the broken keys.

How it works

  • experimental.chat.messages.transform reads the real context size from the most recent completed assistant message's provider-reported token counts (the same number opencode's TUI context meter shows), then — when the threshold is crossed — pushes a synthetic user message into output.messages so the warning is visible to the model as part of the conversation.
  • experimental.chat.system.transform caches the model's context window from model.limit.context because the messages transform does not receive model info.
  • The plugin registers a compact_context tool the agent can call to compact its own session when the window is full. When postCompactContinue is enabled, a successful compaction posts postCompactMsg as a real user message (suppressing opencode's synthetic continue) so the session resumes on the configured instruction. When it is off, no message is sent after compaction.

Development

./dev.sh format lint typecheck
./dev.sh all

License

MIT