Skip to content

Commit 2cd4673

Browse files
Yassinelloclaude
andcommitted
feat: Add automatic context detection for worktree commands (v0.4.4)
Major enhancement: Run /ship, /debugging, and /hotfix directly from worktree directories - no more orchestration from Main required! New Features: - Automatic context detection script (.claude/scripts/context-detection.sh) - /ship auto-detects worktree context (no --worktree flag needed) - /debugging auto-detects worktree context - /hotfix works seamlessly from Main or worktree - Stay in worktree window entire workflow Benefits: - No more directory switching between Main and worktree - Natural two-window workflow (Main for PRDs, Worktree for fixes) - 100% backward compatible with v0.4.3 workflows - Parallel work without interference Documentation: - Updated all command docs with context detection sections - New workflow examples showing worktree-first approach - Detailed migration guide in CHANGELOG-v0.4.4.md 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 6dab137 commit 2cd4673

File tree

7 files changed

+857
-30
lines changed

7 files changed

+857
-30
lines changed

.claude/commands/debugging.md

Lines changed: 131 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name: debugging
33
description: Structured debugging session with team knowledge capture
44
category: Development Tools
5-
version: 0.4.3
5+
version: 0.4.4
66
---
77

88
# Debugging Command
@@ -17,18 +17,45 @@ Transform chaotic debugging into efficient investigation with:
1717
- Hypothesis-driven testing
1818
- Team knowledge documentation
1919

20-
**NEW in v0.4.3**: Support for worktree isolation with `--worktree` flag for debugging sessions requiring code modifications.
20+
**NEW in v0.4.4**: Automatic context detection - run from Main OR from worktree directly!
21+
**v0.4.3**: Support for worktree isolation with `--worktree` flag for debugging sessions requiring code modifications.
22+
23+
## Context Detection (Auto)
24+
25+
The `/debugging` command **automatically detects** where you run it from:
26+
27+
### From Main Repository
28+
```bash
29+
# Working directory: ~/Documents/watchora
30+
$ /debugging "Check API timeout"
31+
→ Behavior: Read-only investigation on Main (default)
32+
→ Optional: Add --worktree for code modifications
33+
```
34+
35+
### From Debug Worktree
36+
```bash
37+
# Working directory: ~/Documents/watchora/worktrees/debug
38+
$ /debugging "Check API timeout"
39+
→ Behavior: Automatically uses worktree (no --worktree needed!)
40+
→ Syncs, locks, creates branch, works in current directory
41+
```
42+
43+
**Key Point**: If you have a dedicated Cursor window open on `worktrees/debug/`, you can use `/debugging` directly from there!
2144

2245
## Usage
2346

2447
```bash
25-
# Default: Investigate on Main (read-only, quick)
48+
# From Main: Investigate on Main (read-only, quick)
2649
/debugging "Check why API returns 500"
2750

28-
# With worktree isolation (modifications needed)
51+
# From Main: With worktree isolation (modifications needed)
2952
/debugging "Memory leak in WebSocket handler" --worktree
3053

31-
# Manage active session
54+
# From Worktree: Auto-detects worktree context
55+
cd worktrees/debug/
56+
/debugging "Memory leak issue" # Automatically uses worktree!
57+
58+
# Manage active session (works from anywhere)
3259
/debugging --resolve # Complete and document
3360
/debugging --abort # Cancel session
3461
/debugging --status # Show current status
@@ -135,7 +162,7 @@ Solution: Updated production config (no code changes)
135162
Session closed.
136163
```
137164
138-
## Workflow: With Worktree
165+
## Workflow: With Worktree (from Main)
139166
140167
### Step 1: Start Session in Worktree
141168
@@ -209,6 +236,82 @@ Choose: 1
209236
↩️ Returned to Main
210237
```
211238
239+
## Workflow: From Worktree Directly (NEW in v0.4.4)
240+
241+
### Setup: Open Cursor Window on Worktree
242+
243+
```bash
244+
# One-time setup: Open dedicated Cursor window
245+
cd ~/Documents/watchora/worktrees/debug/
246+
code . # Opens Cursor in worktree directory
247+
```
248+
249+
### Step 1: Start Session (from Worktree)
250+
251+
```bash
252+
# You're already in worktrees/debug/
253+
$ pwd
254+
~/Documents/watchora/worktrees/debug
255+
256+
# Run /debugging directly - no --worktree flag needed!
257+
$ /debugging "Memory leak in WebSocket handler"
258+
259+
🔍 Detected: Running from worktree debug/
260+
🎯 Auto-enabling worktree mode
261+
262+
# AUTO-SYNC (Intelligent)
263+
🔄 Checking sync status...
264+
✅ Synced with main (or auto-sync if needed)
265+
266+
# START SESSION
267+
✅ Started in current directory
268+
📝 Branch: debug/memory-leak-websocket
269+
📄 Session: .prds/debug-sessions/2025-01-14-memory-leak-websocket.md
270+
🔒 Locked worktree (one session at a time)
271+
272+
💡 Working in worktree - full debugging power!
273+
```
274+
275+
### Step 2: Investigation (Same Directory)
276+
277+
You work in the **same directory** where you launched `/debugging`:
278+
- Already in `worktrees/debug/`
279+
- Add debug logging
280+
- Reproduce bugs
281+
- Test hypotheses
282+
- All your tools work normally
283+
284+
### Step 3: Resolve (from Worktree)
285+
286+
```bash
287+
# Still in worktrees/debug/
288+
$ /debugging --resolve
289+
290+
💬 Resolution status?
291+
1. Resolved with fix → Create PR
292+
2. Resolved without fix → Document only
293+
3. Workaround → Document + TODO
294+
4. Not resolved → Save state
295+
296+
Choose: 1
297+
298+
# Fix found - create PR
299+
✅ Committed fix
300+
📤 PR #237: fix: Memory leak in WebSocket close handler
301+
📝 Updated session doc
302+
303+
# AUTO-CLEANUP
304+
🔄 Returning to parking branch...
305+
🧹 Deleted branch debug/memory-leak-websocket
306+
🔄 Syncing with main...
307+
✅ Worktree ready for next session
308+
🔓 Unlocked worktree
309+
310+
📍 Still in: worktrees/debug/ (ready for next session)
311+
```
312+
313+
**Advantage**: You stay in the same Cursor window the entire time!
314+
212315
## Collision Handling
213316
214317
**One session at a time** in debug worktree:
@@ -495,7 +598,7 @@ $ /debugging --resolve
495598
# Documented, session closed
496599
```
497600
498-
### Example 2: Investigation Needs Code Changes
601+
### Example 2: Investigation Needs Code Changes (from Main)
499602
500603
```bash
501604
$ /debugging "Performance degradation" --worktree
@@ -508,7 +611,21 @@ $ /debugging --resolve
508611
# PR created, session documented
509612
```
510613
511-
### Example 3: Migration to Worktree
614+
### Example 3: Investigation from Worktree - NEW!
615+
616+
```bash
617+
# Cursor window open on worktrees/debug/
618+
$ pwd
619+
~/Documents/watchora/worktrees/debug
620+
621+
$ /debugging "Performance degradation"
622+
623+
# Auto-detects worktree context
624+
# No --worktree flag needed
625+
# Works in current directory
626+
```
627+
628+
### Example 4: Migration to Worktree
512629
513630
```bash
514631
$ /debugging "Bug in production"
@@ -522,7 +639,7 @@ $ /debugging --to-worktree
522639
# Testing fix in isolation
523640
```
524641
525-
### Example 4: Long Investigation with Pause
642+
### Example 5: Long Investigation with Pause
526643
527644
```bash
528645
$ /debugging "Complex race condition" --worktree
@@ -574,6 +691,8 @@ Works seamlessly with:
574691
575692
---
576693
577-
**Version**: 0.4.3
578-
**Plugin**: claude-prd-workflow v0.4.3
579-
**Changes**: Added worktree support, intelligent sync, session management, collision handling
694+
**Version**: 0.4.4
695+
**Plugin**: claude-prd-workflow v0.4.4
696+
**Changes**:
697+
- v0.4.4: Added automatic context detection - run from Main OR worktree directly
698+
- v0.4.3: Added worktree support, intelligent sync, session management, collision handling

.claude/commands/hotfix.md

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,37 @@
22
name: hotfix
33
description: Quick fix with worktree isolation (alias for /ship --worktree)
44
category: Git Workflow
5-
version: 0.4.3
5+
version: 0.4.4
66
---
77

88
# Hotfix Command
99

1010
Alias for `/ship --worktree` - always uses worktree isolation for quick fixes.
1111

12+
**NEW in v0.4.4**: Works seamlessly from Main OR from worktree directly thanks to automatic context detection!
13+
1214
## Purpose
1315

1416
For developers who prefer worktree isolation by default:
1517
- Shorter to type than `/ship --worktree`
1618
- Always works in dedicated worktree
1719
- Same workflow as `/ship` but with guaranteed isolation
20+
- Can be launched from Main OR from worktree directly
1821

1922
## Usage
2023

2124
```bash
22-
# Basic usage
25+
# From Main: Basic usage
2326
/hotfix "Fix login button alignment"
2427

2528
# Equivalent to:
2629
/ship "Fix login button alignment" --worktree
2730

28-
# All /ship options work
31+
# From Worktree: Auto-detects context (NEW!)
32+
cd worktrees/hotfix/
33+
/hotfix "Fix login button" # Works seamlessly!
34+
35+
# All /ship options work (from anywhere)
2936
/hotfix --complete # Finish fix
3037
/hotfix --abort # Cancel fix
3138
/hotfix --status # Check status
@@ -116,7 +123,21 @@ $ /hotfix --status
116123
⏱️ Started: 25 minutes ago
117124
```
118125

119-
### Example 3: Collision
126+
### Example 3: From Worktree Directly (NEW!)
127+
128+
```bash
129+
# Cursor window open on worktrees/hotfix/
130+
$ pwd
131+
~/Documents/watchora/worktrees/hotfix
132+
133+
$ /hotfix "Refactor API endpoints"
134+
135+
# Auto-detects worktree
136+
# Works in current directory
137+
# No --worktree flag needed
138+
```
139+
140+
### Example 4: Collision
120141

121142
```bash
122143
# Fix already in progress
@@ -144,6 +165,8 @@ $ /ship "Another fix"
144165

145166
---
146167

147-
**Version**: 0.4.3
148-
**Plugin**: claude-prd-workflow v0.4.3
168+
**Version**: 0.4.4
169+
**Plugin**: claude-prd-workflow v0.4.4
149170
**Alias for**: `/ship --worktree`
171+
**Changes**:
172+
- v0.4.4: Works from Main OR worktree directly (automatic context detection)

0 commit comments

Comments
 (0)