codeforge-dev 1.14.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/{.devcontainer/config/defaults → .codeforge/config}/ccstatusline-settings.json +44 -6
  2. package/{.devcontainer/config/defaults → .codeforge/config}/main-system-prompt.md +14 -6
  3. package/.codeforge/config/orchestrator-system-prompt.md +333 -0
  4. package/{.devcontainer/config/defaults → .codeforge/config}/settings.json +3 -1
  5. package/{.devcontainer/config → .codeforge}/file-manifest.json +15 -9
  6. package/{.devcontainer → .codeforge/scripts}/connect-external-terminal.sh +3 -1
  7. package/.devcontainer/.env.example +5 -5
  8. package/.devcontainer/.secrets.example +3 -0
  9. package/.devcontainer/CHANGELOG.md +242 -0
  10. package/.devcontainer/CLAUDE.md +129 -22
  11. package/.devcontainer/README.md +34 -19
  12. package/.devcontainer/devcontainer.json +28 -10
  13. package/.devcontainer/features/agent-browser/install.sh +2 -0
  14. package/.devcontainer/features/ast-grep/install.sh +2 -0
  15. package/.devcontainer/features/biome/install.sh +2 -0
  16. package/.devcontainer/features/ccburn/install.sh +2 -0
  17. package/.devcontainer/features/ccms/install.sh +2 -0
  18. package/.devcontainer/features/ccstatusline/README.md +7 -6
  19. package/.devcontainer/features/ccstatusline/install.sh +9 -4
  20. package/.devcontainer/features/ccusage/install.sh +2 -0
  21. package/.devcontainer/features/chromaterm/chromaterm.yml +2 -2
  22. package/.devcontainer/features/chromaterm/install.sh +2 -0
  23. package/.devcontainer/features/claude-code-native/README.md +47 -0
  24. package/.devcontainer/features/claude-code-native/devcontainer-feature.json +29 -0
  25. package/.devcontainer/features/claude-code-native/install.sh +131 -0
  26. package/.devcontainer/features/claude-monitor/install.sh +2 -0
  27. package/.devcontainer/features/claude-session-dashboard/README.md +2 -2
  28. package/.devcontainer/features/claude-session-dashboard/install.sh +2 -0
  29. package/.devcontainer/features/dprint/install.sh +2 -0
  30. package/.devcontainer/features/hadolint/install.sh +2 -0
  31. package/.devcontainer/features/kitty-terminfo/README.md +3 -1
  32. package/.devcontainer/features/kitty-terminfo/install.sh +2 -0
  33. package/.devcontainer/features/lsp-servers/install.sh +2 -0
  34. package/.devcontainer/features/mcp-qdrant/CHANGES.md +3 -3
  35. package/.devcontainer/features/mcp-qdrant/README.md +1 -0
  36. package/.devcontainer/features/mcp-qdrant/devcontainer-feature.json +1 -1
  37. package/.devcontainer/features/mcp-qdrant/install.sh +9 -2
  38. package/.devcontainer/features/mcp-qdrant/poststart-hook.sh +9 -2
  39. package/.devcontainer/features/notify-hook/devcontainer-feature.json +1 -1
  40. package/.devcontainer/features/notify-hook/install.sh +2 -0
  41. package/.devcontainer/features/ruff/install.sh +2 -0
  42. package/.devcontainer/features/shellcheck/install.sh +2 -0
  43. package/.devcontainer/features/shfmt/install.sh +2 -0
  44. package/.devcontainer/features/tmux/README.md +3 -3
  45. package/.devcontainer/features/tmux/install.sh +3 -1
  46. package/.devcontainer/features/tree-sitter/install.sh +2 -0
  47. package/.devcontainer/plugins/devs-marketplace/.claude-plugin/marketplace.json +27 -11
  48. package/.devcontainer/plugins/devs-marketplace/plugins/agent-system/README.md +23 -4
  49. package/.devcontainer/plugins/devs-marketplace/plugins/agent-system/agents/claude-guide.md +4 -4
  50. package/.devcontainer/plugins/devs-marketplace/plugins/agent-system/agents/documenter.md +254 -0
  51. package/.devcontainer/plugins/devs-marketplace/plugins/agent-system/agents/implementer.md +260 -0
  52. package/.devcontainer/plugins/devs-marketplace/plugins/agent-system/agents/investigator.md +255 -0
  53. package/.devcontainer/plugins/devs-marketplace/plugins/agent-system/agents/tester.md +304 -0
  54. package/.devcontainer/plugins/devs-marketplace/plugins/auto-code-quality/README.md +1 -1
  55. package/.devcontainer/plugins/devs-marketplace/plugins/auto-code-quality/scripts/advisory-test-runner.py +4 -2
  56. package/.devcontainer/plugins/devs-marketplace/plugins/dangerous-command-blocker/scripts/block-dangerous.py +2 -2
  57. package/.devcontainer/plugins/devs-marketplace/plugins/git-workflow/.claude-plugin/plugin.json +7 -0
  58. package/.devcontainer/plugins/devs-marketplace/plugins/git-workflow/README.md +125 -0
  59. package/.devcontainer/plugins/devs-marketplace/plugins/git-workflow/skills/pr-review/SKILL.md +325 -0
  60. package/.devcontainer/plugins/devs-marketplace/plugins/git-workflow/skills/ship/SKILL.md +314 -0
  61. package/.devcontainer/plugins/devs-marketplace/plugins/prompt-snippets/.claude-plugin/plugin.json +5 -0
  62. package/.devcontainer/plugins/devs-marketplace/plugins/prompt-snippets/README.md +52 -0
  63. package/.devcontainer/plugins/devs-marketplace/plugins/prompt-snippets/skills/ps/SKILL.md +37 -0
  64. package/.devcontainer/plugins/devs-marketplace/plugins/protected-files-guard/scripts/guard-protected-bash.py +1 -1
  65. package/.devcontainer/plugins/devs-marketplace/plugins/protected-files-guard/scripts/guard-protected.py +1 -1
  66. package/.devcontainer/plugins/devs-marketplace/plugins/session-context/README.md +30 -14
  67. package/.devcontainer/plugins/devs-marketplace/plugins/session-context/hooks/hooks.json +13 -1
  68. package/.devcontainer/plugins/devs-marketplace/plugins/session-context/scripts/collect-session-edits.py +44 -0
  69. package/.devcontainer/plugins/devs-marketplace/plugins/session-context/scripts/commit-reminder.py +89 -10
  70. package/.devcontainer/plugins/devs-marketplace/plugins/skill-engine/.claude-plugin/plugin.json +1 -1
  71. package/.devcontainer/plugins/devs-marketplace/plugins/skill-engine/README.md +19 -11
  72. package/.devcontainer/plugins/devs-marketplace/plugins/skill-engine/scripts/skill-suggester.py +476 -282
  73. package/.devcontainer/plugins/devs-marketplace/plugins/skill-engine/skills/worktree/SKILL.md +227 -0
  74. package/.devcontainer/plugins/devs-marketplace/plugins/skill-engine/skills/worktree/references/manual-worktree-commands.md +238 -0
  75. package/.devcontainer/plugins/devs-marketplace/plugins/skill-engine/skills/worktree/references/parallel-workflow-patterns.md +228 -0
  76. package/.devcontainer/plugins/devs-marketplace/plugins/ticket-workflow/scripts/ticket-linker.py +2 -2
  77. package/.devcontainer/plugins/devs-marketplace/plugins/workspace-scope-guard/README.md +1 -1
  78. package/.devcontainer/plugins/devs-marketplace/plugins/workspace-scope-guard/scripts/guard-workspace-scope.py +3 -2
  79. package/.devcontainer/scripts/check-setup.sh +5 -3
  80. package/.devcontainer/scripts/preflight.sh +113 -0
  81. package/.devcontainer/scripts/setup-aliases.sh +13 -8
  82. package/.devcontainer/scripts/setup-auth.sh +46 -0
  83. package/.devcontainer/scripts/setup-config.sh +29 -10
  84. package/.devcontainer/scripts/setup-migrate-claude.sh +80 -0
  85. package/.devcontainer/scripts/setup-migrate-codeforge.sh +60 -0
  86. package/.devcontainer/scripts/setup-plugins.sh +3 -1
  87. package/.devcontainer/scripts/setup-projects.sh +3 -1
  88. package/.devcontainer/scripts/setup-terminal.sh +3 -1
  89. package/.devcontainer/scripts/setup-update-claude.sh +22 -27
  90. package/.devcontainer/scripts/setup.sh +57 -5
  91. package/LICENSE.txt +14 -0
  92. package/README.md +79 -5
  93. package/package.json +2 -1
  94. package/setup.js +392 -21
  95. package/.devcontainer/docs/configuration-reference.md +0 -93
  96. package/.devcontainer/docs/keybindings.md +0 -100
  97. package/.devcontainer/docs/optional-features.md +0 -64
  98. package/.devcontainer/docs/plugins.md +0 -176
  99. package/.devcontainer/docs/troubleshooting.md +0 -128
  100. package/.devcontainer/scripts/setup-symlink-claude.sh +0 -36
  101. /package/{.devcontainer/config/defaults → .codeforge/config}/keybindings.json +0 -0
  102. /package/{.devcontainer/config/defaults → .codeforge/config}/rules/session-search.md +0 -0
  103. /package/{.devcontainer/config/defaults → .codeforge/config}/rules/spec-workflow.md +0 -0
  104. /package/{.devcontainer/config/defaults → .codeforge/config}/rules/workspace-scope.md +0 -0
  105. /package/{.devcontainer/config/defaults → .codeforge/config}/writing-system-prompt.md +0 -0
  106. /package/{.devcontainer → .codeforge/scripts}/connect-external-terminal.ps1 +0 -0
@@ -0,0 +1,227 @@
1
+ ---
2
+ name: worktree
3
+ description: >-
4
+ Guides git worktree creation, management, and cleanup for parallel
5
+ development workflows including EnterWorktree usage, .worktreeinclude
6
+ setup, and worktree lifecycle. USE WHEN the user asks to "create a
7
+ worktree", "work in a worktree", "set up parallel branches", "isolate
8
+ my work", "clean up worktrees", "list worktrees", "enter worktree",
9
+ "worktree include", or works with git worktree commands, EnterWorktree,
10
+ or parallel development patterns. DO NOT USE for routine git branching
11
+ or single-branch workflows.
12
+ version: 0.1.0
13
+ allowed-tools: Bash, Read, Grep, Glob, EnterWorktree
14
+ ---
15
+
16
+ # Git Worktrees
17
+
18
+ ## Mental Model
19
+
20
+ A git worktree is a parallel checkout of the same repository. One `.git` database, multiple working directories, each on a different branch. Think of it as having multiple monitors for code — same project, different contexts, simultaneously active.
21
+
22
+ The key difference from branches: a branch is a pointer to a commit; a worktree is a full working directory with its own index and working tree. Switching branches requires stashing, committing, or discarding changes. Switching worktrees means walking to a different directory.
23
+
24
+ Use worktrees when:
25
+ - **Parallel features** — work on two features without context-switching overhead
26
+ - **Safe experimentation** — try a risky refactor without touching the main checkout
27
+ - **Code review** — review a PR in one worktree while continuing work in another
28
+ - **Hotfixes** — address an urgent bug without stashing mid-feature work
29
+ - **Agent isolation** — give Claude Code agents their own working directory to prevent file conflicts
30
+
31
+ ---
32
+
33
+ ## Creating Worktrees
34
+
35
+ ### Primary: EnterWorktree Tool (In-Session)
36
+
37
+ The fastest way to create a worktree during a Claude Code session. Call `EnterWorktree` with a descriptive name:
38
+
39
+ ```text
40
+ EnterWorktree: feature-auth-oauth2
41
+ ```
42
+
43
+ **Behavior:**
44
+ - Creates worktree at `<repo>/.claude/worktrees/<name>/`
45
+ - Branches from current HEAD
46
+ - Auto-names the branch `worktree-<name>`
47
+ - Session moves into the worktree directory
48
+ - **Auto-cleanup:** If no changes are made, the worktree and branch are removed on session exit. If changes exist, Claude prompts to keep or remove.
49
+
50
+ ### CLI Flag: `--worktree`
51
+
52
+ Start a new Claude Code session directly in a worktree:
53
+
54
+ ```bash
55
+ # Named worktree
56
+ claude --worktree feature-auth-oauth2
57
+
58
+ # Auto-generated name
59
+ claude --worktree
60
+
61
+ # Combined with tmux for background work
62
+ claude --worktree feature-auth-oauth2 --tmux
63
+ ```
64
+
65
+ The worktree is created at `<repo>/.claude/worktrees/<name>/` with the same auto-cleanup behavior as `EnterWorktree`.
66
+
67
+ ### Manual: `git worktree add`
68
+
69
+ For worktrees outside of Claude Code sessions, or when precise control over path and branch is needed:
70
+
71
+ ```bash
72
+ # Create worktree with new branch
73
+ git worktree add /path/to/worktree -b feature-branch-name
74
+
75
+ # Create worktree tracking existing branch
76
+ git worktree add /path/to/worktree existing-branch
77
+ ```
78
+
79
+ > **Deep dive:** See `references/manual-worktree-commands.md` for the full command reference with all flags, path conventions, and troubleshooting.
80
+
81
+ ### Naming Conventions
82
+
83
+ - **Kebab-case, descriptive:** `feature-auth-oauth2`, `bugfix-login-timeout`, `spike-new-db`
84
+ - **Prefix with category:** `feature-`, `bugfix-`, `spike-`, `chore-`
85
+ - **Claude Code auto-naming:** Branches created by `--worktree` or `EnterWorktree` are prefixed `worktree-`
86
+
87
+ ---
88
+
89
+ ## Environment Setup
90
+
91
+ ### `.worktreeinclude` File
92
+
93
+ New worktrees start with only tracked files. Environment files (`.env`, `.env.local`) are typically `.gitignore`-excluded and will be missing. The `.worktreeinclude` file solves this.
94
+
95
+ Place at the project root. It lists `.gitignore`-excluded files that should be **copied into every new worktree** automatically:
96
+
97
+ ```gitignore
98
+ .env
99
+ .env.local
100
+ .env.*
101
+ **/.claude/settings.local.json
102
+ ```
103
+
104
+ **Rules:**
105
+ - Uses `.gitignore` pattern syntax
106
+ - Only files matching **both** `.worktreeinclude` and `.gitignore` are copied
107
+ - Tracked files are never duplicated (they come from the checkout itself)
108
+ - Commit `.worktreeinclude` to the repo so the team benefits
109
+
110
+ **If `.worktreeinclude` doesn't exist:** Copy environment files manually after worktree creation, or create the file first.
111
+
112
+ ### Post-Creation Checklist
113
+
114
+ After creating a worktree, the working directory needs initialization:
115
+
116
+ 1. **Install dependencies** — `npm install`, `uv sync`, `cargo build`, or whatever the project requires. Worktrees share the git database but not `node_modules/`, `.venv/`, or `target/`.
117
+ 2. **Run `/init`** — in a new Claude Code session within the worktree, run `/init` to orient Claude to the worktree context.
118
+ 3. **Verify the dev environment** — run the test suite or start the dev server to confirm everything works.
119
+
120
+ ---
121
+
122
+ ## Managing Worktrees
123
+
124
+ ### Listing
125
+
126
+ ```bash
127
+ git worktree list
128
+ ```
129
+
130
+ Output shows each worktree's path, HEAD commit, and branch:
131
+
132
+ ```text
133
+ /workspaces/projects/CodeForge d2ba55e [main]
134
+ /workspaces/projects/.worktrees/feature-a abc1234 [feature-a]
135
+ ```
136
+
137
+ ### Switching Context
138
+
139
+ Worktrees are directories. To switch context:
140
+ - **Terminal:** Open a new terminal and `cd` to the worktree path
141
+ - **VS Code Project Manager:** Worktrees in `.worktrees/` are auto-detected and tagged `"worktree"` — click to open
142
+ - **Claude Code:** Start a new session with `claude --worktree <name>` or use `EnterWorktree`
143
+
144
+ ### Cleanup
145
+
146
+ **Claude Code auto-cleanup:**
147
+ - No changes → worktree and branch removed automatically on session exit
148
+ - Changes exist → prompted to keep or remove
149
+
150
+ **Manual cleanup** (confirm with user first — destructive):
151
+
152
+ ```bash
153
+ # Remove a specific worktree
154
+ git worktree remove /path/to/worktree
155
+
156
+ # Force remove (discards uncommitted changes)
157
+ git worktree remove --force /path/to/worktree
158
+
159
+ # Clean up stale worktree references (after manual directory deletion)
160
+ git worktree prune
161
+ ```
162
+
163
+ ### Merging Work Back
164
+
165
+ After completing work in a worktree:
166
+
167
+ 1. **Commit and push** the worktree branch
168
+ 2. **Create a PR** from the worktree branch to the target branch
169
+ 3. **After merge**, clean up:
170
+ ```bash
171
+ git worktree remove /path/to/worktree
172
+ git branch -d worktree-feature-name # delete merged branch
173
+ ```
174
+
175
+ Alternatively, merge locally:
176
+ ```bash
177
+ # From the main checkout
178
+ git merge feature-branch-name
179
+ ```
180
+
181
+ ---
182
+
183
+ ## CodeForge Integration
184
+
185
+ ### Project Manager Auto-Detection
186
+
187
+ The `setup-projects.sh` script scans `.worktrees/` directories at depth 3. Worktrees are detected by checking for a `.git` **file** (not directory) containing a `gitdir:` pointer. Detected worktrees receive both `"git"` and `"worktree"` tags in VS Code Project Manager.
188
+
189
+ ### Agent Isolation
190
+
191
+ Four CodeForge agents use `isolation: worktree` in their frontmatter — refactorer, test-writer, migrator, and doc-writer. When spawned via the `Task` tool, these agents automatically get their own worktree copy of the repository. The worktree is cleaned up after the agent finishes (removed if no changes; kept if changes exist).
192
+
193
+ ### Workspace Scope Guard
194
+
195
+ Each worktree is treated as an independent project directory by the workspace-scope-guard plugin. File operations are restricted to the worktree's directory boundary.
196
+
197
+ ### Path Conventions
198
+
199
+ Two conventions coexist:
200
+
201
+ | Convention | Path | Used by |
202
+ |-----------|------|---------|
203
+ | **Native (primary)** | `<repo>/.claude/worktrees/<name>/` | `--worktree` flag, `EnterWorktree` tool |
204
+ | **Legacy** | `<container-dir>/.worktrees/<name>/` | Manual `git worktree add`, Project Manager detection |
205
+
206
+ Native is recommended for Claude Code sessions. Legacy is used for manual worktree management and remains supported by `setup-projects.sh`.
207
+
208
+ ---
209
+
210
+ ## Ambiguity Policy
211
+
212
+ - Default to `EnterWorktree` for in-session worktree creation.
213
+ - Default to the native path convention unless the user specifies otherwise.
214
+ - When the purpose is unclear, ask: "What will you work on in the worktree?"
215
+ - Default branch base: current branch HEAD, not main/master.
216
+ - Default cleanup: prompt before removing worktrees with uncommitted changes.
217
+ - When `.worktreeinclude` doesn't exist and the project has `.env` files, suggest creating one.
218
+ - For agent work, defer to the `team` skill for orchestration — worktree isolation is automatic for agents that declare it.
219
+
220
+ ---
221
+
222
+ ## Reference Files
223
+
224
+ | File | Contents |
225
+ |------|----------|
226
+ | `references/manual-worktree-commands.md` | Full `git worktree` command reference with all flags, path conventions, `.git` file anatomy, and troubleshooting |
227
+ | `references/parallel-workflow-patterns.md` | Workflow patterns for multi-worktree development, agent swarms, hooks, and anti-patterns |
@@ -0,0 +1,238 @@
1
+ # Git Worktree Command Reference
2
+
3
+ Complete reference for `git worktree` subcommands with flags, path conventions, and troubleshooting.
4
+
5
+ ---
6
+
7
+ ## `git worktree add`
8
+
9
+ Create a new worktree linked to the current repository.
10
+
11
+ ```bash
12
+ # New branch from HEAD
13
+ git worktree add <path> -b <new-branch>
14
+
15
+ # Existing branch
16
+ git worktree add <path> <existing-branch>
17
+
18
+ # Detached HEAD at specific commit
19
+ git worktree add --detach <path> <commit>
20
+
21
+ # Track a remote branch
22
+ git worktree add <path> --track -b <local-name> origin/<remote-branch>
23
+ ```
24
+
25
+ ### Common Flags
26
+
27
+ | Flag | Purpose |
28
+ |------|---------|
29
+ | `-b <branch>` | Create and checkout a new branch |
30
+ | `-B <branch>` | Create or reset and checkout a branch |
31
+ | `--detach` | Checkout in detached HEAD state |
32
+ | `--track` | Set up tracking for the new branch |
33
+ | `--no-checkout` | Create worktree without checking out files (fast, populate later) |
34
+ | `--lock` | Lock the worktree immediately after creation |
35
+ | `-f` / `--force` | Override safeguards (e.g., allow checking out a branch already in another worktree) |
36
+ | `--orphan` | Create worktree with a new orphan branch (no parent commits) |
37
+
38
+ ### Path Conventions
39
+
40
+ **Claude Code native convention (recommended for Claude sessions):**
41
+ ```bash
42
+ # Automatic — handled by --worktree flag or EnterWorktree
43
+ # Path: <repo>/.claude/worktrees/<name>/
44
+ # Branch: worktree-<name>
45
+ claude --worktree feature-auth
46
+ ```
47
+
48
+ **Legacy CodeForge convention (for manual management):**
49
+ ```bash
50
+ # Container directory .worktrees/ sibling to repos
51
+ mkdir -p /workspaces/projects/.worktrees
52
+ git worktree add /workspaces/projects/.worktrees/<name> -b <branch>
53
+ ```
54
+
55
+ **General best practice:**
56
+ - Keep worktrees in a predictable location
57
+ - Use the same naming pattern for worktree directories and branches
58
+ - Add the worktree directory to `.gitignore` if it lives inside the repo
59
+
60
+ ---
61
+
62
+ ## `git worktree list`
63
+
64
+ Show all worktrees linked to the repository.
65
+
66
+ ```bash
67
+ # Default format
68
+ git worktree list
69
+
70
+ # Porcelain format (machine-readable)
71
+ git worktree list --porcelain
72
+ ```
73
+
74
+ **Default output:**
75
+ ```text
76
+ /workspaces/projects/CodeForge d2ba55e [main]
77
+ /workspaces/projects/.worktrees/feature-a abc1234 [feature-a]
78
+ /workspaces/projects/.worktrees/bugfix-b def5678 [bugfix-b] locked
79
+ ```
80
+
81
+ **Porcelain output:**
82
+ ```text
83
+ worktree /workspaces/projects/CodeForge
84
+ HEAD d2ba55eabc1234def5678901234567890abcdef
85
+ branch refs/heads/main
86
+
87
+ worktree /workspaces/projects/.worktrees/feature-a
88
+ HEAD abc1234def5678901234567890abcdef01234567
89
+ branch refs/heads/feature-a
90
+ ```
91
+
92
+ ---
93
+
94
+ ## `git worktree remove`
95
+
96
+ Remove a worktree and its administrative files. **Destructive — confirm before executing.**
97
+
98
+ ```bash
99
+ # Remove (fails if there are uncommitted changes)
100
+ git worktree remove <path>
101
+
102
+ # Force remove (discards uncommitted changes)
103
+ git worktree remove --force <path>
104
+ ```
105
+
106
+ **Safety notes:**
107
+ - Without `--force`, refuses to remove worktrees with modified or untracked files
108
+ - Does NOT delete the branch — use `git branch -d <branch>` separately
109
+ - The main worktree (the original checkout) cannot be removed
110
+
111
+ ---
112
+
113
+ ## `git worktree prune`
114
+
115
+ Clean up stale worktree administrative data. Run this when a worktree directory was deleted manually without using `git worktree remove`.
116
+
117
+ ```bash
118
+ # Prune stale references
119
+ git worktree prune
120
+
121
+ # Dry run — show what would be pruned
122
+ git worktree prune --dry-run
123
+
124
+ # Verbose — show details
125
+ git worktree prune --verbose
126
+ ```
127
+
128
+ **When to use:**
129
+ - After manually deleting a worktree directory (e.g., `rm -rf`)
130
+ - When `git worktree list` shows a worktree that no longer exists on disk
131
+ - During routine repository maintenance
132
+
133
+ ---
134
+
135
+ ## `git worktree move`
136
+
137
+ Relocate an existing worktree to a new path.
138
+
139
+ ```bash
140
+ git worktree move <old-path> <new-path>
141
+
142
+ # Force move (even if locked)
143
+ git worktree move --force <old-path> <new-path>
144
+ ```
145
+
146
+ **Notes:**
147
+ - The main worktree cannot be moved
148
+ - Updates the `.git` file in the worktree and the metadata in the main repo
149
+ - Locked worktrees require `--force`
150
+
151
+ ---
152
+
153
+ ## `git worktree lock` / `unlock`
154
+
155
+ Prevent a worktree from being pruned (useful for worktrees on removable media or network shares).
156
+
157
+ ```bash
158
+ # Lock with reason
159
+ git worktree lock --reason "on USB drive" <path>
160
+
161
+ # Unlock
162
+ git worktree unlock <path>
163
+ ```
164
+
165
+ ---
166
+
167
+ ## Worktree `.git` File Anatomy
168
+
169
+ The main repository has a `.git` **directory**. Each worktree has a `.git` **file** (not directory) containing a pointer:
170
+
171
+ ```text
172
+ gitdir: /workspaces/projects/CodeForge/.git/worktrees/feature-a
173
+ ```
174
+
175
+ This pointer tells git where the worktree metadata is stored within the main repository's `.git/worktrees/` directory. The metadata includes:
176
+ - `HEAD` — current commit reference
177
+ - `commondir` — path back to the shared `.git` directory
178
+ - `gitdir` — path to the worktree's working directory
179
+
180
+ **Detection pattern:** To check if a directory is a worktree (not a standalone repo):
181
+ ```bash
182
+ [ -f "$dir/.git" ] && grep -q "gitdir:" "$dir/.git"
183
+ ```
184
+
185
+ ---
186
+
187
+ ## Troubleshooting
188
+
189
+ ### "fatal: '<branch>' is already checked out"
190
+
191
+ A branch can only be checked out in one worktree at a time.
192
+
193
+ **Fix:** Use a different branch name, or remove the worktree that has it checked out:
194
+ ```bash
195
+ git worktree list # find which worktree has the branch
196
+ git worktree remove <path> # remove it
197
+ ```
198
+
199
+ ### "fatal: '<path>' is a missing but locked worktree"
200
+
201
+ The worktree directory was deleted but the lock prevents pruning.
202
+
203
+ **Fix:**
204
+ ```bash
205
+ git worktree unlock <path>
206
+ git worktree prune
207
+ ```
208
+
209
+ ### Stale worktree references after directory deletion
210
+
211
+ `git worktree list` shows worktrees that no longer exist on disk.
212
+
213
+ **Fix:**
214
+ ```bash
215
+ git worktree prune --verbose
216
+ ```
217
+
218
+ ### Worktree not detected by `setup-projects.sh`
219
+
220
+ CodeForge auto-detection scans `.worktrees/` directories. Ensure:
221
+ 1. The worktree is inside a `.worktrees/` directory
222
+ 2. The worktree has a `.git` file with `gitdir:` (not a standalone repo)
223
+ 3. Run `check-setup` to re-trigger project detection
224
+
225
+ ### Shared state issues between worktrees
226
+
227
+ Worktrees share:
228
+ - The `.git` database (commits, branches, refs, stash)
229
+ - Git configuration (`.git/config`)
230
+ - Hooks (`.git/hooks/`)
231
+
232
+ Worktrees do NOT share:
233
+ - Working tree files
234
+ - Index (staging area)
235
+ - `node_modules/`, `.venv/`, `target/` (dependency directories)
236
+ - `.env` files (unless `.worktreeinclude` copies them)
237
+
238
+ If one worktree's operations seem to affect another, check for shared state leaks through the `.git` database (e.g., `git stash` is shared across all worktrees).
@@ -0,0 +1,228 @@
1
+ # Parallel Workflow Patterns
2
+
3
+ Worktree usage patterns for multi-context development, agent orchestration, and lifecycle customization.
4
+
5
+ ---
6
+
7
+ ## Pattern 1: Feature + Review
8
+
9
+ Work on a feature in one worktree while reviewing a PR in another.
10
+
11
+ **Setup:**
12
+ ```bash
13
+ # Main checkout: feature work
14
+ # New worktree: PR review
15
+ git worktree add /workspaces/projects/.worktrees/review-pr-123 -b review/pr-123
16
+ cd /workspaces/projects/.worktrees/review-pr-123
17
+ git fetch origin pull/123/head:review/pr-123
18
+ git checkout review/pr-123
19
+ ```
20
+
21
+ **Workflow:**
22
+ 1. Continue feature work in the main checkout
23
+ 2. Switch to the review worktree to read, test, and comment on the PR
24
+ 3. No stashing, no context loss
25
+ 4. Remove review worktree after PR is merged
26
+
27
+ **When to use:** Long-running feature work that cannot be interrupted, combined with review responsibilities.
28
+
29
+ ---
30
+
31
+ ## Pattern 2: Safe Experimentation
32
+
33
+ Try a risky refactor or architectural change without affecting the working checkout.
34
+
35
+ **Setup:**
36
+ ```bash
37
+ claude --worktree spike-new-architecture
38
+ # or
39
+ EnterWorktree: spike-new-architecture
40
+ ```
41
+
42
+ **Workflow:**
43
+ 1. Experiment freely in the worktree — break things, try approaches
44
+ 2. If the experiment succeeds: commit, create PR
45
+ 3. If it fails: exit the session → Claude auto-removes the worktree (no changes kept)
46
+ 4. Main checkout is untouched regardless of outcome
47
+
48
+ **When to use:** Evaluating whether an approach works before committing to it. Especially useful for refactors that touch many files.
49
+
50
+ ---
51
+
52
+ ## Pattern 3: Agent Swarm
53
+
54
+ Multiple Claude Code sessions working in parallel, each in their own worktree.
55
+
56
+ **Setup (manual):**
57
+ ```bash
58
+ # Terminal 1
59
+ claude --worktree feature-auth --tmux
60
+
61
+ # Terminal 2
62
+ claude --worktree feature-search --tmux
63
+
64
+ # Terminal 3
65
+ claude --worktree fix-tests --tmux
66
+ ```
67
+
68
+ **Setup (via agent teams):**
69
+ Agents with `isolation: worktree` in their frontmatter (refactorer, test-writer, migrator, doc-writer) automatically get worktrees when spawned via the `Task` tool. The lead agent coordinates, and each teammate operates in its own isolated copy.
70
+
71
+ **Workflow:**
72
+ 1. Each agent/session works on independent files
73
+ 2. Changes stay isolated until explicitly merged
74
+ 3. Reduced conflict risk when file ownership is respected
75
+ 4. After each session completes, review changes via PR
76
+
77
+ **When to use:** Large tasks that decompose into independent workstreams. Effective for feature builds, migrations, or test suites where each agent owns a different set of files.
78
+
79
+ **File ownership rule:** Assign each parallel session/agent to a distinct set of files. Two agents editing the same file causes merge conflicts that are difficult to resolve.
80
+
81
+ ---
82
+
83
+ ## Pattern 4: Hotfix While Mid-Feature
84
+
85
+ An urgent production bug arrives while deep in unfinished feature work.
86
+
87
+ **Without worktrees:**
88
+ ```bash
89
+ git stash # hope you remember what's stashed
90
+ git checkout main
91
+ # fix the bug
92
+ git checkout feature-branch
93
+ git stash pop # hope there are no conflicts
94
+ ```
95
+
96
+ **With worktrees:**
97
+ ```bash
98
+ claude --worktree hotfix-critical-bug
99
+ # fix the bug in the worktree, commit, create PR
100
+ # exit → worktree cleaned up
101
+ # continue feature work — never interrupted
102
+ ```
103
+
104
+ **When to use:** Anytime urgent work arrives while mid-task. The worktree avoids the stash-switch-pop dance entirely.
105
+
106
+ ---
107
+
108
+ ## Pattern 5: Long-Running Migration
109
+
110
+ Incremental migration work spread across multiple sessions.
111
+
112
+ **Setup:**
113
+ ```bash
114
+ git worktree add /workspaces/projects/.worktrees/migrate-v2 -b migrate/v2-upgrade
115
+ ```
116
+
117
+ **Workflow:**
118
+ 1. Work on the migration across multiple Claude sessions using `claude --resume`
119
+ 2. The worktree persists between sessions (not auto-cleaned because it has changes)
120
+ 3. Make incremental commits as milestones are reached
121
+ 4. When migration is complete, create PR from the worktree branch
122
+ 5. Clean up after merge
123
+
124
+ **When to use:** Multi-day migrations where the work cannot be completed in a single session. Keep the worktree alive until the migration PR is merged.
125
+
126
+ ---
127
+
128
+ ## Anti-Patterns
129
+
130
+ ### Too Many Worktrees
131
+
132
+ **Problem:** Five or more active worktrees with partially-complete work scattered across them.
133
+
134
+ **Consequence:** Cognitive overhead of tracking what's where. Dependency directories (`node_modules/`, `.venv/`) duplicated across worktrees consume disk space.
135
+
136
+ **Guideline:** Limit to 2-3 active worktrees. Finish and clean up before starting new ones.
137
+
138
+ ### Forgetting Cleanup
139
+
140
+ **Problem:** Worktrees accumulate after sessions end. `git worktree list` shows stale entries.
141
+
142
+ **Consequence:** Branch namespace pollution, stale references, wasted disk space.
143
+
144
+ **Guideline:** Clean up worktrees as part of completing a task. Run `git worktree list` periodically. Use `git worktree prune` for stale references.
145
+
146
+ ### Shared State Leaks
147
+
148
+ **Problem:** Operations in one worktree unexpectedly affect another.
149
+
150
+ **Examples:**
151
+ - `git stash` — the stash is shared across all worktrees
152
+ - `git gc` — can repack objects used by other worktrees
153
+ - `.git/config` changes — affect all worktrees
154
+ - Global hooks — run in all worktrees
155
+
156
+ **Guideline:** Avoid `git stash` in worktree workflows (use commits instead). Be cautious with global git config changes.
157
+
158
+ ### Editing the Same File in Multiple Worktrees
159
+
160
+ **Problem:** Two worktrees modify the same file independently.
161
+
162
+ **Consequence:** Merge conflict when integrating changes, requiring manual resolution.
163
+
164
+ **Guideline:** Assign file ownership. Each worktree/agent edits a distinct set of files. If overlap is unavoidable, coordinate explicitly before merging.
165
+
166
+ ---
167
+
168
+ ## Worktree Lifecycle Hooks
169
+
170
+ Claude Code provides `WorktreeCreate` and `WorktreeRemove` hooks for customizing worktree lifecycle behavior.
171
+
172
+ ### WorktreeCreate Hook
173
+
174
+ Fires when a worktree is being created via `--worktree` or `isolation: "worktree"`. **Replaces** the default git worktree behavior entirely.
175
+
176
+ **Input:**
177
+ ```json
178
+ {
179
+ "session_id": "abc123",
180
+ "cwd": "/workspaces/projects/CodeForge",
181
+ "hook_event_name": "WorktreeCreate",
182
+ "name": "feature-auth"
183
+ }
184
+ ```
185
+
186
+ **Output:** Print the absolute path to the created worktree directory on stdout.
187
+
188
+ **Use cases:**
189
+ - Custom directory layout (override the default `.claude/worktrees/` path)
190
+ - Non-git VCS (SVN, Mercurial) worktree creation
191
+ - Post-creation setup (install dependencies, copy config files)
192
+
193
+ ### WorktreeRemove Hook
194
+
195
+ Fires when a worktree is being removed (session exit or subagent finish). Cleanup counterpart to WorktreeCreate.
196
+
197
+ **Input:**
198
+ ```json
199
+ {
200
+ "session_id": "abc123",
201
+ "hook_event_name": "WorktreeRemove",
202
+ "worktree_path": "/workspaces/projects/CodeForge/.claude/worktrees/feature-auth"
203
+ }
204
+ ```
205
+
206
+ **Use cases:**
207
+ - Custom cleanup (remove dependency directories, revoke temporary credentials)
208
+ - Non-git VCS cleanup
209
+ - Logging or notification on worktree removal
210
+
211
+ **Configuration:** Hooks are defined in `.claude/settings.json` or `.claude/settings.local.json`:
212
+
213
+ ```json
214
+ {
215
+ "hooks": {
216
+ "WorktreeCreate": [
217
+ {
218
+ "hooks": [
219
+ {
220
+ "type": "command",
221
+ "command": "bash /path/to/create-worktree.sh"
222
+ }
223
+ ]
224
+ }
225
+ ]
226
+ }
227
+ }
228
+ ```
@@ -71,7 +71,7 @@ def fetch_ticket(number: int) -> str | None:
71
71
 
72
72
  try:
73
73
  data = json.loads(result.stdout)
74
- except (json.JSONDecodeError, ValueError):
74
+ except json.JSONDecodeError:
75
75
  return None
76
76
 
77
77
  title = data.get("title", "(no title)")
@@ -103,7 +103,7 @@ def main():
103
103
 
104
104
  try:
105
105
  data = json.loads(raw)
106
- except (json.JSONDecodeError, ValueError):
106
+ except json.JSONDecodeError:
107
107
  sys.exit(0)
108
108
 
109
109
  prompt = data.get("prompt", "")