From smith
Autonomous bugfix workflow from invocation to merged PR with no questions gate, spec generation, or planning phase. Use for bugs, patches, and small well-defined changes scoped to 1-3 files.
How this skill is triggered — by the user, by Claude, or both
Slash command
/smith:smith-bugfixThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
A streamlined alternative to `/smith-new` for bugs, small changes, and trivial fixes that don't require requirements gathering, planning, or a questions gate. Runs fully autonomously from invocation to merged PR.
A streamlined alternative to /smith-new for bugs, small changes, and trivial fixes that don't require requirements gathering, planning, or a questions gate. Runs fully autonomously from invocation to merged PR.
Arguments: $ARGUMENTS
Throughout this action, log significant events to the vault session log. Read the session log path from .smith/vault/.current-session. If the file is missing or the vault is not initialized, skip all logging silently.
Append entries using this format:
### [HH:MM:SS] /smith-bugfix <event>
**User Request:**
> <verbatim user message that triggered this action — capture the exact words the user typed describing the bug or fix needed. For natural language triggers like "fix this", include the preceding context that describes what's broken.>
**Synthesized Input:** <brief summary of the fix being applied>
**Outcome:** <what happened>
**Artifacts:** <files created/modified>
**Systems affected:** <system IDs>
Log at these points:
Immediately before every Agent tool call in this workflow, append a block to the session log. The Agent tool's return value does not expose subagent_type or model to the parent, so this is the only place that information can be captured.
### [HH:MM:SS] Subagent invoked: <description>
**Type:** <subagent_type or "general">
**Model:** <model override passed to Agent, or "inherited" if none>
After the Agent tool returns, the subagent-vault-writeback.sh hook automatically appends a matching "Subagent completed" block with metrics read from the sidechain transcript — do not duplicate that logging in the skill.
/smith-new)Use /smith-bugfix when:
Upgrade to /smith-new if during implementation you discover:
If upgrading: STOP, tell the user, and offer to switch to /smith-new with the context gathered so far.
If the user says any of the following (or similar phrases), treat it as invoking this command:
When triggered by natural language, synthesize the conversation history into a concise bug/fix description and proceed as if that description was passed as $ARGUMENTS.
Every bugfix always runs in an isolated git worktree branched from the configured base branch (origin/$BASE_BRANCH, defaulting to origin/main). The user's current working directory and branch are NEVER touched, and concurrent Smith sessions cannot collide on the shared working tree. There is no "switch to base / stash / cancel" branching logic — the worktree is mandatory.
Generate fix slug (2-4 words) from the fix description. Store as $SLUG. Derive:
BRANCH=fix/$SLUGWORKTREE_PATH=/tmp/smith-bugfix-$SLUGPRIMARY_REPO=<current working directory — capture before entering the worktree>Resolve the configured base branch, then fetch it (does NOT change the user's current branch). Smith reads the project's integration branch from the constitution; it falls back to main when unconfigured:
BASE_BRANCH=$(.specify/scripts/bash/get-base-branch.sh)
git fetch origin "$BASE_BRANCH"
Activate workflow tracking — invoke the shipped helper to create the per-branch marker. The workflow-gate hook (PR #20) exempts this exact helper by basename so the bootstrap runs even when no marker exists yet (per spec/31-workflow-gate-bootstrap). The helper also stamps the current session log with a workflow-start line so workflow-summary.sh --totals-only can attribute tokens to this workflow:
~/.smith/scripts/create-active-workflow.sh \
--branch "$BRANCH" \
--workflow smith-bugfix \
--slug "$SLUG" \
--worktree "$WORKTREE_PATH"
(Falls back to scripts/create-active-workflow.sh in repo-dev layouts.) The helper exits 3 if a marker already exists for this branch under a different workflow type — pick a new slug (e.g., append -2) and retry. The marker is cleared by the Workflow Cleanup step at the end via clear-active-workflow.sh.
Create the worktree with the fix branch from the configured base branch (origin/$BASE_BRANCH):
git worktree add "$WORKTREE_PATH" -b "$BRANCH" "origin/$BASE_BRANCH"
The user's current branch is completely unaffected. They can be on main, a feature branch, or a detached HEAD — this workflow will not interfere.
Copy .env to the worktree (only if one exists in the primary repo and the fix might touch services that read it):
[ -f .env ] && cp .env "$WORKTREE_PATH/.env"
All subsequent phases (2-7) run inside $WORKTREE_PATH. Use cd "$WORKTREE_PATH" for the first command, then keep every subsequent command scoped to that directory via absolute paths or explicit cd. Do NOT cd back to the primary repo until Phase 7.3 (merge) — gh pr merge must run from the primary repo to avoid "main already checked out" errors.
On failure before merge: preserve the worktree for debugging and log its path in the session log. Do NOT auto-remove it. Leave the active-workflow yaml in place so the user knows the session is still holding that branch.
If .smith/vault/ledger/ exists and contains non-empty files, load relevant Ledger sections to inform this bugfix. If the directory is missing, empty, or unreadable, skip silently — the Ledger is purely additive and never required.
ls .smith/vault/ledger/*.md 2>/dev/null.smith/vault/ledger/antipatterns.md.smith/vault/ledger/edge-cases.mdcontext_budget_violations in .smith/vault/ledger/.meta.json by 1. If .meta.json does not exist, create it from the default template first. This signal tells the reconciliation system that the Ledger is too large for the configured budget.Before writing any code, check existing specs for context and conflicts.
Identify affected systems from the fix description and map to spec directories:
services/command-center/ → specs/system-15-command-center/spec.mdservices/email-pipeline/ → specs/system-03-email-archive-contact-graph/spec.mdservices/sentiment-engine/ → specs/sentiment-engine/spec.mdservices/communication-triage/ → specs/system-05-communication-triage/spec.mdservices/voice-training/ → specs/system-04-personal-voice/spec.mddocker-compose.yml → specs/system-01-core-infrastructure/spec.mdspecs/*/spec.md contentRead relevant spec.md files and check:
If a conflict is found: STOP the workflow and alert the user. Explain the conflict and ask how to proceed. This is the ONLY point where the workflow may pause.
If no conflicts: Continue silently.
If the bugfix execution fails, check config for auto-retry:
.smith/config.json — check ledger.auto_retry and ledger.max_retriesauto_retry is false (default) or config is missing, do NOT retry — fail normallyauto_retry is true:
a. Re-read .smith/vault/ledger/antipatterns.md to get the latest failure patterns
b. Analyze the failure against known antipatterns to adjust the approach
c. Retry the fix with the adjusted approach
d. Repeat up to max_retries times (default: 2), re-reading antipatterns before each attempt
e. If all retries exhausted, fail with a summary of all attempts.meta Descriptions for Touched MethodsAfter every Write or Edit to a source file in this fix, refresh the
file's .meta description layer to reflect the new or changed methods.
This step is cheap because Claude already has the source open and parsed
in working memory — it does NOT regenerate descriptions for untouched
methods, and it does NOT call any LLM from the save hook (the save hook
remains LLM-free per data-model.md §3.2). Per data-model.md §4 and
research.md §6.
Run once per modified source file (extensions: .py, .js, .jsx,
.ts, .tsx):
Identify touched method ids. Parse the file via the project
parser (python3 ~/.smith/scripts/parse-python.py <file> or
node ~/.smith/scripts/parse-js.js <file>) and diff the resulting
method-id set against .smith/index/files/<file>.meta's Id:
entries. The 16-char hex ids ADDED or with a CHANGED signature are
the "touched" set. (Body-only edits do not change the id, per the
stable-method-id recipe in data-model.md §1.1.)
Determine purpose_shifted. Set true when any of:
export or __all__ entry was added,Otherwise false.
Inline-spawn ONE Task for this file. Subscription billing,
not API tokens (v3 / PR #23). The spawn replaces the v2 shell-out
to meta_describe.py update-touched.
a. Gather inputs via the discovery helper:
DISCOVERY=$(python3 ~/.smith/scripts/describe_discover.py \
--rel-path <project-relative-path> \
--touched-only \
--touched-ids <comma-separated-16hex-ids>)
(Falls back to scripts/parsers/describe_discover.py in repo-dev
layouts.)
b. Build the prompt body via the prompt-assembly helper:
PROMPT=$(python3 ~/.smith/scripts/describe_write.py build-prompt \
--rel-path <project-relative-path> \
--method-ids <comma-separated-16hex-ids> \
--purpose-shifted <true|false> \
$( [ "<purpose_shifted>" = "true" ] && echo --module ))
c. Spawn the Task (subscription billing — inherits session auth):
subagent_type: general
model: claude-haiku-4-5
prompt: |
<PROMPT body from step b>
Return ONLY a JSON object with `method_descriptions` for the
touched ids, and a `module_description` iff
purpose-shifted=true. Match task-llm-output.schema.json.
d. When the Task returns, pipe its JSON output into the writer:
echo "$TASK_OUTPUT" | \
python3 ~/.smith/scripts/describe_write.py apply --update-touched \
--rel-path <project-relative-path> \
--purpose-shifted <true|false>
e. Test stub. If SMITH_TASK_STUB=1 is set, skip the Task
spawn and use apply --from-stub <fixture> instead.
Failure handling. If any step fails (helper not installed,
Task tool error, write error), log a single line to the session
log and CONTINUE — the missing descriptions are flagged as a
non-blocking PR-body warning by /smith-build (see Phase 8 /
data-model.md §9). This step never blocks the fix.
This step is skipped entirely for files where the diff only touches
non-source extensions (.css, .html, .sh, .md, .json, ...).
If any files changed belong to a Docker service:
docker compose up -d --build <service-name>
bash scripts/health-check.sh
Skip this phase if changes are limited to specs, docs, or config files that don't affect running services.
cd services/command-center && pnpm testcd services/<service> && poetry run pytestservices/command-center/src/** were modifiedcd services/command-center && pnpm exec playwright testcd services/command-center && pnpm lintcd services/<service> && poetry run ruff check .For each affected system spec.md:
If the fix is relevant to project status tracking, update STATUS.md.
git add <all modified files — list explicitly, never git add -A>
git commit -m "fix: <description>"
fix: conventional commit prefixgit add -A or git add .).env files or credentialsgit push -u origin fix/<slug>
BASE_BRANCH=$(.specify/scripts/bash/get-base-branch.sh)
gh pr create --base "$BASE_BRANCH" --title "fix: <short title>" --body "$(cat <<'EOF'
## Summary
<1-3 bullet points describing the fix>
## What was broken
<Brief description of the bug/issue>
## What changed
<List of files and what changed in each>
## Test plan
- [ ] Unit tests pass
- [ ] E2E tests pass (if applicable)
- [ ] Docker health check passes (if applicable)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
EOF
)"
Then merge from the primary repo directory (never from the worktree — gh pr merge fails with "main already checked out" otherwise):
cd "$PRIMARY_REPO" && gh pr merge <pr-number> --squash --delete-branch
cd "$PRIMARY_REPO" && git pull origin "$(.specify/scripts/bash/get-base-branch.sh)"
Already covered by git pull above. The user's working branch in the primary repo is untouched — only the base branch ref moves forward. If the user was on the base branch, they now see the merged changes; if they were on another branch, the base branch is updated but their checkout is not.
cd "$PRIMARY_REPO" && docker compose up -d --build <service-name>
cd "$PRIMARY_REPO" && bash scripts/health-check.sh
Skip if no Docker services were touched.
Emit a final chat message to the user that starts with "Bugfix complete. Here's the summary:" (or equivalent for the fix). Include any bugfix-specific notes (test results, services rebuilt, worktree path if preserved on failure). At the bottom, run the totals command and paste the lines it prints verbatim — do this BEFORE the Workflow Cleanup step below. Pass the workflow's own session log via --session so totals are computed against the correct file even if the session log rolled over mid-workflow:
# $SESSION was captured at workflow start (Phase 1 step 2). Fall back to the
# marker's session_log field, then to .current-session, if not in scope here.
SESSION="${SESSION:-$(cat .smith/vault/.current-session 2>/dev/null)}"
bash "$HOME/.claude/hooks/workflow-summary.sh" --totals-only --session "$SESSION"
If it prints n/a (no workflow invocation found) and exits non-zero, do NOT present those as real numbers — note that totals were unavailable and which session file was checked.
The full === Workflow Summary === block is written to the session log file automatically by the workflow-summary.sh Stop hook once the active-workflow file is removed — that's for audit only, not chat. Do not emit the full block to the user.
Run from the primary repo directory. On success, remove the worktree; on failure (before merge), preserve it and skip worktree removal.
cd "$PRIMARY_REPO"
# Success path: remove the worktree (the branch was already deleted by --delete-branch on merge)
git worktree remove "$WORKTREE_PATH"
# Always: clear the active-workflow marker so future sessions know this branch is free.
# Use the shipped helper so this works even on projects that set Bash(rm:*) in the
# deny list of .claude/settings.json.
.specify/scripts/bash/clear-active-workflow.sh "$BRANCH"
If git worktree remove fails because of uncommitted local edits (shouldn't happen on the success path, but can on forced cleanup), fall back to git worktree remove --force "$WORKTREE_PATH" and warn the user that any uncommitted changes in the worktree are being discarded.
After workflow completion (success or failure), trigger a Ledger reflection if enabled:
.smith/config.json — if ledger.auto_reflect is true (default), proceed.smith/vault/ledger/ pathsmith-reflect workflow.smith/config.json is missing or ledger.auto_reflect is false, skip silentlyAfter reflection completes (or is skipped):
.smith/config.json — if ledger.reconcile.auto_reconcile is false, skip.smith/vault/ledger/.meta.json — check signals against thresholds:
estimated_tokens > thresholds.total_tokens_max (default 30000)context_budget_violations > thresholds.context_violations_threshold (default 3)reinforcements_since_reconcile > thresholds.reinforcements_threshold (default 50)last_reconcile is less than minimum_hours_between_reconciles (default 6) hours ago, skipreconcile_model (default: Haiku).meta.json is missing, or config is missing, skip silentlyAs the VERY LAST action — after the PR merge, Workflow Cleanup (worktree removal +
marker clear), and the reflection/reconciliation launches above — Run
/smith-sync from the primary repo on the default branch. This sweeps the
team-shareable .smith/ artifacts (manifest, .meta describe layer, ledger,
bank, agents, sessions) accumulated this fix into a single
chore(smith): … [skip ci] commit and pushes it to the default branch, so
teammates receive the updated context (including any debug reports and the
session log this fix produced).
Do NOT block on the background reflection sub-agent — this session's ledger
update will be captured by the NEXT /smith-sync run. /smith-sync no-ops
cleanly if there is nothing to sync.
git add -A or git add . — always stage specific files.env files or credentials/smith-newnpx claudepluginhub attckdigital/smithCoordinates diagnosis, test-driven reproduction, root-cause analysis, and targeted fixes for bugs with regression testing.
Autonomous build pipeline that generates tasks, implements features, runs tests, commits, pushes, merges PRs, and produces release notes without user interaction.