@ohzw/worktree-command-tui
v0.1.6
Published
A TUI for managing git worktrees
Readme
worktree-command-tui
worktree-command-tui is a terminal UI for managing Git worktrees from inside a repository.
It keeps one active runtime session per namespace, lets you switch worktrees with the keyboard, and keeps logs/process cleanup tied to the repo's shared Git state.
Features
- Discover worktrees from the current repository even when launched from a subdirectory
- Start, switch, or restart the active worktree session with
Enter - Stop the active session and clean up recorded orphan processes with
s - Run an optional per-worktree setup command with
i - Open the selected worktree in your editor with
e - Open the selected branch's pull request in a browser with
o - Delete a non-root worktree from the TUI with
d, then confirm - Inspect branch, upstream, working tree, and pull request metadata in the detail pane
- Tail ANSI-colored logs inline or in a full-screen log view
- Generate and load JSONC config with comments and trailing commas
Requirements
- Node.js
>=20 - Git
- A Git repository (additional linked worktrees optional)
- Optional: GitHub CLI (
gh) and a GitHub origin remote for pull request metadata ando/ Open PR
Installation
npm install -g @ohzw/worktree-command-tuiInstalled binaries:
wctuiworktree-command-tui(compatibility alias)
Quick start
1) Initialize config
Run this from the repo root or any subdirectory inside the repo:
wctui initThis writes .worktree-command-tui.jsonc at the repository root.
To overwrite an existing config:
wctui init --force2) Start the TUI
wctuiIf config is missing, the CLI exits with a message telling you to run wctui init.
Keyboard shortcuts
Primary shortcuts in the footer:
↑↓/jk— move selectionEnter— start, switch to, or restart the selected worktreei— runsetupCommandwhen configurede— open the selected worktree in the configured editor wheneditorCommandis configuredo— open the selected worktree's pull request when GitHub metadata is availabled— arm worktree deletionL— open full-screen logss— stop active sessionr— refresh worktree metadata?— show helpq— quit
Additional shortcuts from the help window:
g/G— jump to first / last worktree[/]— scroll logsPageUp/PageDn— page the selection list- Mouse wheel — scroll the pane under the cursor
d/y— confirm delete after arming itEsc/n/q— cancel delete confirmation
Security and network behavior
wctui executes the argv commands stored in .worktree-command-tui.jsonc when you press the matching keys. Treat repository config as trusted code:
Enterstartscommandin the selected worktree; pressing it on the active worktree restarts that session.irunssetupCommand; package-manager install commands may run dependency lifecycle scripts.erunseditorCommandwith the selected worktree path appended.
Review config before using those actions in an untrusted repository or worktree.
The TUI also reads pull request metadata with the GitHub CLI when remote.origin.url points at github.com. This uses gh api, your existing gh authentication, and a short timeout. Non-GitHub remote hosts are ignored by default.
Configuration
The tool looks for config in this order:
.worktree-command-tui.jsonc.worktree-command-tui.json
Example config:
{
// Session namespace used for git-common-dir state files and logs.
"namespace": "worktree-command-tui",
// Command launched in the selected worktree.
"command": ["npm", "run", "dev"],
// Optional command run manually with the setup key in the selected worktree.
"setupCommand": ["npm", "install"],
// Optional command that opens the selected worktree path in an editor.
// The selected worktree path is appended as the final argv entry.
"editorCommand": ["code"],
// TCP ports owned by the command, used when stopping stale/orphaned processes.
"ports": [3000],
// Files that must exist in a worktree before the command can be started there.
"requiredFiles": ["package.json"],
// Extra process command-line substrings treated as orphans for cleanup.
"orphanMatchers": []
}Notes:
setupCommandis optional and never runs automatically;ionly appears when it is configured. It accepts one argv array or an array of argv arrays executed in order. The built-in["copy-root-file", "source", "destination"]copies from the repo root into the selected worktree.editorCommandis optional; when set, the selected worktree path is appended to the argv andebecomes available- Use
portsfor every backend/frontend/dev-server port the command may bind; legacy singleportconfigs still load - The generated default config auto-detects package manager hints from
packageManageror common lockfiles and chooses a default script such asdev,start, orserve - Session records and logs are stored under the repository's Git common dir, so they are shared across worktrees in the same repo
Development
npm install
npm test
npm run typecheck
npm run buildLicense
MIT
