From wholework
Local implementation (`/code 123`). Size auto-detection routes XS/S→patch (direct commit to main), M/L→branch+PR. Override with `--patch`/`--pr`. Does not update CLAUDE.md, run session retrospectives, or manage memory.
How this skill is triggered — by the user, by Claude, or both
Slash command
/wholework:codeThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
Receive an Issue number and implement based on the Spec.
Receive an Issue number and implement based on the Spec.
If ARGUMENTS contains --help, Read ${CLAUDE_PLUGIN_ROOT}/modules/skill-help.md and follow the "Processing Steps" section to output help, then stop.
If ARGUMENTS contains the --auto flag, delegate as follows:
--patch is present, run ${CLAUDE_PLUGIN_ROOT}/scripts/run-code.sh $NUMBER --patch [--base {branch}] via Bash; otherwise run ${CLAUDE_PLUGIN_ROOT}/scripts/run-code.sh $NUMBER [--base {branch}] (add --base {branch} if --base flag is present)If --auto is not present, proceed with mode detection below.
Note: Running
/code 123from an interactive session spawns a fork sub-agent viacontext: fork. Output is not streamed, but a summary is returned upon completion.
If ARGUMENTS contains the --non-interactive flag, operate in non-interactive mode (set when invoked autonomously via run-code.sh). In this mode, AskUserQuestion cannot be used — see ## Error Handling in Non-Interactive Mode below for the complete policy.
In interactive mode (no flag), use AskUserQuestion to follow the normal steps.
In --non-interactive mode (invoked via run-code.sh with claude -p), AskUserQuestion is not available (the process would hang).
Policy: At any step that would call AskUserQuestion, apply auto-resolve + log instead of aborting.
Read ${CLAUDE_PLUGIN_ROOT}/modules/ambiguity-detector.md and follow the "Non-Interactive Mode Handling" section. In summary:
## Autonomous Auto-Resolve Log subsectionXL (requires sub-issue splitting before coding; guide to split the Issue, then abort)/code $NUMBER --patch, then abort)Determine the route based on Size (Project field preferred → label fallback) and option flags.
Read ${CLAUDE_PLUGIN_ROOT}/modules/phase-banner.md and display the start banner with ENTITY_TYPE="issue", ENTITY_NUMBER=$NUMBER, SKILL_NAME="code".
First, fetch Size (run before route detection):
${CLAUDE_PLUGIN_ROOT}/scripts/get-issue-size.sh "$NUMBER" 2>/dev/null
get-issue-size.sh fetches Size in two stages: Project field preferred → size/* label fallback. Use the output value (e.g., S, M; empty means Size not set) in subsequent steps (e.g., XS/S detection in Step 2).
Fetch base branch (run before route detection):
If ARGUMENTS contains --base {branch}, use that value as BASE_BRANCH. If --base is not specified, default to BASE_BRANCH=main (backward compatibility).
Flag precedence (explicit flag > Size auto-detection):
--patch → patch route (direct commit to BASE_BRANCH, no PR). Even if Size is XL, --patch takes precedence — skip the XL check and run as patch route--pr → pr route (branch + PR flow)Size auto-detection (when no flags are present):
Follow the Size→workflow mapping table in ${CLAUDE_PLUGIN_ROOT}/modules/size-workflow-table.md:
XS or S → patch routeM or L → pr route (branch + PR flow)XL → exit with error ("XL requires sub-issue splitting. Split the Issue and run /code on each sub-issue.")--non-interactive mode → output error message, guide "Set Size via the Project field or size/* label, then run /code $NUMBER interactively", and abortRecord the result (patch / pr) for use in subsequent steps.
gh issue view $NUMBER --json title,body
Generate a short description from the title (e.g., "add-implement-skill").
Read ${CLAUDE_PLUGIN_ROOT}/modules/worktree-lifecycle.md and follow the "Entry section" to create a worktree.
Worktree naming convention (by route):
SSoT: This section is the single source of truth for worktree naming in
/code. All scripts and modules must derive their naming from this section.
Both patch and pr routes use the same name: code/issue-$NUMBER
EnterWorktree converts / to +, resulting in:
.claude/worktrees/code+issue-$NUMBERworktree-code+issue-$NUMBERRecord the ENTERED_WORKTREE variable for use in subsequent steps.
Edit/Write path conventions inside worktree (CWD-relative):
After entering the worktree, CWD switches to the worktree directory. When editing or creating files with Edit/Write tools, verify CWD first (check with pwd), and use CWD-relative paths rather than absolute paths (e.g., ~/.claude/ or /Users/.../src/...). Using absolute paths would edit the main repository, causing missed commits and conflicts.
phase/ready Label CheckSkip this check if Size is XS (XS does not require Spec — skip this entire step and proceed to Step 4).
For sizes other than XS: run gh issue view $NUMBER --json labels -q '.labels[].name' to get labels, then check if phase/ready is present.
phase/ready label present: proceed to the next stepphase/ready label absent:
## Autonomous Auto-Resolve Log subsection)
/spec $NUMBER", then exitFor pr route:
The branch was already created by Worktree Entry (EnterWorktree) in Step 2 — no need to run git checkout -b.
For patch route (direct commit to BASE_BRANCH):
The worktree was already created by Worktree Entry (EnterWorktree) in Step 2 — no explicit branch work needed.
Both routes:
${CLAUDE_PLUGIN_ROOT}/scripts/gh-label-transition.sh $NUMBER code
Read ${CLAUDE_PLUGIN_ROOT}/modules/detect-config-markers.md and follow the "Processing Steps" section. Retain SPEC_PATH and STEERING_DOCS_PATH for use in subsequent steps.
Search for $SPEC_PATH/issue-$NUMBER-*.md and read the Spec to review the implementation plan.
If no Spec exists, read the requirements from the Issue body and implement accordingly.
Review notes section (only if present in Spec):
If the Spec has a "Notes" section, cross-reference each item against the implementation steps and recognize them as constraints/specifications to consider during implementation. Skip this step if there is no "Notes" section.
External auto-commit area interpretation:
When Spec Notes contains phrases such as the following, interpret as: edit the files to implement the required changes; skip git add / git commit for those specific paths (the external tool, e.g., Obsidian Git or IDE auto-commit, handles committing asynchronously):
<path> in git add/git commit — external tool auto-commit area"git add/git commit for this path (external auto-commit)"vault/)"These are commit-skip instructions, not skip-implementation instructions. The files must be edited to satisfy ACs.
Phase Handoff read (after loading Spec):
Read ${CLAUDE_PLUGIN_ROOT}/modules/phase-handoff.md and follow the "Read Procedure" section.
Parameters: SPEC_PATH, ISSUE_NUMBER=$NUMBER, PHASE_NAME=code.
Read existing retrospective sections (before starting implementation):
If the Spec contains any retrospective sections (e.g., ## Spec Retrospective, ## Code Retrospective) from prior phases, read them before starting implementation. These sections carry forward decisions, pitfalls, and confirmed approaches from earlier phases — reading them avoids repeating known mistakes and aligns implementation with prior design resolutions.
If the Spec has an "Uncertainties" section, before implementing:
## Autonomous Auto-Resolve Log subsection)## Autonomous Auto-Resolve Log subsection)If uncertainties cannot be verified, or the design premise turns out to be incorrect:
## Autonomous Auto-Resolve Log subsectionUse Glob with path="$STEERING_DOCS_PATH" to check whether the following steering documents exist, then Read only those that exist:
$STEERING_DOCS_PATH/tech.md — Coding conventions, Architecture Decisions (check for convention compliance), Forbidden Expressions (avoid prohibited expressions)$STEERING_DOCS_PATH/structure.md — Directory structure, Key Files (check file placement)If not present, skip this step and proceed to the next.
Use information from steering documents for coding convention compliance, file placement, and naming consistency during implementation. If $STEERING_DOCS_PATH/tech.md is Read, reference the ## Forbidden Expressions section and avoid using prohibited expressions in code comments, variable names, commit messages, and new documents.
Project-local Domain files (if present):
Read ${CLAUDE_PLUGIN_ROOT}/modules/domain-loader.md and follow the "Processing Steps" section with SKILL_NAME=code. Domain file content provides additional implementation guidelines and constraints.
Implement the code following the "Implementation Steps" in the Spec.
Implementation scope: all Spec steps are required
Implement every step listed in the Spec's "Implementation Steps" regardless of the verify-type of its associated acceptance condition. A step whose AC is marked <!-- verify-type: post-merge manual --> must still be implemented in this PR — "post-merge manual" describes how the AC is verified (by human observation after merge), not whether the step can be skipped. Omitting a step because its AC is post-merge manual is an implementation error.
If scripts/validate-skill-syntax.py exists, Read ${CLAUDE_PLUGIN_ROOT}/skills/code/stale-test-check.md and follow the "Processing Steps" section.
If scope-out remediations are identified during implementation, create a follow-up Issue using the retro/code label:
gh issue create --title "{remediation title}" --label "retro/code" --body "..."
Follow-up Issue body format:
Do not add the triaged label — it is assigned by /triage afterward.
Skip this sub-step if no out-of-scope remediations are identified.
Read ${CLAUDE_PLUGIN_ROOT}/modules/test-runner.md and follow the "Processing Steps" section to run tests.
On test FAIL, before the generic 1-repair-attempt flow below, run structured recovery:
.tmp/test-failure-recovery-$NUMBER.log.${CLAUDE_PLUGIN_ROOT}/scripts/test-failure-classify.sh --log .tmp/test-failure-recovery-$NUMBER.log
and read the category from stdout.snapshot / mock / fixture (repairable): perform at most one targeted auto-fix attempt for
that class (regenerate snapshot / rebuild mock expectations / update fixture literal). No loop.logic / infra (not repairable): skip Tier 0 and escalate immediately to Tier 3 — fall through
to the existing Step 9 FAIL handling below (in /auto this path reaches orchestration Tier 3 recovery).tests/ directory: after the auto-fix, run git status --porcelain
and confirm only tests/ paths changed. If any non-tests/ file changed, revert the Tier 0 changes
(git checkout -- <files>) and fall through to the existing FAIL handling..tmp/test-failure-recovery-$NUMBER.log for Tier 3 sub-agent reference.Test FAIL handling (when test-runner.md reports FAIL):
/code $NUMBER --patch." and exit with non-zeroAdditional validation (run after tests):
If scripts/validate-skill-syntax.py exists, Read ${CLAUDE_PLUGIN_ROOT}/skills/code/skill-dev-validation.md and follow the "Processing Steps" section.
If scripts/check-forbidden-expressions.sh exists, Read ${CLAUDE_PLUGIN_ROOT}/skills/code/forbidden-expressions-check.md and follow the "Processing Steps" section.
Documentation consistency check (run after validation):
Read ${CLAUDE_PLUGIN_ROOT}/modules/doc-checker.md and follow the "Impact assessment criteria" section to determine whether documentation sync updates are needed for files changed during implementation.
If sync is required, update the target documents (README.md, docs/workflow.md, etc.) before committing.
docs/ja/ sync check: If docs/translation-workflow.md exists, read it and follow the sync procedure.
AC consistency check (run before verify-executor):
After completing implementation — especially when a refactor changes the implementation means (e.g., switching from an MCP tool to a CLI command, renaming a flag, removing a dependency) — verify that the related Issue's Acceptance Criteria verify commands still reflect the current implementation:
<!-- verify: ... --> command in the AC, check whether the command's target (file path, string literal, tool name, flag name) still matches the implementation after any refactoringgh-issue-edit.sh). This is the typical case when a refactor deliberately changes the implementation approach (e.g., switched from mcp_call to a CLI command, so the allowed-tools entry referencing the old MCP tool is now stale)Patch route verify command check:
If patch route (Size is XS/S or --patch flag), before running verify-executor, scan the Issue body's ## Acceptance Criteria > Pre-merge for github_check "gh pr checks" entries.
github_check "gh pr checks" is incompatible. Auto-fixing to github_check "gh run list" form." and replace each with github_check "gh run list" form (add --workflow=<filename> if there are multiple workflow files under .github/workflows/). Update Issue body via gh-issue-edit.sh. Also update Spec verify commands ($SPEC_PATH/issue-$NUMBER-*.md) with the same fix.Resolving {{base_url}} to localhost: If verify commands contain {{base_url}}, resolve it before passing to verify-executor:
LOCAL_BASE_URL is set, use that valueLOCAL_BASE_URL is not set, default to http://localhost:3000{{base_url}} in verify commands with the resolved URL before passing to verify-executorRead ${CLAUDE_PLUGIN_ROOT}/modules/verify-executor.md and follow the "Processing Steps" section to run verify command consistency verification in full mode. Target: pre-merge verify commands for Issue #$NUMBER. Skip if no hints exist.
Handle results as follows:
mkdir -p .tmpgh issue view $NUMBER --json body- [ ] with - [x] (preserve the rest of the line, verify command comments <!-- verify: ... -->, etc.).tmp/issue-body-$NUMBER.md with Write tool${CLAUDE_PLUGIN_ROOT}/scripts/gh-issue-edit.sh $NUMBER .tmp/issue-body-$NUMBER.mdrm -f .tmp/issue-body-$NUMBER.mdsection_contains/file_contains hint:
section_contains "skills/verify/SKILL.md" "Step 9" "Issue OPEN" FAILs because "Issue OPEN" is absent from the implementation → add that text to the appropriate section in skills/verify/SKILL.md.file_contains "settings.json" "gh project" FAILs → check actual file content and rewrite to file_contains "settings.json" "Skill(triage)"mkdir -p .tmp.tmp/issue-body-$NUMBER.md with Write tool${CLAUDE_PLUGIN_ROOT}/scripts/gh-issue-edit.sh $NUMBER .tmp/issue-body-$NUMBER.mdrm -f .tmp/issue-body-$NUMBER.md/verify phase after mergeSpec sync (when verify commands are modified): If Issue body verify commands (<!-- verify: ... -->) are modified, also apply the same fix to the "Verification > Pre-merge" section in the Spec ($SPEC_PATH/issue-$NUMBER-*.md). Updating only the Issue body without updating the Spec will cause discrepancies flagged in the review retrospective.
Read ${CLAUDE_PLUGIN_ROOT}/modules/verify-executor.md and follow the "Processing Steps" section to run verify commands in full mode. Target: the ## Smoke Test section of the Spec loaded in Step 5 ($SPEC_PATH/issue-$NUMBER-*.md).
If the Spec has no ## Smoke Test section, skip this subsection entirely (no-op — backward compatible with existing behavior).
When a ## Smoke Test section is present:
echo "progress: Running smoke test for issue #$NUMBER..."
<!-- verify: ... --> commands from the ## Smoke Test section and run them via verify-executor in full mode. ToolSearch is in allowed-tools so mcp_call smoke checks can invoke MCP tools./code $NUMBER --patch." and exit with non-zero--when condition unmet, ToolSearch unavailable, etc.): record as SKIPPED in both the Step 12 Code Retrospective "Smoke Test" row and the completion message, and proceed to commit (do not silent-adopt a fallback value; do not hard-block on the environment limitation).For patch route (commit to BASE_BRANCH):
Type → prefix mapping (exhaustive):
| Type | prefix |
|---|---|
| Bug | fix: |
| Feature | feat: |
| Task | chore: |
| Not set | patch: |
Determine commit prefix (fetch Type → map to prefix):
${CLAUDE_PLUGIN_ROOT}/scripts/get-issue-type.sh $NUMBER and get the returned Type name (Bug/Feature/Task)patch: prefixInclude closes #N only when the base branch is main (GitHub auto-close via closes #N only works when merging to the default branch).
DCO compliance: use git commit -s to add Signed-off-by:. Do NOT use the global HEREDOC pattern from ~/.claude/CLAUDE.md — it omits -s.
git add <changed files>
# If BASE_BRANCH is main: "{prefix} <summary> (closes #$NUMBER)"
# If BASE_BRANCH is not main: "{prefix} <summary>"
git commit -s -m "{prefix} <summary>
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>"
git log -1 --format='%B' | grep -q "^Signed-off-by:" || { echo "ERROR: missing sign-off"; exit 1; }
Push is done in Step 13 Worktree Exit (merge-to-main pattern). Label transition happens after push completes (after Step 13).
For pr route (branch + PR):
Before creating the PR, emit a progress line so the watchdog resets its silence counter:
echo "progress: Creating PR for issue #$NUMBER..."
gh pr create --title "Issue #$NUMBER: {summary of changes}" --base "${BASE_BRANCH}" --body "..."
Include closes #N in PR body only when BASE_BRANCH is main. If BASE_BRANCH is not main, omit closes #N and instead note: "Since the base branch is {BASE_BRANCH}, please close the Issue manually at final merge."
PR title format:
Issue #N: {summary of changes} (concise English summary)Issue #48: Fix Mermaid diagram parse errorPR body should include:
- only). Informational only; checkbox management is done on the Issue sidecloses #$NUMBERPR body template example:
## Summary
{overview of changes}
## Verification (pre-merge)
- {item 1}
- {item 2}
## Verification (post-merge)
- {item 1}
closes #$NUMBER
Auto-append acceptance conditions to Issue:
When creating a PR, compare the Spec verification methods against the Issue acceptance conditions. If the Issue acceptance conditions are missing verification items, fetch the current Issue body with gh issue view $NUMBER --json body, build the updated body with the missing items appended, pre-create the directory with mkdir -p .tmp, write the updated body to .tmp/issue-body-$NUMBER.md with Write tool, update with ${CLAUDE_PLUGIN_ROOT}/scripts/gh-issue-edit.sh $NUMBER .tmp/issue-body-$NUMBER.md. After update, delete the temp file with rm -f .tmp/issue-body-$NUMBER.md.
Change tracking comment (post-PR):
After creating the PR, if any of the following changes occurred during Step 10 or Step 11, post a change tracking comment to the Issue:
If none of the above changes occurred, skip this step.
When changes occurred, write the comment body to .tmp/change-tracking-$NUMBER.md with the Write tool, then post:
mkdir -p .tmp
${CLAUDE_PLUGIN_ROOT}/scripts/gh-issue-comment.sh $NUMBER .tmp/change-tracking-$NUMBER.md
rm -f .tmp/change-tracking-$NUMBER.md
Comment format:
## Change Tracking (by /code)
### Changes Made
- {change summary 1 — what was changed and why}
- {change summary 2}
Append retrospective information to the Spec and commit.
Content to append:
Retrospective writing discipline:
Template:
## Code Retrospective
### Deviations from Design
- (deviation and reason)
### Design Gaps/Ambiguities
- (problems found during implementation)
### Rework
- (where rework occurred and the cause)
Sync Spec implementation steps (when deviations exist):
If there are items under "Deviations from Design" (reordering of implementation steps, omission/consolidation of steps, adoption of a different approach due to design changes, etc.), in addition to recording in the retrospective, also update the Spec "Implementation Steps" section itself to match the actual implementation. This allows the subsequent /verify phase to verify based on the latest implementation.
Steps:
## Code Retrospective section after ## Spec Retrospective in the Spec ($SPEC_PATH/issue-$NUMBER-*.md) using the Edit toolscripts/check-forbidden-expressions.sh exists, Read ${CLAUDE_PLUGIN_ROOT}/skills/code/forbidden-expressions-check.md and follow the "Retrospective Guard" section.${CLAUDE_PLUGIN_ROOT}/modules/phase-handoff.md and follow the "Write Procedure" section.
Parameters: SPEC_PATH, ISSUE_NUMBER=$NUMBER, PHASE_NAME=code.
The handoff is staged with the Spec in the same git add and committed together.git add $SPEC_PATH/issue-$NUMBER-*.md
git commit -s -m "Add code retrospective for issue #$NUMBER
Co-Authored-By: Claude Sonnet 4.6 [email protected]"
```bash
git log -1 --format='%B' | grep -q "^Signed-off-by:" || { echo "ERROR: missing sign-off"; exit 1; }
echo "progress: Pushing branch to origin for issue #$NUMBER..."
git push origin HEAD
Read ${CLAUDE_PLUGIN_ROOT}/modules/worktree-lifecycle.md and follow the Exit section appropriate for the route.
patch route (merge-to-main pattern):
Follow "Exit: merge-to-main section". After push completes, transition the label (patch route skips /merge, so label transition happens here).
patch route (XS/S common): After push completes, transition to phase/verify:
${CLAUDE_PLUGIN_ROOT}/scripts/gh-label-transition.sh $NUMBER verify
patch route completes here. Follow the completion report section to inform the user.
pr route (push-and-remove pattern): Follow "Exit: push-and-remove section" (push was done in Step 12, so only delete the worktree).
Only if .wholework.yml in the project has opportunistic-verify: true, Read ${CLAUDE_PLUGIN_ROOT}/modules/opportunistic-verify.md and follow the "Processing Steps" section to run opportunistic verification. The skill name is /code. Skip this step if not configured.
Output the route-specific prefix, then read ${CLAUDE_PLUGIN_ROOT}/modules/next-action-guide.md and follow the "Processing Steps" section.
Parameters to pass to next-action-guide:
SKILL_NAME=codeISSUE_NUMBER=$NUMBERPR_NUMBER={PR number if pr route}ROUTE={patch|pr}RESULT=success--patch flag). For the pr route, always create a branchcat/echo/redirect (>) is prohibited (causes confirmation prompts)@test names must be in English (ASCII). Multibyte characters (Japanese, etc.) cause test name parse failures and result in 0 tests executed. See: #226{1,2,3}) is prohibited. Use globs for deleting multiple files: rm -f .tmp/issue-*.md (brace expansion triggers Claude Code security warnings).claude/ are treated as sensitive files by Claude Code — Edit and Write tools are rejected for these paths. When implementation requires editing .claude/ files (e.g., settings.json.template), use Bash (e.g., python3 -c "..." or sed -i) insteadgit add / git commit for those specific paths. The external tool handles committing. A Spec Notes instruction like "do not include in git commit procedure" is a commit-skip instruction only — not skip-implementation.Creates, edits, and optimizes skills for Claude Code, including drafting, evaluating with test prompts, iterating on performance, and improving skill descriptions for better triggering accuracy.
npx claudepluginhub saitoco/wholework --plugin wholework