Skip to content

feat: add lifecycle extension system for user-defined workflow hooks - #1224

Closed
jhochenbaum wants to merge 59 commits into
obra:devfrom
jhochenbaum:feat/lifecycle-extensions
Closed

jhochenbaum wants to merge 59 commits into
obra:devfrom
jhochenbaum:feat/lifecycle-extensions

Conversation

@jhochenbaum

@jhochenbaum jhochenbaum commented Apr 19, 2026 •

Copy link
Copy Markdown

What problem are you trying to solve?

One of Superpowers' core strengths is its minimal set of skills and configuration without bloating the core. This is one of the reasons many of us find ourselves coming back to Superpowers over similar frameworks. At the same time, while we can (and should) create our own toolkits or plugins to manage custom skills, there are many instances where injecting a specific skill into the superpowers workflow would be genuinely useful. Today, users who want to add custom steps, whether a compound learning phase after plan execution, a specialized security review after code review, or a compliance check before merge, have no supported way to do it. Their only options are to submit a PR to core (which will, and should, be rejected since these tend to be domain or user-specific) or to maintain a fork.

This creates two problems: (1) unnecessary PR pressure on the core repo maintainer from users trying to add domain-specific workflow steps, and (2) users who could benefit from superpowers' lifecycle structure can't extend it without modifying core.

Concrete example: Issue #230 requests compound learning at the end of work (inspired by the compound-engineering-plugin). This is a great idea for some users, but too domain-specific for core, and there are countless others like it. With this change, any user could implement it as a personal extension skill, without bloating the core Superpowers framework.

What does this PR change?

Adds a lifecycle extension system: users declare custom skills to run at specific workflow events via YAML manifest files. Two manifest locations are supported — personal (~/.superpowers/extensions.yaml) and project-level (.superpowers/extensions.yaml) — which are merged at session start (personal first, project appends). The session-start hook parses both manifests and injects the combined registry into session context.

Core skills check the registry at seven lifecycle events and invoke registered extensions via the Skill tool:

Event Skill When
post-brainstorm brainstorming After spec approval, before writing plans
post-plan writing-plans After plan is saved
pre-task executing-plans / subagent-driven-development Before each task begins
post-task executing-plans / subagent-driven-development After each task completes
post-execution executing-plans / subagent-driven-development After all tasks complete
post-review requesting-code-review After code review completes
pre-finish finishing-a-development-branch Before presenting merge/PR options

Extension skills are just regular skills in the user's own skill directories — no new skill format or tooling required.

Example manifest (~/.superpowers/extensions.yaml):

extensions:
  post-execution:
    - compound-learning    # invokes skill by name via the Skill tool
  post-review:
    - security-audit
  pre-finish:
    - compliance-check

Is this change appropriate for the core library?

Yes — this is general-purpose infrastructure, not a domain-specific skill. It benefits all users by giving them a sanctioned way to extend superpowers without modifying core. It's explicitly designed to reduce the need for (and burden of) domain-specific PRs by providing extension points instead.

No third-party dependencies, no domain-specific content, and no new skills were added to core. Extension skills live entirely in the user's own skill directories.

What alternatives did you consider?

Three approaches were evaluated:

  1. Frontmatter hooks — Custom skills declare lifecycle hooks via a hooks: or superpowers-hooks: field in YAML frontmatter. Rejected because it adds superpowers-specific semantics on top of the agentskills.io spec, which would confuse users who expect frontmatter to be standard.

  2. Named extension points in core skills — Core skills define explicit named extension points. Potentially more granular but requires a larger API surface and more upfront design. Elements of this were borrowed (named lifecycle events) without the full complexity.

  3. Skill composition / wrapper pattern — Custom skills "extend" core skills via an extends: field. Most flexible but fragile — wrappers break silently when core skills change, and composing multiple extensions is hard.

Final approach is a separate manifest file (extensions.yaml) that maps named lifecycle events to skills. This keeps skill files spec-compliant, makes the superpowers-specific wiring explicit, and provides a single file to see all active extensions at a glance.

Does this PR contain multiple unrelated changes?

No. All changes serve one feature: the lifecycle extension system. The session-start hook parses manifests, using-superpowers tells the agent about extensions, and the core skill edits add minimal extension check points at lifecycle events. None of these are useful independently.

Existing PRs

No existing PR proposes a lifecycle hook/extension system.

Testing

Three-tier test suite

1. Hook unit tests (test-lifecycle-extensions-hook.sh) — 11 tests, 25 assertions
Tests the bash session-start hook directly without the Claude CLI:

  • Personal manifest only → extensions parsed correctly
  • Project manifest only → extensions parsed correctly
  • Both manifests → merge order verified (personal first, project appends)
  • No manifests → graceful no-op with valid JSON, no extensions key
  • Malformed YAML → graceful degradation
  • All 7 lifecycle events recognized
  • Repo-root project manifest found from subdirectory
  • Namespaced skill names with colons preserved

2. Skill documentation tests (test-lifecycle-extensions.sh) — 8 headless tests
Fast claude -p sessions verifying each skill's documentation mentions extension checkpoints:

  • Each of the 7 lifecycle events has a corresponding skill that mentions checking extensions
  • using-superpowers skill describes the extensions registry

3. Integration test (test-lifecycle-extensions-integration.sh) — 5 Claude sessions, 7 lifecycle events
End-to-end verification that Claude actually invokes registered extension skills at each lifecycle event during real workflow execution. Uses the repo's established testing pattern:

  • Registers a canary extension skill at all 7 events via ~/.superpowers/extensions.yaml
  • Runs 5 separate Claude sessions (one per workflow: executing-plans, writing-plans, code-review, finish-branch, brainstorming)
  • Verifies canary invocation via JSONL transcript analysis (grep '"skill":"lifecycle-canary"')
  • All 7/7 lifecycle events verified: pre-task, post-task, post-execution, post-plan, post-review, pre-finish, post-brainstorm

Integration test results

Events verified: 7 / 7
Failures: 0

post-brainstorm  — Session 5 (brainstorming)       ✓
post-plan        — Session 2 (writing-plans)        ✓
pre-task         — Session 1 (executing-plans)      ✓
post-task        — Session 1 (executing-plans)      ✓
post-execution   — Session 1 (executing-plans)      ✓
post-review      — Session 3 (requesting-code-review) ✓
pre-finish       — Session 4 (finishing-a-development-branch) ✓

STATUS: PASSED

Note: The integration test verifies via JSONL transcript analysis that Claude invokes extensions through the Skill tool (not just that it outputs the expected text). This catches cases where the agent simulates the extension output without actually invoking the skill.

Environment tested

Harness Harness version Model Model version/ID
Claude Code 2.1.114 Claude Opus claude-opus-4-6

Evaluation

  • Design session: Collaborative brainstorming through the superpowers:brainstorming skill — explored the problem space, evaluated 3 architectural approaches, converged on the separate manifest approach.
  • Hook testing: Session-start hook tested with 3 scenarios: personal manifest only, personal + project manifests (merge order verified), and no manifests (graceful no-op).
  • Skill changes are additive one-liners — each core skill gets a "check extensions registry for X extensions and invoke each in order" instruction at the appropriate lifecycle point. No existing behavior-shaping content was modified.
  • End-to-end integration: All 7 lifecycle events verified via JSONL transcript analysis across 5 real Claude sessions.

Rigor

  • If this is a skills change: I used superpowers:writing-skills and
    completed adversarial pressure testing (paste results below)
  • This change was tested adversarially, not just on the happy path
  • I did not modify carefully-tuned content (Red Flags table,
    rationalizations, "human partner" language) without extensive evals
    showing the change is an improvement

The skill changes are additive one-line instructions at lifecycle transition points. The integration test suite verifies end-to-end extension invocation across all 7 lifecycle events via JSONL transcript analysis.

Human review

  • A human has reviewed the COMPLETE proposed diff before submission

Drew Ritter and others added 30 commits March 23, 2026 17:37
Design for making using-git-worktrees, finishing-a-development-branch,
and subagent-driven-development skills work in the Codex App's sandboxed
worktree environment. Read-only environment detection via git-dir vs
git-common-dir comparison, ~48 lines across 4 files, zero breaking changes.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Fix three Important issues from spec review:
- Clarify Step 1.5 placement relative to existing Steps 2/3
- Re-derive environment state at cleanup time instead of relying on
  earlier skill output
- Acknowledge pre-existing Step 5 cleanup inconsistency

Also: precise step references, exact codex-tools.md content, clearer
Integration section update instructions.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
- Add commit SHA + data loss warning to handoff payload (HIGH)
- Add explicit commit step before handoff (HIGH)
- Remove misleading "mark as externally managed" from Path B
- Add executing-plans 1-line edit (was missing)
- Add branch name derivation rules
- Add conditional UI language for non-App environments
- Add sandbox fallback for permission errors
- Add STOP directive after Step 0 reporting

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
) to spec

Both tests address real risk scenarios:
- obra#5: cleanup guard bug would delete Codex App's own worktree (data loss)
- obra#10: Local thread sandbox fallback needs manual Codex App validation

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
8 tasks covering: environment detection in using-git-worktrees,
Step 1.5 + cleanup guard in finishing-a-development-branch,
Integration line updates, codex-tools.md docs, automated tests,
and final verification.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
The subagent review loop (dispatching a fresh agent to review plans/specs)
doubled execution time (~25 min overhead) without measurably improving plan
quality. Regression testing across 5 versions (v3.6.0 through v5.0.4) with
5 trials each showed identical plan sizes, task counts, and quality scores
regardless of whether the review loop ran.

Changes:
- writing-plans: Replace subagent Plan Review Loop with inline Self-Review
  checklist (spec coverage, placeholder scan, type consistency)
- writing-plans: Add explicit "No Placeholders" section listing plan failures
  (TBD, vague descriptions, undefined references, "similar to Task N")
- brainstorming: Replace subagent Spec Review Loop with inline Spec Self-Review
  (placeholder scan, internal consistency, scope check, ambiguity check)
- Both skills now use "look at it with fresh eyes" framing

Testing: 5 trials with the new skill show self-review catches 3-5 real bugs
per run (spawn positions, API mismatches, seed bugs, grid indexing) in ~30s
instead of ~25 min. Remaining defects are comparable to the subagent approach.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Metadata files (.server-info, .events, .server.pid, .server.log,
.server-stopped) were stored in the same directory served over HTTP,
making them accessible via the /files/ route. They now live in a .meta/
subdirectory that is not web-accessible.

Also fixes a stale test assertion ("Waiting for Claude" → "Waiting for
the agent").

Reported-By: 吉田仁
The session directory now contains two peers: content/ (HTML served to
the browser) and state/ (events, server-info, pid, log). Previously
all files shared a single directory, making server state and user
interaction data accessible over the /files/ HTTP route.

Also fixes stale test assertion ("Waiting for Claude" → "Waiting for
the agent").

Reported-By: 吉田仁
ownerAlive() treated EPERM (permission denied) the same as ESRCH
(process not found), causing the server to self-terminate within 60s
whenever the owner process ran as a different user. This affected WSL
(owner is a Windows process), Tailscale SSH, and any cross-user
scenario.

The fix: `return e.code === 'EPERM'` — if we get permission denied,
the process is alive; we just can't signal it.

Tested on Linux via Tailscale SSH with a root-owned grandparent PID:
- Server survives past the 60s lifecycle check (EPERM = alive)
- Server still shuts down when owner genuinely dies (ESRCH = dead)

Fixes obra#879
Two bugs caused the brainstorm server to self-terminate within 60s:

1. ownerAlive() treated EPERM (permission denied) as "process dead".
   When the owner PID belongs to a different user (Tailscale SSH,
   system daemons), process.kill(pid, 0) throws EPERM — but the
   process IS alive. Fixed: return e.code === 'EPERM'.

2. On WSL, the grandparent PID resolves to a short-lived subprocess
   that exits before the first 60s lifecycle check. The PID is
   genuinely dead (ESRCH), so the EPERM fix alone doesn't help.
   Fixed: validate the owner PID at server startup — if it's already
   dead, it was a bad resolution, so disable monitoring and rely on
   the 30-minute idle timeout.

This also removes the Windows/MSYS2-specific OWNER_PID="" carve-out
from start-server.sh, since the server now handles invalid PIDs
generically at startup regardless of platform.

Tested on Linux (magic-kingdom) via Tailscale SSH:
- Root-owned owner PID (EPERM): server survives ✓
- Dead owner PID at startup (WSL sim): monitoring disabled, survives ✓
- Valid owner that dies: server shuts down within 60s ✓

Fixes obra#879
…ction

Copilot CLI v1.0.11 reads `additionalContext` from sessionStart hook
output, but the session-start script only emits the Claude Code-specific
nested format. Add COPILOT_CLI env var detection so Copilot CLI gets the
SDK-standard top-level `additionalContext` while Claude Code continues
getting `hookSpecificOutput`.

Based on PR obra#910 by @culinablaz.
- Add references/copilot-tools.md with full tool equivalence table
- Add Copilot CLI to using-superpowers skill platform instructions
- Add marketplace install instructions to README
- Add changelog entry crediting @culinablaz for the hook fix
The bootstrap text advertised a configDir-based skills path that didn't
match the runtime path (resolved relative to the plugin file). Tests
used yet another hardcoded path and referenced a nonexistent lib/ dir.

- Remove misleading skills path from bootstrap text; the agent should
  use the native skill tool, not read files by path
- Fix test setup to create a consistent layout matching the plugin's
  ../../skills resolution
- Export SUPERPOWERS_SKILLS_DIR from setup.sh so tests use a single
  source of truth
- Add regression test that bootstrap doesn't advertise the old path
- Remove broken cp of nonexistent lib/ directory

Fixes obra#847
…sage

Move bootstrap injection from experimental.chat.system.transform to
experimental.chat.messages.transform, prepending to the first user
message instead of adding a system message.

This avoids two issues:
- System messages repeated every turn inflate token usage (obra#750)
- Multiple system messages break Qwen and other models (obra#894)

Tested on OpenCode 1.3.2 with Claude Sonnet 4.5 — brainstorming skill
fires correctly on "Let's make a React to do list" prompt.
Design for detect-and-defer worktree support. Superpowers defers to
native harness worktree systems when available, falls back to manual
git worktree creation when not. Covers Phases 0-2: detection, consent,
native tool preference, finishing state detection, and three bug fixes
(obra#940, obra#999, obra#238).

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
- Fix Bug obra#999 order: merge → verify → remove worktree → delete branch
  (avoids losing work if merge fails after worktree removal)
- Add submodule guard to Step 0 detection (GIT_DIR != GIT_COMMON is also
  true in submodules)
- Preserve global path (~/.config/superpowers/worktrees/) in detection for
  backward compatibility, just stop offering it to new users
- Add step numbering note and implementation notes section
- Expand provenance heuristic to cover global path and manual creation

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
- Step 1a is the load-bearing assumption, not just a risk — if it fails,
  the entire design needs rework. TDD validation must be first impl task.
- obra#1009 resolution depends on Step 1a working, stated explicitly
- obra#574 honestly deferred, not "partially addressed"
- Add hooks symlink to Step 1b (PR obra#965 idea, prevents silent hook loss)
- Add stale worktree pruning to Step 5 (PR obra#1072 idea, one-line self-heal)

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
5 tasks: TDD gate for Step 1a, using-git-worktrees rewrite,
finishing-a-development-branch rewrite, integration updates,
end-to-end validation. Task 1 is a hard gate — if native tool
preference fails RED/GREEN, stop and redesign.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
jhochenbaum and others added 2 commits April 19, 2026 20:07
Three-tier test coverage for the lifecycle extensions feature:
- Hook unit tests (test-lifecycle-extensions-hook.sh): 9 tests, 22 assertions
- Skill documentation tests (test-lifecycle-extensions.sh): 8 headless tests
- Integration test (test-lifecycle-extensions-integration.sh): 5 Claude sessions
  verifying all 7 lifecycle events via JSONL transcript analysis

Also includes the design spec and implementation plan.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
…t from repo root

Fixes two edge cases in the session-start hook:
- Skill names containing colons (e.g. github:gh-fix-ci) were split
  incorrectly by the colon delimiter. Switch to tab-separated parsing.
- Project extensions manifest was only found in $PWD. Now walks up to
  the git root (or nearest parent) so it works from subdirectories.

Adds test coverage for both cases.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@jhochenbaum jhochenbaum reopened this Apr 20, 2026
These are process artifacts, not part of the feature.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@jhochenbaum

Copy link
Copy Markdown
Author

@obra curious if this is something you'd be open to or if you think it's out of scope for Superpowers? Apologies for not opening an issue to discuss first.

@obra

obra commented Sep 26, 2026

Copy link
Copy Markdown
Owner

Hi @jhochenbaum! I'm Claude, helping @obra triage. I'm closing this in favor of #2398, the master tracking ticket for configurability. The status change isn't a judgment about your work. We found fourteen requests for different kinds of configurability and want to design them together rather than one knob at a time. Your write-up is linked there as part of the input, and we'd love your thoughts in that thread.

— Claude (Opus 5.5, claude-opus-5-5), Claude Code 2.1.283, session 49301b31-b716-41b8-a316-80b8461e0de9

@obra obra closed this Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request skills Retired: use a skill:* label or skill-system

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants