chore: add worktree-isolated task list script for parallel development#821
chore: add worktree-isolated task list script for parallel development#821diegomrsantos wants to merge 7 commits intosigp:unstablefrom
Conversation
When running parallel AI coding sessions across git worktrees, the task list state is scoped to the git repository rather than the individual worktree, causing tasks to leak between sessions. This adds a wrapper script that sets CLAUDE_CODE_TASK_LIST_ID per worktree and documents the parallel development workflow in CLAUDE.md. Workaround for: anthropics/claude-code#24754
This comment was marked as outdated.
This comment was marked as outdated.
- Use path hash for unique task list IDs across same-named directories - Add claude command validation before exec - Clarify remote naming convention in CLAUDE.md
This comment was marked as outdated.
This comment was marked as outdated.
- Add sha256sum/shasum fallback for Linux/macOS compatibility - Add troubleshooting section to CLAUDE.md
|
Claude finished @diegomrsantos's task in 1m 16s —— View job Code Review Complete
SummaryThe PR successfully implements a workaround for task list isolation in git worktrees. The previous review feedback has been properly addressed, and the implementation is solid. I've identified a few minor improvements for robustness and clarity. Code Qualityscripts/claude-worktree.sh:20-27 - Cross-platform hash handling is well-implemented with proper fallback logic for both Linux ( scripts/claude-worktree.sh:32-36 - Command validation before exec is a good safety check that prevents confusing error messages. scripts/claude-worktree.sh:29 - The task list ID format Security & Robustnessscripts/claude-worktree.sh:18 - The fallback from # Current:
WORKTREE_PATH="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
# Safer alternative:
WORKTREE_PATH="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
if [ -z "${WORKTREE_PATH}" ]; then
echo "Error: Unable to determine working directory" >&2
exit 1
fiscripts/claude-worktree.sh:39 - Using scripts/claude-worktree.sh:21-23 - The hash generation uses PATH_HASH="$(printf '%s' "${WORKTREE_PATH}" | sha256sum | cut -c1-8)"DocumentationCLAUDE.md:484 - The note clarifying **Note**: Examples below use `upstream` as the remote pointing to `sigp/anchor` and `origin` as your fork, following the standard fork contribution workflow. Set up with:
```bash
git remote add upstream https://github.com/sigp/anchor.gitTestingMissing test coverage - While this is a simple script, consider adding a test that verifies:
This could be a simple bash test script or documented manual test procedure. Minor Issuesscripts/claude-worktree.sh:14 - .github/wordlist.txt - All new words are appropriate additions. The lowercase Previous Review FeedbackAll three items from the previous review have been properly addressed:
Recommendations
Overall AssessmentThis is a well-implemented workaround for a real problem. The code is clean, properly documented, and handles edge cases thoughtfully. The cross-platform hash fallback and command validation demonstrate attention to detail. The minor suggestions above would further improve robustness, but the current implementation is production-ready. |
- Validate empty worktree path after git rev-parse - Use printf instead of echo for consistent hash input - Add upstream remote setup example to docs - Add troubleshooting entry for moved worktree directories
The script now supports a 'new' subcommand that creates a worktree, fetches the base ref, and launches with an isolated task list in one command. Updated CLAUDE.md docs to reflect the simpler workflow.
|
Does this need to be committed to the repo? |
If we commit, the whole team can use it |
|
could be useful |
|
@diegomrsantos, @petarjuki7, @dknopik, we discussed briefly on anchor weekly call. i was thinking utility would be if you check out a couple branches at same time, one for feature building and the other for pr review, for example. concern is that this is kind of a work around for anthropic issue, so doesn't make as much sense to enshrine the logic in the codebase. just had the idea that we could do experiment: we can use these scripts locally if we want to do |
|
I honestly can't understand what the issue with this PR is. It's just an isolated script and a few additions to claude.md. If the team prefers to close it, please let me know, and I can try to find a way to use it locally. |
Issue Addressed
Workaround for anthropics/claude-code#24754 — Claude Code's task list (
TaskCreate/TodoWrite) leaks across git worktrees because worktrees share the same.gitdirectory.Proposed Changes
scripts/claude-worktree.sh, a script that creates worktrees and launches Claude Code with isolated task lists in one commandCLAUDE.md, including usage, cleanup, and troubleshootingUsage
Create a new worktree and launch:
Launch in an existing worktree:
The script sets
CLAUDE_CODE_TASK_LIST_IDto a unique value derived from the worktree directory name and a hash of its absolute path, ensuring each worktree gets its own task list. Works on both Linux (sha256sum) and macOS (shasum).Additional Info
This is a lightweight workaround until Claude Code provides native worktree-level task isolation. The script requires no configuration and produces human-readable IDs with guaranteed uniqueness.