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-kratos

v0.1.1

Published

Persistent kratos-memory integration for OpenCode — context injection, per-prompt recall, auto-capture, session summaries

Readme

opencode-kratos

Persistent project memory for OpenCode, powered by kratos-memory. Every session automatically gets the project's memory injected as context, every prompt gets relevant memories recalled, every tool edit and command gets buffered, and every idle session gets summarized into long-term memory — with zero tokens spent on agent tools, because all memory logic lives in the kratos CLI, not in the model's context.

How OpenCode events map to kratos

| OpenCode event | Plugin action | Kratos call | |---|---|---| | session.hook("context") — every model call, cached per session | Inject memory block as a system part | kratos context [--budget N] once per sessionID, result cached | | session.hook("prompt") — prompt admission | Append recall block to prompt text | kratos capture --event user-prompt stdin {prompt}, stdout appended | | ctx.tool.hook("execute.after") — completed tool calls | Buffer edit/command events | kratos capture --event post-tool-use stdin translated payload | | session.hook("compaction") — before context compaction | Flush session buffer | kratos capture --event session-end | | session.idle (interactive) or session.execution.* completion (headless runs), debounced 15 min | Flush session buffer | kratos capture --event session-end | | Plugin cleanup (server shutdown) | Best-effort flush | kratos capture --event session-end |

Tool events are translated to the tool names kratos understands:

| OpenCode tool | Mapped to | Input mapping | |---|---|---| | edit, write | Edit / Write | path/filePath/file_path → file_path | | patch | MultiEdit | path → file_path | | shell, bash | Bash | command → command | | any other tool | passed through with its name | — |

Requirements

  • OpenCode V2 (the plugin API shipped with V2).
  • kratos — either the launcher at ~/.kratos/bin/kratos, any binary you point binary at, or nothing at all: the plugin falls back to running kratos through npx --yes kratos-memory automatically. A global kratos install is faster (no npx resolution on first use) and works offline.

Install

Add the plugin to your OpenCode config (~/.config/opencode/opencode.json):

{ "plugins": [{ "package": "opencode-kratos" }] }

That's it — all features are on by default.

Options

{
  "plugins": [{
    "package": "opencode-kratos",
    "options": {
      "binary": "",
      "context": true,
      "recall": true,
      "capture": true,
      "summary": true,
      "idleDebounceMinutes": 15,
      "contextBudget": 2000,
      "debug": false
    }
  }]
}

| Option | Default | Description | |---|---|---| | binary | "" | Explicit path to a kratos binary. When empty, the plugin probes ~/.kratos/bin/kratos, then falls back to npx --yes kratos-memory. | | context | true | Inject the project memory block into the session context (system part) on every model call. | | recall | true | Append kratos's recall output to each user prompt. | | capture | true | Buffer completed tool events (edits, commands) into kratos. | | summary | true | Write session summaries (the session-end flushes). | | idleDebounceMinutes | 15 | How long a session must stay idle before its summary is flushed. 0 flushes on the next tick after each idle event. | | contextBudget | (unset) | Token budget passed to kratos context --budget N to cap the memory block size. | | debug | false | Write every plugin decision to ~/.kratos/opencode-kratos/debug.log under a [kratos] prefix. |

How it works

  • Context injection — the first model call of a session runs kratos context in the project directory (10s timeout) and caches the result; every model call in that session pushes the same cached block as a <kratos-context> system part. The cache is capped at 100 sessions.
  • Per-prompt recall — each admitted prompt is piped to kratos capture --event user-prompt (5s timeout); when kratos prints a recall, it is appended to the prompt text inside a <kratos-recall> block. Kratos's own gating applies: short prompts, slash commands, and sub-threshold matches produce nothing.
  • Tool capture — completed tool calls are translated and piped to kratos capture --event post-tool-use, fire-and-forget so the agent loop never waits. Failed tool calls are skipped.
  • Session summaries — instead of hooking a "stop" moment that OpenCode does not have, the plugin subscribes to session.idle and execution-completion events (session.execution.succeeded/failed/interrupted, which headless opencode run sessions emit) and arms a per-session debounce (default 15 min). Each new trigger re-arms the timer, so the summary is written when the session has truly gone quiet, regardless of event cadence. Context compaction and plugin shutdown flush immediately. Before summarizing, a flush waits (up to 5 s) for the session's still-in-flight tool captures so kratos sees a complete event buffer. The session-end capture itself runs in a detached child process: the OpenCode server only grants ~1-2 s of shutdown grace, which an awaited capture would not survive. Flushes are serialized per project through a lock file (~/.kratos/opencode-kratos/locks/), so several OpenCode instances open on the same project never double-summarize; a lock older than 10 s is considered abandoned (a flush holds it for at most ~6 s) and taken over.

Every hook is wrapped in a never-throw guard: if kratos is missing, slow, or broken, sessions proceed normally — you just lose memory features until it comes back.

Troubleshooting

  • "kratos not found" / nothing captured — check that ~/.kratos/bin/kratos --help exits 0, or install globally (npm i -g kratos-memory). The npx fallback needs network on first use.
  • Nothing in memory after a session — the summary flush is debounced (default 15 min); it also fires on compaction and shutdown. Lower idleDebounceMinutes if you iterate quickly.
  • General diagnosis — set "debug": true in the plugin options and read ~/.kratos/opencode-kratos/debug.log; every plugin decision is prefixed with [kratos]. (OpenCode v2 swallows plugin console output, so the plugin writes its own debug file.)

Known limitations

  • No git post-commit capture (kratos captures Claude-style tool events only).
  • The memory buffer is shared per project: concurrent sessions in the same project buffer into the same kratos project memory.
  • Memories saved mid-session appear in recall on the next session — the context block is cached per session by design.

Development

npm install
npm test          # unit tests (node:test)
npm run typecheck # tsc --noEmit
npm run e2e       # end-to-end: boots `opencode run --standalone` twice

License

MIT

Credit

Memory backend: kratos-memory by ceorkm. This plugin is an independent OpenCode integration and is not affiliated with that project.

Source and issues: MisterAssm/opencode-kratos.