Rewind
Claude Code style /rewind for opencode — git-free, prompt-based snapshots. Each user prompt is snapshotted to .opencode/rewind/snapshots and can be restored via /rewind.
0
440
近 7 天 6
34.3
生态多维模型
1 个月前
2026-08-25
快速安装与配置
opencode.json写入当前项目的 opencode.json,只对这个仓库生效。
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@nameused/opencode-rewind@1.0.2"]
}写入 ~/.config/opencode/opencode.json,对所有项目生效。
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@nameused/opencode-rewind@1.0.2"]
}若你要在本地改造这个插件,先装到项目里再从本地路径引用。
shell
pnpm add -D @nameused/opencode-rewindOpenCode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。
Claude Code style /rewind for opencode — git-free, prompt-based snapshots.
Each user prompt (non-/ command) is snapshotted to .opencode/rewind/snapshots/<id>/ and recorded in .opencode/rewind/history.json. List via /rewind, pick a prompt with arrow keys, choose 1 of 6 actions to restore.
How it relates to your project
- Project root = where your
opencode.jsonlives and where you runopencode. The plugin readsdirectoryfrom opencode and stores snapshots under<project>/.opencode/rewind/. - Two parts are required:
- Plugin (
src/index.ts/plugin/rewind.ts) — hookschat.messageandtool.execute.after, provides toolsrewind/list_checkpoints/restore_checkpoint. Loaded viaopencode.json: plugin. - Command (
command/rewind.md) — defines the slash command/rewind(usesquestion+ the tools above). Loaded from.opencode/commands/rewind.md(project) or~/.config/opencode/commands/rewind.md(global). Without it, tools exist but/rewindwon't appear in TUI.
- Plugin (
Installation
Option A — npm (recommended) — 2 locations
A1. Project node_modules (simplest)
Run in project root (where opencode.json lives):
npm i @nameused/opencode-rewind
# or bun add / pnpm add / yarn add
# installs to <project>/node_modules/@nameused/opencode-rewind
A2. .opencode isolated (keeps project package.json clean)
Keep package.json clean by installing into <project>/.opencode itself (opencode supports <project>/.opencode/package.json per opencode.ai/docs/plugins: Dependencies):
mkdir -p .opencode
cat > .opencode/package.json <<'JSON'
{
"dependencies": {
"@nameused/opencode-rewind": "^1.0.2"
}
}
JSON
# install into <project>/.opencode/node_modules
(cd .opencode && npm install)
# or: (cd .opencode && bun install)
Both A1 and A2 work; A2 puts the package at <project>/.opencode/node_modules/@nameused/opencode-rewind at the same level as your project root's .opencode dir (sibling to project files, inside .opencode).
In project root opencode.json (create if not exists, opencode.jsonc also works):
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@nameused/opencode-rewind"]
}
@nameused/opencode-rewind is published with command/ and plugin/ included (see package.json: files). But opencode does not auto-install the command file — you must copy it once:
mkdir -p .opencode/commands
# A1 source: <project>/node_modules/...
cp node_modules/@nameused/opencode-rewind/command/rewind.md .opencode/commands/rewind.md
# A2 source: <project>/.opencode/node_modules/...
# cp .opencode/node_modules/@nameused/opencode-rewind/command/rewind.md .opencode/commands/rewind.md
# if you skipped npm i and let opencode auto-install via opencode.json, source is instead:
# cp ~/.cache/opencode/node_modules/@nameused/opencode-rewind/command/rewind.md .opencode/commands/rewind.md
Global alternative:
mkdir -p ~/.config/opencode/commands && cp <source>/command/rewind.md ~/.config/opencode/commands/rewind.mdand putpluginin~/.config/opencode/opencode.json.
Restart opencode. Type / — you should see /rewind and /checkpoint.
Where packages live: A1
npm i→<project>/node_modules/@nameused/opencode-rewind; A2(cd .opencode && npm i)→<project>/.opencode/node_modules/@nameused/opencode-rewind(same level as project.opencodedir, isolated); auto-install viaopencode.json→~/.cache/opencode/node_modules/@nameused/opencode-rewind(opencode runsbun installat startup). If you see nothing, clear~/.cache/opencodeand restart, or check TUI logs (client.app.logwithservice:"rewind").
Option B — local (no npm)
mkdir -p .opencode/plugins .opencode/commands
cp src/index.ts .opencode/plugins/rewind.ts
# or cp plugin/rewind.ts .opencode/plugins/rewind.ts (both are synced)
cp command/rewind.md .opencode/commands/rewind.md
No opencode.json change needed. Restart opencode.
src/index.ts is the source of truth (plugin/rewind.ts synced each release).
Verify
/rewindappears when typing/in TUI- Send a normal prompt (not
/...), then/rewindshould list it - Tools available to agent:
list_checkpoints,restore_checkpoint,rewind
Troubleshooting — /rewind not visible
- Did you copy
command/rewind.mdto.opencode/commands/rewind.md(plural, notcommand/)? Old docs usedcommand/singular — nowcommands/. - Did you restart opencode after editing
opencode.json/ adding files? - Is
opencode.jsonin project root (or~/.config/opencode/opencode.jsonfor global)?opencode.jsoncalso works. - Check
~/.cache/opencode/node_modules/@nameused/opencode-rewindexists after restart. If not, runbun pm cache rmorrm -rf ~/.cache/opencodeand restart. - Check opencode version supports plugins (
>=0.10).
Usage
| Command | Description |
|---|---|
/rewind |
Interactive list (last 10, newest on top, system prompts filtered) → arrow keys → 6 actions |
/rewind <index> --action=1 |
Direct restore: 1=code+conv, 2=conv, 3=code, 4=summarize-from, 5=summarize-upto, 6=never (--confirm alias for 1) |
/checkpoint [label] |
Manual snapshot with label (manual-<ISO> if empty) |
list_checkpoints (tool) |
Same filtered/sorted list for agents |
restore_checkpoint {steps, action} |
Programmatic restore |
Agent natural language:
List checkpoints
Restore to checkpoint 2
Sorting/filtering: rewind/list_checkpoints filter isIgnorablePrompt and sort by timestamp desc before slicing.
Storage
- Snapshots:
.opencode/rewind/snapshots/<id>/ - History:
.opencode/rewind/history.json(atomic write, reindexed after prune, filtered on load if snapshot missing)
Restore: deletes current files not in snapshot (including .opencode tracked files), then copies snapshot files; empty dirs pruned; lastPrompt reset to restored entry.
Large projects
Current snapshotWorkingTree: src/index.ts:146 is a full copy (exact restore, including newly created/deleted files), not Claude Code's “only edited files” model. For small/medium repos this is correct and simple. For large repos (>10k files) each checkpoint is O(N) and 100 checkpoints use more disk. Mitigations:
- Ignores
.git/node_modules/.opencode/.cache/dist/build/.next/coverage/tmp/logs/.turbo/out/.parcel-cache/.vite/.idea/.vscode, skips>50MBand symlinks (fixed in1.0.1to uselstat), precisely excludes.opencode/rewind. - Use
/checkpointmanually before riskybashedits (bash is only heuristically tracked:rm/mv/cp/mkdir/touch/echo/sed/perl/python/>/cat >). - Future: incremental mode (only restore edited files, aligned with Claude Code limitations) can be enabled to trade exactness for speed — tracked as enhancement.
Limitations (same as Claude Code)
bashfile changes, subagents, symlinks not fully tracked — use/checkpointbefore risky bash- Large files
>50MBskipped - Symlinks skipped (
1.0.1fixeslistFilesRecursiveto uselstat)
Development
node --check src/index.ts
# edit src/index.ts, it will be synced to plugin/rewind.ts before publish
Publish
npm login
npm publish --access public
License
MIT
同类生态推荐
Agency Skills
@jehudarajasa/agency-skills
Skills for issue-driven software development, from issue to change request.
Magic Compact
magic-compact
Lossless context compression plugin for OpenCode.
Ocm
@wntic/ocm
Plugin marketplace for opencode: install skills, agents, commands, JS plugins and MCP servers from any git repo — once, globally, kept up to date