Loading...
Loading...
Use when starting any RLM requirement to set up an isolated git worktree. REQUIRED before Phase 1 - creates isolated workspace, verifies clean test baseline, and prevents main branch pollution.
npx skill4agent add doubleuuser/rlm-workflow rlm-worktreeNEVER WORK ON MAIN/MASTER BRANCH WITHOUT EXPLICIT CONSENTPhase 0: 00-worktree.md (isolated workspace setup)
↓
Phase 1: 00-requirements.md (already exists)
↓
Phase 2: 01-as-is.md# Check in priority order
ls -d .worktrees 2>/dev/null # Preferred (hidden)
ls -d worktrees 2>/dev/null # Alternative.worktreesgrep -i "worktree.*director" CLAUDE.md 2>/dev/null
grep -i "worktrees" CLAUDE.md 2>/dev/nullNo worktree directory found. Where should I create worktrees?
1. .worktrees/ (project-local, hidden - RECOMMENDED)
2. ~/.config/rlm-workflow/worktrees/<project-name>/ (global location)
Which would you prefer? (1/2).worktrees/# Check if directory is ignored (respects local, global, and system gitignore)
git check-ignore -q .worktrees 2>/dev/null || git check-ignore -q worktrees 2>/dev/null# RLM worktrees
.worktrees/git add .gitignore
git commit -m "chore: ignore RLM worktree directory"project=$(basename "$(git rev-parse --show-toplevel)")
branch_name="rlm/${run_id}"current_branch=$(git branch --show-current)
if [ "$current_branch" = "main" ] || [ "$current_branch" = "master" ]; then
# STOP - Require explicit consent
echo "WARNING: Currently on $current_branch branch."
echo "RLM Workflow requires isolated worktrees."
echo ""
read -p "Create worktree and switch to feature branch? (yes/no): " consent
if [ "$consent" != "yes" ]; then
echo "Aborted. Please run from a feature branch or consent to worktree creation."
exit 1
fi
fi# Determine full path
case $LOCATION in
.worktrees|worktrees)
path="$LOCATION/$run_id"
;;
~/.config/rlm-workflow/worktrees/*)
path="~/.config/rlm-workflow/worktrees/$project/$run_id"
;;
esac
# Create worktree with new branch
git worktree add "$path" -b "$branch_name"
cd "$path"# Node.js
if [ -f package.json ]; then
echo "Detected Node.js project"
npm install
fi
# Rust
if [ -f Cargo.toml ]; then
echo "Detected Rust project"
cargo build
fi
# Python
if [ -f requirements.txt ]; then
echo "Detected Python project (requirements.txt)"
pip install -r requirements.txt
elif [ -f pyproject.toml ]; then
echo "Detected Python project (pyproject.toml)"
poetry install || pip install -e .
fi
# Go
if [ -f go.mod ]; then
echo "Detected Go project"
go mod download
fi
# Java/Maven
if [ -f pom.xml ]; then
echo "Detected Maven project"
mvn compile -q
fi
# Java/Gradle
if [ -f build.gradle ] || [ -f build.gradle.kts ]; then
echo "Detected Gradle project"
./gradlew compileJava --quiet 2>/dev/null || gradlew compileJava --quiet 2>/dev/null
fi
# .NET
if [ -f *.csproj ] || [ -f *.sln ]; then
echo "Detected .NET project"
dotnet restore
fi# Detect test command and run
if [ -f package.json ]; then
# Check for npm test script
if grep -q '"test"' package.json; then
echo "Running npm test..."
npm test
fi
elif [ -f Cargo.toml ]; then
echo "Running cargo test..."
cargo test
elif [ -f requirements.txt ] || [ -f pyproject.toml ]; then
echo "Running pytest..."
pytest -q || python -m pytest -q
elif [ -f go.mod ]; then
echo "Running go test..."
go test ./...
elif [ -f pom.xml ]; then
echo "Running Maven tests..."
mvn test -q
elif [ -f build.gradle ] || [ -f build.gradle.kts ]; then
echo "Running Gradle tests..."
./gradlew test --quiet 2>/dev/null || gradlew test --quiet 2>/dev/null
elif [ -f *.csproj ] || [ -f *.sln ]; then
echo "Running dotnet tests..."
dotnet test --verbosity quiet
fi## Worktree Details
**Location:** `/full/path/to/.worktrees/run-id`
**Branch:** `rlm/run-id`
**Created from:** `main` (commit: abc123)
**Setup commands executed:**
- npm install
- npm test (47 passing, 0 failing)
**Baseline verified:** ✅branch=$(git branch --show-current)
if [ "$branch" = "main" ] || [ "$branch" = "master" ]; then
echo "╔════════════════════════════════════════════════════════════╗"
echo "║ ⚠️ MAIN BRANCH PROTECTION ║"
echo "╠════════════════════════════════════════════════════════════╣"
echo "║ You are currently on the $branch branch. ║"
echo "║ ║"
echo "║ RLM Workflow requires isolated worktrees to: ║"
echo "║ • Prevent accidental commits to production ║"
echo "║ • Enable parallel requirement development ║"
echo "║ • Maintain clean main branch history ║"
echo "║ ║"
echo "║ Options: ║"
echo "║ 1. Create worktree (RECOMMENDED) ║"
echo "║ 2. Switch to existing feature branch ║"
echo "║ 3. Abort and run from feature branch ║"
echo "╚════════════════════════════════════════════════════════════╝"
echo ""
# Default to worktree creation
echo "Creating worktree by default (press Ctrl+C to abort)..."
sleep 3
fi## Main Branch Work Acknowledgment
User has explicitly requested to work on main branch.
**Acknowledged risks:**
- [ ] Commits go directly to production branch
- [ ] No isolation for this requirement
- [ ] Cannot run parallel requirements
- [ ] Harder to discard if abandoned
**Consent:** User has chosen to proceed on main branch
**Reason:** [user-provided reason]
**Recorded:** [timestamp]
**Recommendation:** Use worktrees for future requirements./.codex/rlm/<run-id>/00-worktree.mdRun: `/.codex/rlm/<run-id>/`
Phase: `00 Worktree Setup`
Status: `DRAFT` | `LOCKED`
Inputs:
- Current git repository state
- User preference (for worktree location)
Outputs:
- `/.codex/rlm/<run-id>/00-worktree.md`
- Isolated worktree at `[location]`
Scope note: This document records isolated workspace setup and verifies clean test baseline.
## Directory Selection
**Convention checked:**
- [ ] `.worktrees/` exists
- [ ] `worktrees/` exists
- [ ] CLAUDE.md preference found
- [ ] User preference obtained
**Selected location:** `.worktrees/` (project-local, hidden)
## Safety Verification
**Gitignore check:**
```bash
$ git check-ignore -q .worktrees && echo "IGNORED" || echo "NOT IGNORED"
IGNOREDgit worktree add .worktrees/run-id -b rlm/run-idPreparing worktree (new branch 'rlm/run-id')
HEAD is now at abc1234 Previous commit messagerlm/run-id/full/path/to/project/.worktrees/run-idcd .worktrees/run-id
npm installadded 472 packages in 8snpm testmainrlm/run-id.worktrees/run-idYYYY-MM-DDTHH:MM:SSZ<sha256-hex>
## Integration with RLM
### Phase 0 → Phase 1 Transition
Phase 0 must be locked before proceeding:
1. Verify worktree exists and is properly configured
2. Check Phase 0 gates are PASS
3. Lock Phase 0 artifact
4. Proceed to Phase 1 (requirements already exist)
5. All subsequent phases execute in worktree context
### Worktree Context for All Phases
Once Phase 0 is complete:
- All RLM commands run from worktree directory
- Git operations target feature branch
- Main branch remains untouched
- Development is fully isolated
### Phase 6/7 (Global Updates)
When updating global artifacts:
1. Changes are made in worktree context
2. Commits go to feature branch
3. User merges feature branch to main when ready
4. DECISIONS.md and STATE.md updates are part of the merge
## Common Mistakes
### Skipping ignore verification
- **Problem:** Worktree contents get tracked, pollute git status
- **Fix:** Always use `git check-ignore` before creating project-local worktree
### Assuming directory location
- **Problem:** Creates inconsistency, violates project conventions
- **Fix:** Follow priority: existing > CLAUDE.md > ask
### Proceeding with failing tests
- **Problem:** Can't distinguish new bugs from pre-existing issues
- **Fix:** Report failures, get explicit permission to proceed
### Hardcoding setup commands
- **Problem:** Breaks on projects using different tools
- **Fix:** Auto-detect from project files (package.json, Cargo.toml, etc.)
## Red Flags
**Never:**
- Create worktree without verifying it's ignored (project-local)
- Skip baseline test verification
- Proceed with failing tests without asking
- Assume directory location when ambiguous
- Skip CLAUDE.md check
- Work on main/master without explicit consent and documentation
**Always:**
- Follow directory priority: existing > CLAUDE.md > ask
- Verify directory is ignored for project-local
- Auto-detect and run project setup
- Verify clean test baseline
- Create feature branch (rlm/run-id pattern)
- Document worktree location in Phase 0 artifact
## Quick Reference
| Situation | Action |
|-----------|--------|
| `.worktrees/` exists | Use it (verify ignored) |
| `worktrees/` exists | Use it (verify ignored) |
| Both exist | Use `.worktrees/` |
| Neither exists | Check CLAUDE.md → Ask user |
| Directory not ignored | Add to .gitignore + commit |
| Tests fail during baseline | Report failures + ask |
| On main/master branch | Create worktree (default) |
| User insists on main | Document consent, proceed with caution |
| No package.json/Cargo.toml | Skip dependency install |
## Real-World Impact
From development sessions:
- **Before worktrees:** 15% of requirements had accidental main branch commits
- **After worktrees:** 0% accidental main branch commits
- **Parallel development:** 3+ requirements can be worked simultaneously
- **Clean main branch:** Production history is clean and linear
- **Easy discard:** Abandoned requirements don't pollute main branch
## References
- **REQUIRED:** Use this skill for ALL RLM runs
- **TRIGGERS:** At start of "Implement requirement 'run-id'"
- **OUTPUT:** `00-worktree.md` artifact + isolated worktree
- **NEXT:** Continue with Phase 1 (requirements) in worktree context