Agent skill
implement-worktree-no-merge
Implement a plan in an isolated git worktree without merging, testing, or cleaning up. For MCP orchestration use — the orchestrator handles testing and merging separately.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/implement-worktree-no-merge
SKILL.md
Implement in Worktree (No Merge) Skill
Implement a provided plan in an isolated git worktree branched from the current branch. The worktree is left intact for the orchestrator to test and merge separately.
When to Use
- MCP orchestrator calls this via
run_skill - Orchestrator wants to control test/merge gates independently
Arguments
{plan_path} — Absolute path to the implementation plan file (required)
Critical Constraints
NEVER:
- Implement without first exploring affected systems with subagents
- Implement in the main working directory (always use the worktree)
- Force push or perform destructive git operations
- Merge the worktree branch into any branch
- Delete or remove the worktree
- Run the full test suite (the orchestrator handles testing)
- Rebase onto the base branch
- Clean up the worktree environment
- Re-run tests just to see failures — grep the saved output file instead
- Pipe test output through
tail,head, or other truncation commands - Execute
git mergecommands (including--no-ff,--no-commit, or any variant). All branch content must be applied viagit cherry-pick <commit>for individual commits orgit checkout <branch> -- <file>for specific files.merge_worktreerequires linear commit history — merge commits cannot be rebased and will causeWORKTREE_INTACT_MERGE_COMMITS_DETECTEDfailure.
ALWAYS:
- Create a new worktree from the current branch
- Use subagents to deeply understand affected systems BEFORE implementing
- Use
model: "sonnet"when spawning all subagents via the Task tool - Implement one phase at a time
- Commit per phase with descriptive messages
- Leave the worktree intact when done
Context Limit Behavior
If this skill hits the Claude context limit mid-execution, the headless session
terminates with needs_retry=true in the tool response. The worktree remains
intact on disk with all commits made up to that point.
The orchestrator must not retry this skill when needs_retry=true. Retrying
creates a brand-new timestamped worktree, discarding all partial progress.
Correct orchestration on needs_retry=true:
- Route immediately to
/autoskillit:retry-worktree(viaretry.on_exhausted) - The
run_skillresponse now includesworktree_pathas a top-level JSON field whenneeds_retry=true. The orchestrator reads it fromresult.worktree_path— no filesystem search is needed. - Use
max_attempts: 0on this step'sretryblock to ensure immediate escalation
Workflow
Step 0: Validate Prerequisites
- Extract and verify the plan path using path detection: scan the tokens
after the skill name for the first one that starts with
/,./,temp/, or.autoskillit/— that token is the plan path. Ignore any non-path words that appear before it (orchestrators sometimes prepend descriptive text such as "the verified plan"). If no path-like token is found, treat the entire argument string as pasted plan content. Verify the resolved file exists before proceeding; if it does not, abort with:"Plan file not found: {path}. Correct format: /autoskillit:implement-worktree-no-merge <plan_path>" - Check for dry-walkthrough verification: Read the first line of the plan file. If it does not contain exactly
Dry-walkthrough verified = TRUE:- Display warning: "WARNING: This plan has NOT been validated with a dry-walkthrough. Implementation may encounter issues that could have been caught beforehand."
- Use
AskUserQuestionto prompt: "Do you want to continue without dry-walkthrough validation?" - If user declines, abort and suggest running
/autoskillit:dry-walkthroughfirst
- Check
git status --porcelain— if dirty, warn user - Parse plan: phases, files per phase, verification commands
- Multi-Part Plan Detection: Examine the plan filename. If it contains
_part_(e.g.,_part_a,_part_b,_part_1):- Extract the part identifier (A, B, C… or number) from the suffix.
- SCOPE FENCE — MANDATORY: Before any exploration or implementation begins, output the following constraint:
"🚧 SCOPE FENCE ACTIVE: I am implementing PART {X} ONLY. I MUST NOT open, read, or execute any other part files, regardless of what I encounter in temp/ or any other directory. Sibling part files are out of scope for this entire session."
- When launching subagents in Step 2, include this fence instruction explicitly in each subagent prompt so that the subagents do not open, read, or reference sibling part files.
Step 1: Create Git Worktree
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
WORKTREE_NAME="impl-{plan_name}-$(date +%Y%m%d-%H%M%S)"
WORKTREE_PATH="../worktrees/${WORKTREE_NAME}"
git worktree add -b "${WORKTREE_NAME}" "${WORKTREE_PATH}"
WORKTREE_PATH="$(cd "${WORKTREE_PATH}" && pwd)"
# Record the base branch in two ways for reliable discovery by retry-worktree:
# 1) Write an explicit file store (works with any Git version, works offline)
mkdir -p ".autoskillit/temp/worktrees/${WORKTREE_NAME}"
echo "${CURRENT_BRANCH}" > ".autoskillit/temp/worktrees/${WORKTREE_NAME}/base-branch"
# 2) Set git upstream tracking (requires remote tracking ref in local fetch cache)
if ! git fetch origin "${CURRENT_BRANCH}" 2>/dev/null; then
echo "NOTE: Branch '${CURRENT_BRANCH}' has no remote tracking ref on origin."
echo " merge_worktree will fail unless you push first: git push -u origin ${CURRENT_BRANCH}"
echo " Continuing — implementation will proceed, but the merge step will be blocked."
fi
if ! git -C "${WORKTREE_PATH}" branch --set-upstream-to="origin/${CURRENT_BRANCH}" "${WORKTREE_NAME}" 2>/dev/null; then
echo "NOTE: Could not set upstream tracking for '${WORKTREE_NAME}' → 'origin/${CURRENT_BRANCH}'."
fi
Step 1 (cont.): Emit Structured Tokens Early
Immediately after the worktree is created, output these tokens on their own
lines so the execution layer can capture them from assistant_messages even
if context is exhausted before Step 6:
worktree_path = ${WORKTREE_PATH}
branch_name = ${WORKTREE_NAME}
Why emit early? If context exhaustion occurs during Steps 2–5, the
execution layer scans assistant_messages for worktree_path= and surfaces
it as a top-level field in the run_skill JSON response. The orchestrator
reads this field directly without filesystem discovery heuristics.
Step 1.5: Initialize Code Index for Original Project
Set the MCP code-index project path to the original project directory so Explore subagents can use code search tools:
mcp__code-index__set_project_path(path="{ORIGINAL_PROJECT_PATH}")
This must happen before Step 2 or any code-index search tools will fail with "Project path not set."
Step 2: Deep System Understanding (Subagents)
Before implementing ANY code, launch parallel Explore subagents to understand affected systems:
- Affected files — current implementation, dependencies, consumers
- Test coverage — existing tests, patterns, fixtures for affected code
- Integration points — entry/exit points, contracts that must be maintained
- Data flow — state management, source of truth
Step 3: Set Up Worktree Environment
Set up the project's development environment in the worktree. Use the project's configured worktree_setup.command from .autoskillit/config.yaml if available. If not configured, check for a Taskfile with install-worktree task, or detect the project type and run appropriate setup.
cd "${WORKTREE_PATH}"
# If worktree_setup.command is configured, run it. Otherwise:
task install-worktree # or equivalent for the project type
Why isolated env matters: Installing packages without isolation overwrites the global state. When the worktree is deleted, CLI commands break with import errors.
All commands in Steps 4–5 must run from ${WORKTREE_PATH}. Use absolute paths to avoid CWD drift across Bash tool calls.
Step 3.5: Re-point Code Index to Worktree (REQUIRED)
CRITICAL: After setting up the worktree environment, you MUST update the MCP code-index project path to the worktree:
mcp__code-index__set_project_path(path="${WORKTREE_PATH}")
Failure to do this means code-index searches will return results from the original project, not your worktree.
Step 4: Implement Phase by Phase
For each phase:
- Announce phase objective and files to modify
- Implement changes guided by understanding from Step 2
- Run per-phase verification if plan specifies it
- Commit per phase with descriptive messages. If the project has pre-commit
hooks, run
pre-commit run --all-filesand stage any auto-fixed files before each commit. - Report phase completion
Where practical, delegate test updates to subagents to keep main conversation context lean.
Step 5: Run Pre-commit Checks
cd "${WORKTREE_PATH}" && pre-commit run --all-files
Fix any formatting or linting issues. Do NOT run the full test suite.
Step 5.5: Completeness Self-Check (Conflict Resolution Plans Only)
If the plan contains a PR Changes Inventory section, perform a completeness check before
handoff:
- Extract the Category C — Clean Carry-Overs file list from the plan.
- Run
git diff {base_branch}...HEAD --name-onlyto get all files in the implementation. - For each Category C file, verify it appears in the diff.
- If any Category C files are missing from the diff:
- Fetch them from the PR branch:
git show origin/{pr_branch}:{file_path} - Write them to the worktree and commit:
fix: carry over {file_path} from PR branch - Re-run the check until all Category C files are present.
- Fetch them from the PR branch:
This guard prevents silent data loss: Category C files are PR-only changes that require no conflict resolution and must be preserved in full.
Step 6: Handoff Report
Output to terminal:
- Worktree path:
${WORKTREE_PATH} - Branch name:
${WORKTREE_NAME} - Base branch: the branch the worktree was created from
- Summary: list of implemented phases and key changes
Explicitly state: "Worktree left intact for orchestrator to test and merge."
Then emit these structured output tokens on their own lines so recipe capture blocks can extract them:
worktree_path = ${WORKTREE_PATH}
branch_name = ${WORKTREE_NAME}
If this is a _part_ plan file: The orchestrator MUST merge this worktree
(merge_worktree) into the base branch BEFORE invoking
implement-worktree-no-merge for the next part. Part N+1's worktree must be
created from the post-merge state of the base branch, not from Part N's base
commit. This is a global sequencing rule — it applies even when operating
off-recipe.
Step 6.5: Reset Code Index to Original Project (REQUIRED)
CRITICAL: After completion, you MUST reset the MCP code-index project path back to the original project directory:
mcp__code-index__set_project_path(path="{ORIGINAL_PROJECT_PATH}")
Error Handling
- Worktree creation fails — check
git worktree list, suggestgit worktree prune - Phase fails — report which phase and why, offer to fix/retry, skip (if optional), or abort. Do NOT clean up the worktree.
- Pre-commit fails — fix formatting/linting issues and re-commit
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?