Skip to content

Commit bd93811

Browse files
author
Nick Sullivan
committed
📋 Refactor git-worktree-task workflow for clarity and practicality
Restructured guide to emphasize why worktrees matter and practical setup details. Added port isolation section to prevent dev server conflicts. Simplified verbose sections and removed redundant bash examples. Tightened language throughout for better readability.
1 parent 9f0e63f commit bd93811

File tree

1 file changed

+24
-46
lines changed

1 file changed

+24
-46
lines changed

.cursor/rules/git-worktree-task.mdc

Lines changed: 24 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,96 +6,74 @@ alwaysApply: false
66
# Git Worktree Task Workflow
77

88
<objective>
9-
Deliver a pull request that passes all checks and merges without back-and-forth. Work in isolated git worktrees to keep the main directory clean and allow context switching.
9+
Deliver a pull request that passes all checks and merges without back-and-forth. Work in isolated git worktrees to keep the main directory clean and allow context switching between tasks.
1010
</objective>
1111

12-
<workspace-setup>
13-
Create git worktree in .gitworktrees/ directory:
14-
15-
```bash
16-
mkdir -p .gitworktrees
17-
git worktree add -b feature/task-name .gitworktrees/task-name main
18-
cd .gitworktrees/task-name
19-
```
12+
<why-worktrees>
13+
Worktrees isolate task branches in separate directories. Your main repo stays on main for quick reference. Your task directory is completely separate. You can switch between them instantly. When done, the worktree disappears cleanly. This is faster and cleaner than stashing or branch switching.
14+
</why-worktrees>
2015

16+
<workspace-setup>
17+
Create git worktree as a sibling directory (not nested inside the repo). Sibling directories avoid module resolution issues with ESLint, monorepo tools, and symlinked dependencies that break when worktrees are nested.
2118
</workspace-setup>
2219

23-
<environment-initialization>
24-
Run /setup-environment to prepare the worktree. This detects project type and sets up dependencies, code generation, and environment files.
25-
26-
If /setup-environment doesn't exist, set up manually based on project type (Node.js:
27-
`pnpm install`, Python: `pip install -r requirements.txt`, Ruby: `bundle install`).
20+
<port-isolation>
21+
Each worktree needs its own port for dev servers to avoid conflicts when running multiple tasks. Create a `.env.local` in the worktree with a unique PORT based on the task name (hash the name to a port offset from 3000, or use sequential assignment). This prevents "port already in use" errors and makes it clear which server belongs to which task.
22+
</port-isolation>
2823

29-
Copy environment files from parent directory if needed. After proper setup, all tests
30-
(unit + integration) should pass. </environment-initialization>
24+
<environment-initialization>
25+
Run /setup-environment if available, otherwise install dependencies and set up environment files manually. After proper setup, all tests (unit + integration) should pass.
26+
</environment-initialization>
3127

3228
<standards-discovery>
3329
Read all cursor rules in .cursor/rules/. If CLAUDE.md or AGENTS.md exist at project root, read those too. Every applicable rule must be followed.
3430
</standards-discovery>
3531

3632
<implementation>
37-
Write code that solves the problem following all cursor rules. Make commits along the way as logical units of work are completed. Follow git commit message guidelines in .cursor/rules/git-commit-message.mdc.
33+
Write code that solves the problem following all cursor rules. Make commits along the way as logical units of work are completed. Follow git commit message guidelines in .cursor/rules/git-commit-message.mdc if it exists.
3834
</implementation>
3935

4036
<local-validation>
41-
Run project's pre-push validation before pushing. This catches issues before CI:
42-
- Node.js: `pnpm pre-push` or check package.json scripts
43-
- Python: `pre-commit run --all-files`, `pytest`, `ruff check`, `mypy`
44-
- Ruby: `bundle exec rake test`, `bundle exec rubocop`
45-
- Go: `go test ./...`, `golangci-lint run`
46-
- Rust: `cargo test`, `cargo clippy`
47-
48-
Check .github/workflows/ to see what CI runs - run those steps locally.
49-
50-
All tests should pass after environment setup. If tests fail, it's either incomplete
51-
setup or bugs in your code. Fix before pushing. </local-validation>
37+
Run the project's pre-push validation before pushing. Check .github/workflows/ to see what CI runs and run those steps locally first. Local validation catches issues in seconds vs waiting for CI. All tests must pass before pushing.
38+
</local-validation>
5239

5340
<self-review>
5441
Invoke code reviewer agent (Rivera in .claude/agents/rivera.md if available) to review changes before pushing. Address critical issues, consider warnings seriously, evaluate suggestions for merit. Learn from feedback.
5542
</self-review>
5643

5744
<pull-request-creation>
58-
Once local validation passes and code review is addressed, push commits. Create pull request with clear description of what changed and why. Help reviewers understand context and decisions made.
45+
Push commits and create pull request with clear description of what changed and why. Help reviewers understand context and decisions made.
5946
</pull-request-creation>
6047

6148
<ci-validation>
6249
Let all CI jobs run to completion. All must pass. Green checks required before merge. If CI fails, read logs carefully, understand what broke and why, fix and push again.
6350
</ci-validation>
6451

6552
<bot-review-handling>
66-
AI code review bots will analyze the pull request. Evaluate feedback critically - you have full project context, bots don't.
53+
AI code review bots will analyze the pull request. Evaluate feedback criticallyyou have full project context, bots don't.
6754

6855
Fix valuable feedback that identifies real issues. Mark as WONTFIX with clear reasoning
6956
if feedback is incorrect, not applicable, conflicts with project standards, or would
7057
break functionality.
7158

72-
Be discerning. You are smarter than the bots. </bot-review-handling>
59+
You are smarter than the bots. Be discerning. </bot-review-handling>
7360

7461
<merge-and-cleanup>
75-
Once CI is green, bot reviews are addressed, and all checks pass, merge the PR.
76-
77-
After merge, clean up worktree:
78-
79-
```bash
80-
cd ../.. # Return to main directory
81-
git worktree remove .gitworktrees/task-name
82-
```
83-
62+
Once CI is green, bot reviews are addressed, and all checks pass, merge the PR. After merge, remove the worktree.
8463
</merge-and-cleanup>
8564

8665
<critical-success-factors>
87-
Environment setup is not optional. After creating worktree, run /setup-environment or manually install dependencies. Type errors and test failures often stem from missing code generation or dependencies.
66+
Environment setup is not optional. Type errors and test failures often stem from missing code generation or dependencies.
8867

8968
Local validation saves time. Don't push without running pre-push checks. Local tooling
9069
catches issues in seconds vs waiting for CI.
9170

9271
Bot feedback requires judgment. Bots provide suggestions, not mandates. Evaluate each
9372
piece based on your context and project standards.
9473

95-
Full test suite must pass. After setup, all tests (unit + integration) should pass. Fix
96-
setup or code before pushing.
74+
Full test suite must pass after setup. Fix setup or code before pushing.
9775

98-
Successful autonomous task means: original request completed, all automated checks pass,
99-
code follows all cursor rules, tests green, code review addressed, bot feedback
100-
evaluated intelligently, PR merges without human intervention requesting changes.
76+
Successful autonomous task: original request completed, all automated checks pass, code
77+
follows all cursor rules, tests green, code review addressed, bot feedback evaluated
78+
intelligently, PR merges without human intervention requesting changes.
10179
</critical-success-factors>

0 commit comments

Comments
 (0)