/solopreneur:worktree-handofffrom solopreneur
Creates a git worktree for a task and records handoff context into a plan file committed to the branch. Use when starting a new branch or handing off a task to a fresh session.
Ships in solopreneur. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Before any other action, check whether CODEX_THREAD_ID is set. If it is, stop
before creating a worktree or branch, copying configuration, changing a plan,
or committing. This release supports Worktree Handoff only on Claude Code;
tell the user the Codex worktree seam is not shipped yet and to run the
workflow there instead.
Create an isolated workspace for a new or in-progress task, and record the complete task context into a plan file that gets committed to the branch. The next session reads the plan file to pick up without re-explanation.
Source the cascade config helpers, then determine the operating mode:
# --- solopreneur config helpers (sourced from shared/config.sh) ---
# One real shell file, so no harness rewrites the helpers on the way to the
# shell. Claude Code replaces the ${CLAUDE_SKILL_DIR} token below when it loads
# this body; Codex does not. It is SINGLE-quoted on purpose — it is a load-time
# token, not an environment variable, and letting the shell expand the name
# would source whatever an inherited value happened to point at. Unreplaced, it
# is not a directory, so substitute the absolute path of the directory holding
# THIS SKILL.md — every harness states that path to the model.
SOLO_SKILL_DIR='${CLAUDE_SKILL_DIR}'
[ -d "$SOLO_SKILL_DIR" ] || SOLO_SKILL_DIR="<absolute path of the directory holding this SKILL.md>"
SOLO_CONFIG_SH="$SOLO_SKILL_DIR/../../shared/config.sh"
# Three candidates, one contract. Inside the plugin the helpers sit at ../../shared/;
# authoring against this repo reaches them under src/solopreneur/shared/; and a
# skill republished on its own — any flattened skills directory — carries them
# at scripts/config.sh instead, because shared/ is a sibling of skills/ and does
# not travel with a per-skill copy. Try each in order, then STOP. Sourcing a
# file that is not there does not halt the shell: every helper stays undefined,
# every config read returns empty, and the 2026-08-11 A2 run showed where that
# leads — the model "rescued" it with a repo-relative path, which resolves only
# when the repo under review happens to be this plugin's own source repo.
# Canonical authoring keeps non-skill source under src/.
[ -f "$SOLO_CONFIG_SH" ] || SOLO_CONFIG_SH="$SOLO_SKILL_DIR/../../../src/solopreneur/shared/config.sh"
[ -f "$SOLO_CONFIG_SH" ] || SOLO_CONFIG_SH="$SOLO_SKILL_DIR/scripts/config.sh"
[ -f "$SOLO_CONFIG_SH" ] || { echo "HALT: solopreneur config helpers not found under $SOLO_SKILL_DIR — stop here, do not improvise a path"; exit 1; }
source "$SOLO_CONFIG_SH"
# --- end solopreneur config helpers ---
TODOS_CONFIG=$(read_solopreneur_config todos)
PLANS_CONFIG=$(read_solopreneur_config plans)
BACKLOG=$(echo "${TODOS_CONFIG:-{}}" | jq -r '.backlog // empty')
DOING=$(echo "${TODOS_CONFIG:-{}}" | jq -r '.doing // empty')
PLANS_DIR=$(echo "${PLANS_CONFIG:-{}}" | jq -r '.dir // empty')
PLANS_DIR="${PLANS_DIR:-docs/solopreneur/plans}" # default
MODE=$([ -n "$BACKLOG" ] && [ -n "$DOING" ] && echo "state-machine" || echo "flat")
Mode decision:
$BACKLOG and $DOING are both non-empty$PLANS_DIRName based on task type and description:
| Task Type | Branch Prefix | Example |
|---|---|---|
| Bug fix | fix/ | fix/sleep-calculation |
| New feature | feature/ | feature/health-connect-edit |
| Refactor | refactor/ | refactor/sleep-sessionizer |
| Research | research/ | research/healthkit-sources |
Worktree directory name = branch name slug (strip prefix, use - separators).
Always place worktrees under .worktrees/:
git worktree add .worktrees/<slug> -b <branch-name>
Prohibited: operating on main, placing worktrees outside .worktrees/.
Worktrees are separate directories — gitignored files don't carry over automatically.
Check .gitignore for config/secret patterns, find matching files in the main repo,
copy them to the same relative paths in the worktree. Never copy build artifacts.
# The main repo is the first worktree. `--porcelain` puts the path on its own
# `worktree <path>` line, so a path containing spaces survives — and no `$N`
# lands in a skill body (see ../../shared/config.sh for why that matters).
MAIN_REPO="$(git worktree list --porcelain | sed -n 's/^worktree //p' | head -1)"
WORKTREE=".worktrees/<slug>"
# Find gitignored config files that exist in the main repo
# Common patterns: .env, *.xcconfig, local.properties, secrets.json
# Copy any that are relevant to this project to the worktree's corresponding paths
Collect all plan files:
# State-machine mode: collect from backlog + doing
if [ "$MODE" = "state-machine" ]; then
ALL_FILES=$(find "$BACKLOG" "$DOING" -maxdepth 1 -name "*.md" 2>/dev/null)
else
mkdir -p "$PLANS_DIR"
ALL_FILES=$(find "$PLANS_DIR" -maxdepth 1 -name "*.md" 2>/dev/null)
fi
Context matching — before prompting the user:
Extract 3–5 key terms from the current conversation (task name, feature area, keywords from the user's description). Then score each plan file:
Plan-Branch: lines, first 20 lines) for the key terms# ILLUSTRATIVE ONLY — substitute actual key terms extracted from the current
# conversation before running. Do NOT execute this block with these hardcoded terms.
TERMS="<term1>\|<term2>\|<term3>" # replace with actual key terms
CANDIDATES=""
while IFS= read -r f; do
[ -z "$f" ] && continue
score=$(head -20 "$f" | grep -i -c "$TERMS" 2>/dev/null); score=${score:-0}
name_score=$(basename "$f" | grep -i -c "$TERMS" 2>/dev/null); name_score=${name_score:-0}
total=$((score + name_score * 2))
[ "$total" -gt 0 ] && CANDIDATES="$CANDIDATES\n$total $f"
done <<< "$ALL_FILES"
CANDIDATES=$(printf '%b' "$CANDIDATES" | sort -rn)
MATCH_COUNT=$([ -n "$CANDIDATES" ] && printf '%b' "$CANDIDATES" | grep -c . || echo 0)
Match count = number of files with a score greater than zero (i.e., at least one key term found in the filename or first 20 lines of content).
Decision based on match count:
0 matches — if $ALL_FILES is non-empty, briefly tell the user: "No matching plans found for this task — creating a new plan file. (Reply with a filename to use an existing plan instead.)" Then proceed to Step 6 to create a new file.
1 match — use it automatically, no prompt. Print: → Matched plan: <filename> so the user knows what was selected.
2+ matches — show only the matching candidates (not all files) with index numbers, then ask:
"Found N matching plans. Which one does this worktree belong to? Enter a number to reuse it, or 'new' to create a fresh plan file."
In state-machine mode, note the source directory in parentheses (Backlog / Doing) next to each filename.
If no plan files exist at all, skip all of the above and proceed directly to creating a new file.
Recording the source: When a file is selected, set PLAN_SOURCE=backlog or
PLAN_SOURCE=doing based on which directory it came from. Step 6 checks
$PLAN_SOURCE to decide whether to run git mv (only when PLAN_SOURCE=backlog).
Create a new file:
<doing>/<YYYY-MM-DD>-<branch-slug>.md<plans-dir>/<YYYY-MM-DD>-<branch-slug>.mdWhere <branch-slug> = branch name with / replaced by -
(e.g., fix/sleep-calculation → fix-sleep-calculation).
Date from $(date +%Y-%m-%d).
New file content:
<!--
Plan-Branch: <branch-name>
-->
## Handoff Context (<YYYY-MM-DD>, branch: <branch-name>)
### Problem Background
<why is this being done — user reports, screenshots, logs>
### Root Cause
<known technical issues, with file paths + line numbers>
### Items to Fix / Implement
- [ ] <item with expected approach>
### Key Files
| path | description |
|------|-------------|
### Current Progress
Not started.
Fill in the five sections based on context from the current conversation.
Move from backlog to doing (state-machine mode only):
If the selected file is in $BACKLOG, move it:
git mv "$BACKLOG/<filename>" "$DOING/<filename>"
PLAN_FILE="$DOING/<filename>"
In flat mode, skip this step — the file stays in place.
Ensure the Plan-Branch: marker block exists at the top of the file.
If the file already starts with an HTML comment block containing at least one
Plan-Branch: line, check whether Plan-Branch: <branch-name> is already
present. If it is absent, append the line inside the existing comment block:
python3 -c "
import sys branch, path = sys.argv[1], sys.argv[2] with open(path) as f: content = f.read() idx = content.find('\n-->') if idx != -1: content = content[:idx+1] + 'Plan-Branch: ' + branch + '\n' + content[idx+1:] with open(path, 'w') as f: f.write(content) " "" "$PLAN_FILE"
If no comment block exists at the top (legacy file), prepend one:
```markdown
<!--
Plan-Branch: <branch-name>
-->
Append the handoff section at the end of the file:
## Handoff Context (<YYYY-MM-DD>, branch: <branch-name>)
### Problem Background
<why is this being done — user reports, screenshots, logs>
### Root Cause
<known technical issues, with file paths + line numbers>
### Items to Fix / Implement
- [ ] <item with expected approach>
### Key Files
| path | description |
|------|-------------|
### Current Progress
<not started / steps done so far>
Fill in the five sections based on context from the current conversation. Be specific: include file names, line numbers, error messages, actual numbers. Include root cause analysis already done so the next session doesn't debug from scratch. If the conversation had screenshots or user-reported bug details, include everything.
git add <plan-file-path>
# Also stage the git mv result if the file moved from backlog to doing
git commit -m "docs(handoff): context for <branch-name>"
git push -u origin <branch-name>
Single commit. Push immediately so the doc is visible to the next session and to PR reviewers.
Print this so the user can paste it into a new session:
cd /absolute/path/to/repo/.worktrees/<slug>
Plan file: <relative/path/to/plan.md>
Read the plan file for the full context — branch <branch-name> is tracked under
the `Plan-Branch:` marker, and the latest `## Handoff Context` section captures
the current state.
Branch: <branch-name>, <one-line task description>.
Use an absolute path in the cd command (from git worktree list). The plan file
path should be relative to the repo root.
User says: "Open a worktree to fix the sleep calculation — the issue is duplicate sources from HealthKit"
git worktree add .worktrees/fix-sleep-calculation -b fix/sleep-calculation
Plan file discovery: user picks existing 2026-04-10-sleep-tracking.md from
backlog (state-machine mode). File is git mv'd to doing, Plan-Branch: fix/sleep-calculation is added to the marker block, and the Handoff Context
section is appended with the HealthKit duplicate-source root cause detail.
Commit: docs(handoff): context for fix/sleep-calculation
Output for user:
cd /path/to/project/.worktrees/fix-sleep-calculation
Plan file: docs/solopreneur/plans/doing/2026-04-10-sleep-tracking.md
Read the plan file for the full context — branch fix/sleep-calculation is tracked
under the `Plan-Branch:` marker, and the latest `## Handoff Context` section
captures the current state.
Branch: fix/sleep-calculation, deduplicate HealthKit multi-source sleep samples
so displayed sleep time matches Apple Health's value.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
17 skills in this plugin
/autopilotPR orchestration planner. Reads a task file, discusses PR splitting strategy
with the user, produces plan + spec files, and either dispatches a worktree
subagent in the current session (single PR, run now) or schedules execution
via cron (multi-PR, or single-PR scheduled). Use when the user wants a task
implemented, reviewed, and merged automatically — whether the scope fits in
one PR or needs to be split. Triggers: "autopilot", "orchestrate", "batch
implement", "split into PRs and run", or when the user provides a todo/spec
and wants unattended PR execution.
/codex-agents-bootstrapInstall or refresh custom agents shipped by solopreneur-family plugins in the
Codex user agents directory. Use after installing, updating, enabling, or
disabling a solopreneur-family plugin, or when the user asks to bootstrap,
install, refresh, or diagnose Codex agents. This is unnecessary on Claude.
/greenlightAutomated PR review loop that keeps running until the PR is clean. Triggers
external reviewers (Codex bot, Codex CLI, and the Gemini bot when activity
detection sees it on the repo), processes feedback, fixes issues, and
re-triggers — repeating until no new suggestions remain.
Supports `/greenlight external` to skip internal review and go straight to
external reviewers, and `/greenlight external gemini` to specify a starting
reviewer. Use when the user says "greenlight", "run reviews until clean",
"get this PR approved", or wants automated review cycling on an open PR.
Also auto-detects uncommitted mode: when on main branch with uncommitted
changes and no PR, runs Codex CLI `--uncommitted` review loop only, fixes
in-place without committing, until codex reports clean.
Also supports post-commit mode (explicit `/greenlight post-commit <SHA>`
or `<SHA1>..<SHA2>`): Phase 1 subagents + Codex CLI + agy (Gemini-family CLI)
in parallel, fixes as new commits on top (no amend, no new PR), pushes after
each round.
npx claudepluginhub hanamizuki/solopreneur --plugin solopreneurOther plugins' skills for the same job