opencode-worktree

作者 kdcokenny已验证

Zero-friction git worktrees for OpenCode. Auto-spawns terminals, syncs files, cleans up on exit.

714
Stars
38
Forks
TypeScript
语言
2026/8/23
添加时间

⚠️ 第三方软件声明

本 Skill 为第三方开源软件,独立托管于 GitHub。SkillTip 仅为信息目录,不控制或维护底层仓库。所显示的安全检查为自动化且范围有限,安装前请自行审查源码。

阅读服务条款

安装

添加到你的 Claude Code skills 目录:

# Add to your Claude Code skills
git clone https://github.com/kdcokenny/opencode-worktree

快速入门

使用 opencode-worktree 等 Skills 的指南。

安全报告

已验证

上次扫描:—

{
  "status": "PASSED",
  "issues": []
}

README.md

opencode-worktree

Git worktrees that spawn their own terminal. Zero-friction isolation for AI-driven development.

An OpenCode plugin that creates isolated git worktrees—where each worktree automatically opens its own terminal with OpenCode running inside. No manual setup, no context switching, no cleanup work.

Why This Exists

You already know you can create git worktrees manually. Or use OpenCode Desktop's UI. So why this plugin?

Manual worktrees require setup: create the worktree, open a terminal, navigate to it, start OpenCode. OpenCode Desktop gives you worktrees, but locks you into the GUI workflow. Each approach has friction.

This plugin eliminates that friction. When the AI calls worktree_create, your terminal spawns automatically, OpenCode is already running, and files are synchronized. When it calls worktree_delete, changes commit automatically and the worktree cleans itself up. It's the difference between having a tool and having a workflow.

Works great standalone, but pairs especially well with cmux for agentic workflows. cmux provides native workspace management and programmatic control that fits naturally into automated development workflows. tmux is also supported if you prefer a traditional multiplexer setup.

When to Use This

Approach Best For Tradeoffs

Manual git worktree One-off experiments, full control Manual setup, no auto-cleanup, context switching

OpenCode Desktop UI Visual workflow, integrated experience Tied to desktop app, less automation

This plugin AI-driven workflows, automation, CLI-first users Adds plugin dependency to your project

If you prefer manual control or work exclusively in OpenCode Desktop, you may not need this. But if you want AI agents to seamlessly create and manage isolated development sessions—complete with automatic terminal spawning and state cleanup—this is what you're looking for.

How It Works

flowchart LR
    A[Create Worktree] --> B{Terminal Spawns}
    B --> C[OpenCode Running]
    C --> D[Work in Isolation]
    D --> E[Delete Worktree]
    E --> F{Auto-commit & Cleanup}
    F --> G[Session Ends]
  • Create - AI calls worktree_create("feature/dark-mode")

  • Terminal spawns - New window opens with OpenCode at ~/.local/share/opencode/worktree/<project-id>/feature/dark-mode

  • Work - AI experiments in complete isolation

  • Delete - AI calls worktree_delete("reason")

  • Cleanup - Changes commit automatically, git worktree removed

Worktrees are stored in ~/.local/share/opencode/worktree/<project-id>/<branch>/ outside your repository.

Installation

ocx add kdco/worktree --from https://registry.kdco.dev

If you don't have OCX installed, install it from the OCX repository.

Optional: Install kdco-workspace for the full experience—it bundles worktrees with background agents, planning tools, and notifications:

ocx add kdco/workspace --from https://registry.kdco.dev

Usage

The plugin adds two tools:

Tool Purpose

worktree_create(branch, baseBranch?) Create a new git worktree for isolated development. A new terminal spawns with OpenCode ready.

worktree_delete(reason) Delete the current worktree. Changes commit automatically before removal.

Creating a Worktree

worktree_create:
  branch: "feature/dark-mode"
  baseBranch: "main"  # optional, defaults to HEAD

When called, this:

  • Creates git worktree at ~/.local/share/opencode/worktree/<project-id>/feature/dark-mode

  • Syncs files based on .opencode/worktree.jsonc config

  • Runs post-create hooks (e.g., pnpm install)

  • Opens a new terminal with OpenCode running

Deleting a Worktree

worktree_delete:
  reason: "Feature complete, merging to main"

When called, this:

  • Runs pre-delete hooks (e.g., docker compose down)

  • Commits all changes with snapshot message

  • Removes git worktree with --force

  • Cleans up session state

Platform Support

The plugin detects your terminal automatically:

Platform Terminals Supported

macOS Ghostty, iTerm2, Kitty, WezTerm, Alacritty, Warp, Terminal.app

Linux Kitty, WezTerm, Alacritty, Ghostty, Foot, GNOME Terminal, Konsole, XFCE4 Terminal, xterm

Windows Windows Terminal (wt.exe), cmd.exe fallback

cmux Uses native cmux workflow when CMUX_WORKSPACE_ID is present or socket control is explicitly enabled (CMUX_SOCKET_PATH + CMUX_SOCKET_MODE=allowAll); each worktree launch opens a new cmux workspace and falls back safely when unavailable

tmux Creates new tmux window (supported on all platforms)

WSL Windows Terminal via wt.exe interop

Detection Priority

  • tmux - Runtime priority on all platforms when already inside tmux. Creates new tmux windows instead of spawning separate terminal applications.

  • cmux - Recommended for new agentic workflows. Uses native cmux launch flow when available via CMUX_WORKSPACE_ID or explicit socket control (CMUX_SOCKET_PATH with CMUX_SOCKET_MODE=allowAll). Worktree launches always create a new cmux workspace (no current-workspace reuse), then fall back safely when cmux context is unavailable.

  • WSL - Uses Windows Terminal for Linux subsystem

  • Environment vars - Checks TERM_PROGRAM, KITTY_WINDOW_ID, GHOSTTY_RESOURCES_DIR, etc.

  • Fallback - System defaults (Terminal.app, xterm, cmd.exe)

Configuration

Auto-creates .opencode/worktree.jsonc on first use:

{
  "$schema": "https://registry.kdco.dev/schemas/worktree.json",

  "sync": {
    // Files to copy from main worktree
    "copyFiles": [],

    // Directories to symlink
    "symlinkDirs": [],

    // Patterns to exclude
    "exclude": []
  },

  "hooks": {
    // Run after creation
    "postCreate": [],

    // Run before deletion
    "preDelete": []
  }
}

Common Configurations

Node.js project:

{
  "sync": {
    "copyFiles": [".env", ".env.local"],
    "symlinkDirs": ["node_modules"]
  },
  "hooks": {
    "postCreate": ["pnpm install"]
  }
}

Docker-based project:

{
  "sync": {
    "copyFiles": [".env"]
  },
  "hooks": {
    "postCreate": ["docker compose up -d"],
    "preDelete": ["docker compose down"]
  }
}

FAQ

Why not just use git worktree manually?

Manual worktrees require manual setup: git worktree add, opening a terminal, navigating to it, starting OpenCode. Each step is friction. This plugin gives you a single command that handles everything end-to-end, complete with automatic file synchronization and lifecycle hooks.

Does this work with OpenCode Desktop?

Worktrees created with this plugin work fine in OpenCode Desktop, but you lose the automatic terminal spawning. The plugin's value is in CLI-first workflows and AI automation—if you prefer Desktop exclusively, you may not need this.

What happens if I forget to delete the worktree?

Changes remain in ~/.local/share/opencode/worktree/<project-id>/<branch>. The branch exists in git. You can manually check out or delete it later. The plugin doesn't force cleanup—it's just the convenient default path.

Can I have multiple worktrees simultaneously?

Yes. Each gets its own terminal and OpenCode session. They're fully independent.

Does this break my existing git workflow?

No. It uses standard git worktrees. git worktree list shows them. Branches merge normally.

Why spawn a new terminal instead of reusing the current one?

Isolation. You can close the worktree session without affecting your main workflow. If the AI breaks something, your original terminal remains untouched.

Limitations

Security

  • Branch names validated against git ref rules and shell metacharacters

  • File sync paths validated to prevent directory traversal

  • Hook commands run with user privileges in worktree directory

Terminal Spawning

  • Ghostty on macOS uses inline commands to avoid permission dialogs

  • Kitty tab support requires allow_remote_control config (falls back to window)

  • Some terminals don't support tabs; opens new OS window instead

Manual Installation

Copy src/ to .opencode/plugin/. You lose OCX's dependency management and automatic updates.

Requirements:

  • Manually install jsonc-parser

  • Manual updates via re-copying

Part of the OCX Ecosystem

From the KDCO Registry. Combine with:

Acknowledgments

Inspired by opencode-worktree-session by Felix Anhalt.

Contributing

This facade is maintained from the main OCX monorepo.

If you want to update opencode-worktree itself, start here:

https://github.com/kdcokenny/ocx/blob/main/workers/kdco-registry/files/plugins/worktree.ts

https://github.com/kdcokenny/ocx/tree/main/workers/kdco-registry/files/plugins/worktree

Open issues here: https://github.com/kdcokenny/ocx/issues/new

Open pull requests here: https://github.com/kdcokenny/ocx/compare

Please do not open issues or PRs in this facade repository.

Disclaimer

This project is not built by the OpenCode team and is not affiliated with OpenCode in any way.

License

MIT

常见问题

What is opencode-worktree?

opencode-worktree is an open-source ai agents skill for AI coding assistants such as Claude Code, Codex CLI, and ChatGPT, built by kdcokenny. Zero-friction git worktrees for OpenCode. Auto-spawns terminals, syncs files, cleans up on exit. It has 714 GitHub stars.

Is opencode-worktree safe to use?

Yes. opencode-worktree passed SkillsLLM's automated security scan — a dependency vulnerability audit plus prompt-injection heuristics — with no high-severity issues. You can read the full report in the Security Report section on this page.

How do I install opencode-worktree?

Clone the repository with "git clone https://github.com/kdcokenny/opencode-worktree" and add it to your Claude Code skills directory (see the Installation section above).

What programming language is opencode-worktree written in?

opencode-worktree is primarily written in TypeScript. It is open-source under kdcokenny on GitHub, so you can review or fork the full source.

Are there alternatives to opencode-worktree?

Yes. SkillsLLM lists many other AI Agents skills you can browse and compare side by side. Open the AI Agents category from the badge at the top of this page, or use the Related Skills and comparison links further down to weigh opencode-worktree against similar tools.

评论 (0)

暂无评论,成为第一个分享想法的人!

ECC

by affaan-m

10

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

242,21936,702JavaScript
AI 智能体ai-agentsanthropicclaude-code
查看详情
15

An agentic skills framework & software development methodology that works.

234,96620,863Shell
AI 智能体ai-agentsbrainstorming
查看详情

hermes-agent

by NousResearch

10

The agent that grows with you

234,43747,175Python
AI 智能体ai-agentsagent-orchestration
查看详情

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

185,94028,768JavaScript
AI 智能体ai-agentsanthropicclaude-code
查看详情

cc-switch

by farion1231

3

A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode, OpenClaw, Grok Build & Hermes Agent. Only official website: ccswitch.io

128,8688,826Rust
AI 智能体claude-codeai-tools
查看详情

claude-code

by anthropics

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

120,03119,897Shell
AI 智能体
查看详情

开发者还喜欢

基于喜欢此 Skill 的开发者投票和收藏

ECC

by affaan-m

10

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

242,21936,702JavaScript
AI 智能体ai-agentsanthropicclaude-code
查看详情
15

An agentic skills framework & software development methodology that works.

234,96620,863Shell
AI 智能体ai-agentsbrainstorming
查看详情

hermes-agent

by NousResearch

10

The agent that grows with you

234,43747,175Python
AI 智能体ai-agentsagent-orchestration
查看详情

n8n

by n8n-io

12

Fair-code workflow automation platform with native AI capabilities. Combine visual building with custom code, self-host or cloud, 400+ integrations.

201,88160,308TypeScript
MCP 服务器apisai-tools
查看详情

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

185,94028,768JavaScript
AI 智能体ai-agentsanthropicclaude-code
查看详情

cc-switch

by farion1231

3

A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode, OpenClaw, Grok Build & Hermes Agent. Only official website: ccswitch.io

128,8688,826Rust
AI 智能体claude-codeai-tools
查看详情