worktree-manager

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
<objective> Manage parallel development across ALL projects using git worktrees with Claude Code agents. Each worktree is an isolated copy of the repo on a different branch, stored centrally at `~/tmp/worktrees/`. This enables multiple agents to work simultaneously without conflicts. </objective>
<quick_start> Create a single worktree with agent:
/worktree create feature/auth
Claude will:
  1. Allocate ports (8100-8101)
  2. Create worktree at
    ~/tmp/worktrees/[project]/feature-auth
  3. Install dependencies
  4. Create WORKTREE_TASK.md for the agent
  5. Launch terminal with Claude Opus 4.5 agent </quick_start>
<success_criteria> A worktree setup is successful when:
  • Worktree created at
    ~/tmp/worktrees/[project]/[branch-slug]
  • Ports allocated and registered globally
  • Dependencies installed
  • Agent launched in terminal (Ghostty/iTerm2/tmux)
  • Entry added to
    ~/.claude/worktree-registry.json
    </success_criteria>
<current_state> Git repository: !
git status --short --branch 2>/dev/null
Existing worktrees: !
git worktree list 2>/dev/null
Worktree registry: !
cat ~/.claude/worktree-registry.json 2>/dev/null | jq -r '.worktrees[] | "\(.project)/\(.branch) → \(.status)"' | head -10
Available ports: !
cat ~/.claude/worktree-registry.json 2>/dev/null | jq '.portPool.allocated | length' || echo "0"
allocated </current_state>
<activation_triggers>
<objective> 借助git worktrees和Claude Code agents管理所有项目的并行开发。每个工作树是仓库在不同分支上的独立副本,集中存储在`~/tmp/worktrees/`目录下。这允许多个agents同时工作而不会产生冲突。 </objective>
<quick_start> 创建带agent的单个工作树:
/worktree create feature/auth
Claude将:
  1. 分配端口(8100-8101)
  2. ~/tmp/worktrees/[project]/feature-auth
    路径下创建工作树
  3. 安装依赖
  4. 为agent创建WORKTREE_TASK.md文件
  5. 启动运行Claude Opus 4.5 agent的终端 </quick_start>
<success_criteria> 工作树设置成功的标志:
  • 工作树已创建在
    ~/tmp/worktrees/[project]/[branch-slug]
    路径下
  • 端口已分配并全局注册
  • 依赖已安装
  • agent已在终端(Ghostty/iTerm2/tmux)中启动
  • 条目已添加到
    ~/.claude/worktree-registry.json
    </success_criteria>
<current_state> Git仓库状态: !
git status --short --branch 2>/dev/null
现有工作树: !
git worktree list 2>/dev/null
工作树注册表: !
cat ~/.claude/worktree-registry.json 2>/dev/null | jq -r '.worktrees[] | "\(.project)/\(.branch) → \(.status)"' | head -10
可用端口: !
cat ~/.claude/worktree-registry.json 2>/dev/null | jq '.portPool.allocated | length' || echo "0"
已分配 </current_state>
<activation_triggers>

When This Skill Activates

该Skill的激活场景

Trigger phrases:
  • "spin up worktrees for X, Y, Z"
  • "create 3 worktrees for features A, B, C"
  • "new worktree for feature/auth"
  • "what's the status of my worktrees?"
  • "show all worktrees" / "show worktrees for this project"
  • "clean up merged worktrees"
  • "launch agent in worktree X"
触发语句:
  • "为X、Y、Z创建工作树"
  • "为功能A、B、C创建3个工作树"
  • "为feature/auth创建新工作树"
  • "我的工作树状态如何?"
  • "显示所有工作树" / "显示当前项目的工作树"
  • "清理已合并的工作树"
  • "在工作树X中启动agent"

Invocation

调用方式

Command syntax:
  • /worktree create feature/auth
    - Single worktree
  • /worktree create feat1 feat2 feat3
    - Multiple worktrees
  • /worktree status
    - Check all worktrees
  • /worktree status --project myapp
    - Filter by project
  • /worktree cleanup feature/auth
    - Remove worktree
  • /worktree launch feature/auth
    - Launch agent in worktree
</activation_triggers>
<file_locations>
命令语法:
  • /worktree create feature/auth
    - 创建单个工作树
  • /worktree create feat1 feat2 feat3
    - 创建多个工作树
  • /worktree status
    - 查看所有工作树状态
  • /worktree status --project myapp
    - 按项目过滤查看
  • /worktree cleanup feature/auth
    - 删除工作树
  • /worktree launch feature/auth
    - 在工作树中启动agent
</activation_triggers>
<file_locations>

Key Files

关键文件

FilePurpose
~/.claude/worktree-registry.json
Global registry - tracks all worktrees across all projects
~/.claude/skills/worktree-manager/config.json
Skill config - terminal, shell, port range settings
~/.claude/skills/worktree-manager/scripts/
Helper scripts - optional, can do everything manually
~/tmp/worktrees/
Worktree storage - all worktrees live here
.claude/
(per-project)
Project config - CLAUDE.md, hooks, permissions, custom agents
.claude/worktree.json
(per-project)
Project config - optional custom settings
WORKTREE_TASK.md
(per-worktree)
Auto-loaded task prompt - agent reads on startup
</file_locations>
<core_concepts>
文件用途
~/.claude/worktree-registry.json
全局注册表 - 跟踪所有项目的所有工作树
~/.claude/skills/worktree-manager/config.json
Skill配置文件 - 终端、Shell、端口范围设置
~/.claude/skills/worktree-manager/scripts/
辅助脚本 - 可选,所有操作也可手动完成
~/tmp/worktrees/
工作树存储目录 - 所有工作树的存放位置
.claude/
(每个项目下)
项目配置 - CLAUDE.md、钩子、权限、自定义agents
.claude/worktree.json
(每个项目下)
项目配置 - 可选自定义设置
WORKTREE_TASK.md
(每个工作树下)
自动加载的任务提示文件 - agent启动时会读取
</file_locations>
<core_concepts>

Core Concepts

核心概念

Centralized Worktree Storage

集中式工作树存储

All worktrees live in
~/tmp/worktrees/<project-name>/<branch-slug>/
~/tmp/worktrees/
├── obsidian-ai-agent/
│   ├── feature-auth/           # branch: feature/auth
│   ├── feature-payments/       # branch: feature/payments
│   └── fix-login-bug/          # branch: fix/login-bug
└── another-project/
    └── feature-dark-mode/
所有工作树都存放在
~/tmp/worktrees/<project-name>/<branch-slug>/
目录下
~/tmp/worktrees/
├── obsidian-ai-agent/
│   ├── feature-auth/           # 分支:feature/auth
│   ├── feature-payments/       # 分支:feature/payments
│   └── fix-login-bug/          # 分支:fix/login-bug
└── another-project/
    └── feature-dark-mode/

Branch Slug Convention

分支Slug命名规范

Branch names are slugified for filesystem safety:
  • feature/auth
    feature-auth
  • fix/login-bug
    fix-login-bug
Slugify manually:
echo "feature/auth" | tr '/' '-'
分支名称会被转换为Slug格式以确保文件系统安全:
  • feature/auth
    feature-auth
  • fix/login-bug
    fix-login-bug
手动转换Slug:
echo "feature/auth" | tr '/' '-'

Port Allocation

端口分配

  • Global pool: 8100-8199 (100 ports total)
  • Per worktree: 2 ports allocated (for API + frontend patterns)
  • Globally unique: Ports tracked to avoid conflicts across projects
See:
reference/port-allocation.md
for detailed operations.
  • 全局端口池:8100-8199(共100个端口)
  • 每个工作树:分配2个端口(适用于API+前端的典型架构)
  • 全局唯一:端口会被全局跟踪,避免跨项目冲突
详情参考:
reference/port-allocation.md
中的详细操作说明

Required Defaults

必需默认设置

CRITICAL: These settings MUST be used when launching agents:
SettingValueReason
TerminalGhostty or iTerm2Auto-detected, configurable in config.json
Model
--model opus
Opus 4.5 alias (most capable)
Flags
--dangerously-skip-permissions
Required for autonomous file ops
Launch command pattern:
bash
undefined
重要提示:启动agents时必须使用以下设置:
设置项原因
终端Ghostty或iTerm2自动检测,可在config.json中配置
模型
--model opus
Opus 4.5的别名(功能最强大)
标志
--dangerously-skip-permissions
自主文件操作必需
启动命令模板:
bash
undefined

Recommended: agent inherits .claude/ config (CLAUDE.md, hooks, permissions)

推荐:agent继承.claude/配置(CLAUDE.md、钩子、权限)

claude --model opus --dangerously-skip-permissions
claude --model opus --dangerously-skip-permissions

Or with explicit permission allowlist (safer, from .claude/settings.json):

或使用显式权限白名单(更安全,来自.claude/settings.json):

claude --model opus --allowedTools "Bash(npm test),Bash(npm run build),Edit,Write,Read,Glob,Grep"

</core_concepts>

<config>
claude --model opus --allowedTools "Bash(npm test),Bash(npm run build),Edit,Write,Read,Glob,Grep"

</core_concepts>

<config>

Skill Config

Skill配置

Location:
~/.claude/skills/worktree-manager/config.json
json
{
  "terminal": "ghostty",
  "terminalPreference": "auto",
  "enableNumberedTabs": true,
  "shell": "zsh",
  "defaultModel": "opus",
  "claudeCommand": "claude --model opus --dangerously-skip-permissions",
  "portPool": { "start": 8100, "end": 8199 },
  "portsPerWorktree": 2,
  "worktreeBase": "~/tmp/worktrees",
  "defaultCopyDirs": [".claude"],
  "envFilePriority": [".env.local", ".env", ".env.example"],
  "autoCleanupOnMerge": true
}
位置:
~/.claude/skills/worktree-manager/config.json
json
{
  "terminal": "ghostty",
  "terminalPreference": "auto",
  "enableNumberedTabs": true,
  "shell": "zsh",
  "defaultModel": "opus",
  "claudeCommand": "claude --model opus --dangerously-skip-permissions",
  "portPool": { "start": 8100, "end": 8199 },
  "portsPerWorktree": 2,
  "worktreeBase": "~/tmp/worktrees",
  "defaultCopyDirs": [".claude"],
  "envFilePriority": [".env.local", ".env", ".env.example"],
  "autoCleanupOnMerge": true
}

.claude/ Directory Propagation

.claude/目录的传播

When creating worktrees, the entire
.claude/
directory is copied so agents inherit project-level config:
.claude/
├── CLAUDE.md              # Project instructions (auto-loaded by Claude Code)
├── settings.json          # Hooks and permissions
│   ├── hooks.PostToolUse  # Auto-format on Write|Edit (e.g., "bun run format || true")
│   └── permissions.allow  # Whitelisted bash commands for agents
├── agents/                # Custom subagent definitions
│   ├── build-validator.md # Validates builds pass
│   ├── code-architect.md  # Plans implementation
│   ├── code-simplifier.md # Refactors for clarity
│   └── verify-app.md      # End-to-end verification
└── PROJECT_CONTEXT.md     # Session continuity (project-context-skill)
Why this matters:
  • CLAUDE.md: Agent reads project conventions, dev commands, tech stack
  • Hooks: Auto-formatting runs after every Write/Edit, keeping code consistent across agents
  • Permissions: Agents can run pre-approved commands without prompting (e.g.,
    npm test
    ,
    bun run build
    )
  • Custom agents: Agents can dispatch subagents (e.g.,
    verify-app.md
    for end-to-end checks)
Hook example (settings.json):
json
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Write|Edit",
        "hooks": [{ "type": "command", "command": "bun run format || true" }]
      }
    ]
  }
}
</config> <workflows>
创建工作树时,整个
.claude/
目录会被复制,以便agents继承项目级配置:
.claude/
├── CLAUDE.md              # 项目说明文档(Claude Code会自动加载)
├── settings.json          # 钩子和权限设置
│   ├── hooks.PostToolUse  # 在Write|Edit操作后自动格式化(例如:"bun run format || true")
│   └── permissions.allow  # agents可执行的Bash命令白名单
├── agents/                # 自定义子agent定义
│   ├── build-validator.md # 验证构建是否通过
│   ├── code-architect.md  # 规划实现方案
│   ├── code-simplifier.md # 重构以提升代码清晰度
│   └── verify-app.md      # 端到端验证
└── PROJECT_CONTEXT.md     # 会话连续性(project-context-skill)
为什么这很重要:
  • CLAUDE.md:agent会读取项目约定、开发命令、技术栈信息
  • 钩子:每次Write/Edit操作后自动执行格式化,确保所有agents的代码一致性
  • 权限:agents无需提示即可执行预批准的命令(例如:
    npm test
    bun run build
  • 自定义agents:agents可以调度子agents(例如:
    verify-app.md
    用于端到端检查)
钩子示例(settings.json):
json
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Write|Edit",
        "hooks": [{ "type": "command", "command": "bun run format || true" }]
      }
    ]
  }
}
</config> <workflows>

Workflows

工作流程

Create Multiple Worktrees

创建多个工作树

User says: "Spin up 3 worktrees for feature/auth, feature/payments, and fix/login-bug"
You do (can parallelize with subagents):
For EACH branch (can run in parallel):

1. SETUP
   PROJECT=$(basename $(git remote get-url origin 2>/dev/null | sed 's/\.git$//') || basename $(pwd))
   REPO_ROOT=$(git rev-parse --show-toplevel)
   BRANCH_SLUG=$(echo "feature/auth" | tr '/' '-')
   WORKTREE_PATH=~/tmp/worktrees/$PROJECT/$BRANCH_SLUG

2. ALLOCATE PORTS
   Find 2 unused ports from 8100-8199, add to registry

3. CREATE WORKTREE
   mkdir -p ~/tmp/worktrees/$PROJECT
   git worktree add $WORKTREE_PATH -b $BRANCH

4. COPY PROJECT CONFIG (.claude/ directory)
   cp -r .claude $WORKTREE_PATH/ 2>/dev/null || true
   Copy .env.local or .env as appropriate

5. CREATE WORKTREE_TASK.md
   Create detailed task file for agent

6. INSTALL DEPENDENCIES
   Detect package manager, run install command

7. VALIDATE (optional)
   Start server, health check, stop

8. REGISTER IN GLOBAL REGISTRY
   Update ~/.claude/worktree-registry.json with entry

9. LAUNCH AGENT
   ghostty -e "cd $WORKTREE_PATH && claude --model opus --dangerously-skip-permissions"

AFTER ALL COMPLETE:
- Report summary table to user
用户请求: "为feature/auth、feature/payments和fix/login-bug创建3个工作树"
执行操作(可通过子agents并行处理):
针对每个分支(可并行执行):

1. 准备工作
   PROJECT=$(basename $(git remote get-url origin 2>/dev/null | sed 's/\.git$//') || basename $(pwd))
   REPO_ROOT=$(git rev-parse --show-toplevel)
   BRANCH_SLUG=$(echo "feature/auth" | tr '/' '-')
   WORKTREE_PATH=~/tmp/worktrees/$PROJECT/$BRANCH_SLUG

2. 分配端口
   从8100-8199中找到2个未使用的端口,添加到注册表

3. 创建工作树
   mkdir -p ~/tmp/worktrees/$PROJECT
   git worktree add $WORKTREE_PATH -b $BRANCH

4. 复制项目配置(.claude/目录)
   cp -r .claude $WORKTREE_PATH/ 2>/dev/null || true
   复制合适的.env.local或.env文件

5. 创建WORKTREE_TASK.md
   为agent创建详细的任务文件

6. 安装依赖
   检测包管理器,执行安装命令

7. 验证(可选)
   启动服务器、健康检查、停止服务器

8. 注册到全局注册表
   更新`~/.claude/worktree-registry.json`添加条目

9. 启动agent
   ghostty -e "cd $WORKTREE_PATH && claude --model opus --dangerously-skip-permissions"

所有分支处理完成后:
- 向用户报告汇总表格

Check Status

查看状态

With script:
bash
~/.claude/skills/worktree-manager/scripts/status.sh
~/.claude/skills/worktree-manager/scripts/status.sh --project my-project
Manual:
bash
cat ~/.claude/worktree-registry.json | jq -r '.worktrees[] | "\(.project)\t\(.branch)\t\(.ports | join(","))\t\(.status)"'
使用脚本:
bash
~/.claude/skills/worktree-manager/scripts/status.sh
~/.claude/skills/worktree-manager/scripts/status.sh --project my-project
手动查看:
bash
cat ~/.claude/worktree-registry.json | jq -r '.worktrees[] | "\(.project)\t\(.branch)\t\(.ports | join(","))\t\(.status)"'

Cleanup Worktree

清理工作树

See:
reference/cleanup-operations.md
for full cleanup procedure.
Quick cleanup:
bash
~/.claude/skills/worktree-manager/scripts/cleanup.sh <project> <branch> --delete-branch
</workflows> <routing>
详情参考:
reference/cleanup-operations.md
中的完整清理流程
快速清理:
bash
~/.claude/skills/worktree-manager/scripts/cleanup.sh <project> <branch> --delete-branch
</workflows> <routing>

Reference Files

参考文件

For detailed operations, see:
TopicFile
Registry operations
reference/registry-operations.md
Port allocation
reference/port-allocation.md
Agent launching
reference/agent-launching.md
System notifications
reference/system-notifications.md
Script reference
reference/script-reference.md
Cleanup operations
reference/cleanup-operations.md
Troubleshooting
reference/troubleshooting.md
</routing>
<safety_guidelines>
如需详细操作说明,请查看:
主题文件
注册表操作
reference/registry-operations.md
端口分配
reference/port-allocation.md
Agent启动
reference/agent-launching.md
系统通知
reference/system-notifications.md
脚本参考
reference/script-reference.md
清理操作
reference/cleanup-operations.md
故障排除
reference/troubleshooting.md
</routing>
<safety_guidelines>

Safety Guidelines

安全指南

  1. Before cleanup, check PR status:
    • PR merged → safe to clean everything
    • PR open → warn user, confirm before proceeding
    • No PR → warn about unsubmitted work
  2. Before deleting branches, confirm if:
    • PR not merged
    • No PR exists
    • Worktree has uncommitted changes
  3. Port conflicts: If port in use by non-worktree process, pick different port
  4. Environment files: Never commit
    .env
    or
    .env.local
    to git
</safety_guidelines>
<example_session>
  1. 清理前,检查PR状态:
    • PR已合并 → 可安全清理所有内容
    • PR未合并 → 向用户发出警告,确认后再继续
    • 无PR → 警告用户存在未提交的工作
  2. 删除分支前,确认以下情况:
    • PR未合并
    • 没有对应的PR
    • 工作树中有未提交的更改
  3. 端口冲突:如果端口被非工作树进程占用,选择其他端口
  4. 环境文件:绝不要将
    .env
    .env.local
    提交到git
</safety_guidelines>
<example_session>

Example Session

示例会话

User: "Spin up 2 worktrees for feature/dark-mode and fix/login-bug"
You:
  1. Detect project:
    obsidian-ai-agent
    (from git remote)
  2. Detect package manager:
    uv
    (found uv.lock)
  3. Allocate 4 ports:
    8100 8101 8102 8103
  4. Create worktrees:
    bash
    git worktree add ~/tmp/worktrees/obsidian-ai-agent/feature-dark-mode -b feature/dark-mode
    git worktree add ~/tmp/worktrees/obsidian-ai-agent/fix-login-bug -b fix/login-bug
  5. Copy .claude/ and .env to each
  6. Install deps:
    (cd <path> && uv sync)
  7. Register both in
    ~/.claude/worktree-registry.json
  8. Launch agents:
    bash
    ghostty -e "cd ~/tmp/worktrees/.../feature-dark-mode && claude --model opus --dangerously-skip-permissions"
  9. Report:
    Created 2 worktrees with agents:
    
    | Branch | Ports | Path | Task |
    |--------|-------|------|------|
    | feature/dark-mode | 8100, 8101 | ~/tmp/worktrees/.../feature-dark-mode | Implement dark mode |
    | fix/login-bug | 8102, 8103 | ~/tmp/worktrees/.../fix-login-bug | Fix login redirect |
    
    Both agents running in Ghostty windows.
</example_session>

用户: "为feature/dark-mode和fix/login-bug创建2个工作树"
执行操作:
  1. 检测项目:
    obsidian-ai-agent
    (来自git远程仓库)
  2. 检测包管理器:
    uv
    (发现uv.lock文件)
  3. 分配4个端口:
    8100 8101 8102 8103
  4. 创建工作树:
    bash
    git worktree add ~/tmp/worktrees/obsidian-ai-agent/feature-dark-mode -b feature/dark-mode
    git worktree add ~/tmp/worktrees/obsidian-ai-agent/fix-login-bug -b fix/login-bug
  5. 复制.claude/和.env文件到每个工作树
  6. 安装依赖:
    (cd <path> && uv sync)
  7. ~/.claude/worktree-registry.json
    中注册这两个工作树
  8. 启动agents:
    bash
    ghostty -e "cd ~/tmp/worktrees/.../feature-dark-mode && claude --model opus --dangerously-skip-permissions"
  9. 向用户报告:
    已创建2个带agents的工作树:
    
    | 分支 | 端口 | 路径 | 任务 |
    |--------|-------|------|------|
    | feature/dark-mode | 8100, 8101 | ~/tmp/worktrees/.../feature-dark-mode | 实现暗黑模式 |
    | fix/login-bug | 8102, 8103 | ~/tmp/worktrees/.../fix-login-bug | 修复登录重定向问题 |
    
    两个agents均在Ghostty窗口中运行。
</example_session>

Boris Cherny Workflow Integration

Boris Cherny工作流集成

Based on Boris Cherny's (Claude Code creator) 13-step autonomous workflow.
基于Claude Code创造者Boris Cherny的13步自主工作流实现。

iTerm2 Notifications Setup

iTerm2通知设置

Enable system notifications when Claude needs input (Boris runs 5 numbered tabs):
Step 1: iTerm2 Preferences
  1. iTerm2 → Preferences → Profiles → Terminal
  2. Enable "Notification when idle"
  3. Set "After 30 seconds of silence, send notification"
Step 2: Shell Integration (Optional)
bash
undefined
当Claude需要输入时启用系统通知(Boris使用5个编号标签页):
步骤1:iTerm2偏好设置
  1. 打开iTerm2 → 偏好设置 → 配置文件 → 终端
  2. 启用"空闲时发送通知"
  3. 设置"静默30秒后发送通知"
步骤2:Shell集成(可选)
bash
undefined

Add to ~/.zshrc for manual attention requests

添加到~/.zshrc以手动请求关注

it2attention() { printf "\e]1337;RequestAttention=fireworks\a"; }

**Step 3: Tab Numbering**
The launch-agent.sh script automatically numbers iTerm2 tabs as `[1] project - branch`, `[2] project - branch`, etc. when using `--terminal iterm2`.
it2attention() { printf "\e]1337;RequestAttention=fireworks\a"; }

**步骤3:标签页编号**
当使用`--terminal iterm2`时,launch-agent.sh脚本会自动将iTerm2标签页编号为`[1] project - branch`、`[2] project - branch`等格式。

Web Session Handoff (Teleport)

Web会话移交(Teleport)

Hand off local session to claude.ai/code for longer tasks or mobile monitoring:
bash
undefined
将本地会话移交到claude.ai/code以处理更长任务或通过移动端监控:
bash
undefined

In terminal Claude session, run:

在终端Claude会话中运行:

/teleport
/teleport

Or use ampersand for background handoff:

或使用&在后台移交:

claude & teleport

**Workflow:**
1. Start work in terminal
2. When leaving desk, run `/teleport`
3. Continue from https://claude.ai/code
4. Or check in from Claude iOS app
5. Resume locally: `claude --resume <session-id>`
claude & teleport

**工作流:**
1. 在终端开始工作
2. 离开工位时,运行`/teleport`
3. 在https://claude.ai/code继续工作
4. 或通过Claude iOS应用查看进度
5. 在本地恢复会话:`claude --resume <session-id>`

Long-Running Autonomous Sessions (Ralph Loop)

长期自主会话(Ralph Loop)

For tasks that need extended autonomous work without intervention:
Step 1: Create worktree
spin up worktree for feature/big-refactor
Step 2: Start ralph loop in worktree terminal
/ralph-loop "Implement complete auth system with tests" --max-iterations 10
Step 3: Set completion promise (optional)
/ralph-loop "Refactor database layer" --completion-promise "All tests pass and no type errors"
How Ralph Loop Works:
  • Claude works on the task
  • When it tries to exit, the SAME PROMPT is fed back
  • Claude sees previous work in files and git history
  • Iterates until completion promise is met or max iterations reached
  • Use with
    --dangerously-skip-permissions
    for fully autonomous operation
Verification Integration:
bash
/ralph-loop "Implement feature X" --completion-promise "verify-app returns OVERALL: PASS"
适用于需要长时间自主工作无需干预的任务:
步骤1:创建工作树
为feature/big-refactor创建工作树
步骤2:在工作树终端中启动Ralph Loop
/ralph-loop "实现完整的带测试的认证系统" --max-iterations 10
步骤3:设置完成条件(可选)
/ralph-loop "重构数据库层" --completion-promise "所有测试通过且无类型错误"
Ralph Loop工作原理:
  • Claude处理任务
  • 当它尝试退出时,会重新输入相同的提示
  • Claude会查看文件和git历史中的之前工作成果
  • 迭代直到满足完成条件或达到最大迭代次数
  • 配合
    --dangerously-skip-permissions
    使用可实现完全自主操作
验证集成:
bash
/ralph-loop "实现功能X" --completion-promise "verify-app返回OVERALL: PASS"

Terminal Strategy

终端策略

Use CaseTerminalWhy
Quick interactive workGhosttyFast, clean UI
Monitored parallel sessionsiTerm2Numbered tabs + notifications
Long autonomous tasksiTerm2 + ralph-loopBackground with alerts
CI/CD integrationtmuxDetached sessions
使用场景终端原因
快速交互式工作Ghostty快速、简洁的UI
受监控的并行会话iTerm2编号标签页+通知
长期自主任务iTerm2 + ralph-loop后台运行并带提醒
CI/CD集成tmux分离式会话

Daily Workflow Protocol

日常工作流规范

Morning:
bash
undefined
早晨:
bash
undefined

1. Check worktree status

1. 检查工作树状态

cat ~/.claude/worktree-registry.json | jq '.worktrees[] | select(.status == "active")'
cat ~/.claude/worktree-registry.json | jq '.worktrees[] | select(.status == "active")'

3. Start primary session

3. 启动主会话

cd ~/tk_projects/<priority-project> claude --model opus

**Parallel Work:**
```bash
cd ~/tk_projects/<priority-project> claude --model opus

**并行工作:**
```bash

Spin up 3 worktrees with iTerm2 tabs

创建3个带iTerm2标签页的工作树

spin up worktrees for feature/a, feature/b, feature/c --terminal iterm2
为feature/a、feature/b、feature/c创建工作树 --terminal iterm2

Or use Ghostty for quick sessions

或使用Ghostty进行快速会话

spin up worktree for fix/quick-bug --terminal ghostty

**End of Day:**
```bash
为fix/quick-bug创建工作树 --terminal ghostty

**下班前:**
```bash

Check merged PRs

查看已合并的PR

gh pr list --state merged --author @me --limit 10
gh pr list --state merged --author @me --limit 10

Cleanup merged worktrees

清理已合并的工作树

cleanup merged worktrees
undefined
清理已合并的工作树
undefined