Execute a development task in a completely isolated git worktree environment.
From pwnpx claudepluginhub ken2403/claude-paralell-dev-plugin --plugin pwExecute a development task in a completely isolated git worktree environment. This command runs autonomously until PR creation without requiring user approval.
$ARGUMENTS
NEVER modify files in the parent directory
NEVER modify the default branch (main/master/develop)
NEVER modify files outside the worktree
worktrees/<job-name>/NEVER delete or force-push existing branches
git push --force on existing branchesNEVER delete the worktree before the PR is merged
/pw:wt-cleanBefore ANY file write/edit operation, verify the target path starts with your worktree directory.
If you are about to modify a file outside worktrees/<job-name>/, STOP IMMEDIATELY.
#!/bin/bash
set -e
# Plugin discovery
_PD=""; for _d in .claude-paralell-dev-plugin ../.claude-paralell-dev-plugin ../../.claude-paralell-dev-plugin "$HOME"/.claude/plugins/cache/claude-parallel-dev-plugin/pw/*; do [ -d "$_d/scripts" ] && _PD="$_d" && break; done 2>/dev/null; [ -n "${PW_PLUGIN_DIR:-}" ] && _PD="$PW_PLUGIN_DIR"
# Run shared worktree setup
"$_PD/scripts/setup-worktree.sh" "$ARGUMENTS" "Worktree Job"
# Load metadata from Phase 1
if [ -z "$WORKTREE_PATH" ]; then
# Try to find wtj-meta in any worktree
for meta in worktrees/*/.wtj-meta; do
if [ -f "$meta" ]; then
source "$meta"
break
fi
done
fi
if [ -z "$WORKTREE_PATH" ] || [ ! -d "$WORKTREE_PATH" ]; then
echo "ERROR: WORKTREE_PATH not set or directory does not exist"
echo "This script must be run after Phase 1 setup"
exit 1
fi
# Source metadata file for all variables
source "$WORKTREE_PATH/.wtj-meta"
cd "$WORKTREE_PATH"
if [ -n "$ISSUE_NUM" ]; then
echo "=== Issue #${ISSUE_NUM} Details ==="
gh issue view "$ISSUE_NUM" 2>/dev/null || echo "Could not fetch issue details"
fi
# Load metadata from Phase 1
if [ -z "$WORKTREE_PATH" ]; then
for meta in worktrees/*/.wtj-meta; do
[ -f "$meta" ] && source "$meta" && break
done
fi
[ -z "$WORKTREE_PATH" ] || [ ! -d "$WORKTREE_PATH" ] && echo "ERROR: Run Phase 1 first" && exit 1
source "$WORKTREE_PATH/.wtj-meta"
cd "$WORKTREE_PATH"
echo "=== Project Configuration ==="
if [ -f "CLAUDE.md" ]; then
echo "--- CLAUDE.md ---"
head -100 CLAUDE.md
fi
if [ -f "README.md" ]; then
echo ""
echo "--- README.md (excerpt) ---"
head -50 README.md
fi
MANDATORY: Use explorer subagent to understand the codebase before implementation.
Use explorer subagent to:
1. Understand the project structure
2. Find files related to the task
3. Identify existing patterns and conventions
For complex tasks, also use analyzer:
Use analyzer subagent to understand architecture and dependencies if needed
NOTE: This phase runs WITHOUT user approval. Make careful, incremental changes.
Before writing code:
If the implementation plan involves modifying or creating 3 or more files, use simple-implementer subagents for parallel execution:
Group by directory or functional area. Each group should have:
For each file in each group, describe exactly what to create or modify:
Before launching subagents, verify your instructions:
Fix any issues in the instructions before dispatching.
Launch multiple simple-implementer subagents in parallel using the Task tool. For each group:
Use simple-implementer subagent to implement changes in the following files:
Working directory: [WORKTREE_PATH]
Files and changes:
- `[file1]`: [Detailed description ā function signatures, logic, patterns to follow from existing_file:line]
- `[file2]`: [Detailed description ā must match interface defined in file1]
Context:
- This is part of a larger task: [task description]
- Related files (read-only reference): [list of files that provide context]
- Code patterns to follow: See [existing file:line] for style reference
After implementation:
1. Verify each file is syntactically correct
2. Stage changed files: `git add [file]`
IMPORTANT:
- Only modify the files listed above
- Follow existing code style exactly
- Do NOT run git commit or git push
After all subagents complete:
git diff for all changed files to verify correctnessIf only 1-2 files need modification, implement directly without subagent overhead.
Apply Quality Skills:
/pw:code-quality standards/pw:security-review standards for sensitive codeBefore EVERY file write or edit, verify:
/pw:precheck uses git diff BASE...HEAD to review committed changes. Create an interim commit so precheck can analyze the diff.
# Load metadata from Phase 1
if [ -z "$WORKTREE_PATH" ]; then
for meta in worktrees/*/.wtj-meta; do
[ -f "$meta" ] && source "$meta" && break
done
fi
[ -z "$WORKTREE_PATH" ] || [ ! -d "$WORKTREE_PATH" ] && echo "ERROR: Run Phase 1 first" && exit 1
source "$WORKTREE_PATH/.wtj-meta"
cd "$WORKTREE_PATH"
echo "=== Creating Interim Commit for Precheck ==="
git add .
if ! git diff --cached --quiet; then
git commit -m "wip: ${TASK_DESCRIPTION}"
echo "Interim commit created"
else
echo "No changes to commit"
fi
Use the Skill tool to invoke /pw:precheck HEAD. This runs comprehensive checks including:
If /pw:precheck reports any issues:
git add . && git commit --amend --no-edit/pw:precheck HEAD via the Skill tool# Load metadata from Phase 1
if [ -z "$WORKTREE_PATH" ]; then
for meta in worktrees/*/.wtj-meta; do
[ -f "$meta" ] && source "$meta" && break
done
fi
[ -z "$WORKTREE_PATH" ] || [ ! -d "$WORKTREE_PATH" ] && echo "ERROR: Run Phase 1 first" && exit 1
source "$WORKTREE_PATH/.wtj-meta"
cd "$WORKTREE_PATH"
echo "=== Final Safety Check ==="
CURRENT_DIR=$(pwd)
CURRENT_BRANCH=$(git branch --show-current)
echo "Current directory: $CURRENT_DIR"
echo "Current branch: $CURRENT_BRANCH"
# Verify in worktree
if [[ ! "$CURRENT_DIR" == *"/worktrees/"* ]]; then
echo "FATAL ERROR: Not in worktree directory!"
exit 1
fi
# Verify NOT on protected branch
if [ "$CURRENT_BRANCH" = "main" ] || [ "$CURRENT_BRANCH" = "master" ] || [ "$CURRENT_BRANCH" = "develop" ]; then
echo "FATAL ERROR: On protected branch '$CURRENT_BRANCH'! Aborting."
exit 1
fi
echo ""
echo "=== Finalizing commit ==="
# Stage any remaining changes (from precheck fix iterations)
git add .
if ! git diff --cached --quiet; then
git commit --amend --no-edit
fi
# Amend interim commit with proper message
COMMIT_TITLE="${BRANCH_PREFIX}: ${TASK_DESCRIPTION}"
git commit --amend -m "${COMMIT_TITLE}
Automated implementation by wt-j
š¤ Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>"
echo "Commit finalized: ${COMMIT_TITLE}"
echo ""
echo "=== Pushing branch ==="
git push -u origin "$CURRENT_BRANCH"
echo ""
echo "Branch pushed successfully"
# Load metadata from Phase 1
if [ -z "$WORKTREE_PATH" ]; then
for meta in worktrees/*/.wtj-meta; do
[ -f "$meta" ] && source "$meta" && break
done
fi
[ -z "$WORKTREE_PATH" ] || [ ! -d "$WORKTREE_PATH" ] && echo "ERROR: Run Phase 1 first" && exit 1
source "$WORKTREE_PATH/.wtj-meta"
cd "$WORKTREE_PATH"
# Variables are now loaded from metadata file:
# - BRANCH_PREFIX, TASK_DESCRIPTION, ISSUE_NUM, etc.
CLOSES_LINE=""
if [ -n "$ISSUE_NUM" ]; then
CLOSES_LINE="Closes #${ISSUE_NUM}"
fi
# Generate PR title from task description (variables from metadata)
PR_TITLE="${BRANCH_PREFIX}: ${TASK_DESCRIPTION}"
echo "=== Creating Pull Request ==="
echo "Title: ${PR_TITLE}"
gh pr create --title "${PR_TITLE}" --body "## Summary
${TASK_DESCRIPTION}
Automated implementation by wt-j.
## Changes
See commit history for details.
## Testing
- [ ] All existing tests pass
- [ ] New functionality tested
## Related Issues
${CLOSES_LINE:-N/A}
---
š¤ Generated autonomously with [Claude Code](https://claude.com/claude-code)
**Worktree Job**: This PR was created in an isolated worktree environment.
To clean up after merge: \`/pw:wt-clean $(basename $(pwd))\`
"
echo ""
echo "PR created successfully"
# Worktree Job Report
## Job Information
- **Job Name**: [job-name]
- **Branch**: [branch-name]
- **Worktree Path**: worktrees/[job-name]/
- **Base Branch**: [base-branch]
## Task
[Original task description or issue reference]
## Implementation Summary
[What was implemented]
## Files Changed
- `path/to/file1` - [Description]
- `path/to/file2` - [Description]
## Verification Results
- [ ] Lint: PASS/FAIL
- [ ] Type Check: PASS/FAIL
- [ ] Tests: PASS/FAIL
- [ ] Build: PASS/FAIL
## Pull Request
- **PR URL**: [URL]
- **PR Number**: #[number]
- **Status**: Ready for Review
## Cleanup Instructions
After PR is merged, run:
```bash
/pw:wt-clean [job-name]
WARNING: Do NOT manually delete the worktree before merging!
[Any additional notes, decisions made, or issues encountered]
---
## Error Handling
If ANY error occurs:
1. **DO NOT** attempt to fix by modifying files outside worktree
2. **DO NOT** switch to base branch
3. **DO NOT** delete the worktree
4. Document the error clearly in the output
5. Leave the worktree in its current state for manual inspection
6. Report what was attempted and what failed
```bash
# On error, show diagnostic info
echo "=== Error Diagnostic ==="
echo "Working directory: $(pwd)"
echo "Branch: $(git branch --show-current 2>/dev/null || echo 'unknown')"
echo "Git status:"
git status --short 2>/dev/null || echo "Not in git repo"
echo ""
echo "Recent commits:"
git log --oneline -5 2>/dev/null || echo "No commits"