OpenCode plugin that automatically syncs .opencode/memory/ from your main repository into git worktrees.
When you create a git worktree via OpenCode's /worktree command, the new worktree gets a fresh .opencode/memory/ directory with only empty frontmatter scaffolds. All your project memory (conventions, architecture notes, preferences) is lost.
This plugin runs on every session initialization. When it detects the current directory is a git worktree, it locates the main repository and copies the memory files over — but only if the destination memory is empty (so it never overwrites your changes).
Add to your opencode.json:
{
"plugin": ["opencode-worktree-memory-sync"]
}Restart OpenCode. That's it.
- On session init, reads the
.gitfile to detect if the directory is a worktree - Parses the
gitdir:path to resolve the main repository root - Checks if
.opencode/memory/in the worktree only contains empty scaffolds - If empty, copies all memory files from the main repo's
.opencode/memory/
Non-worktree directories are silently ignored. Worktrees with existing memory content are skipped.
MIT