Skip to content

notque/vexjoy-agent / skills/process/workflow

workflow

Verified

Structured work: multi-phase tasks, feature builds, planning, objective loops, hill climbing.

FileKindSize
SKILL.mdskill md13.2 KB
references/adr-template.mdmarkdown9.4 KB
references/agent-upgrade.mdmarkdown12.5 KB
references/article-evaluation-pipeline.mdmarkdown8.9 KB
references/article-evaluation-pipeline/references/report-template.mdmarkdown2.5 KB
references/article-evaluation-pipeline/references/wabi-sabi-classification.mdmarkdown2.4 KB
references/auto-pipeline.mdmarkdown12.5 KB
references/auto-pipeline/references/pipeline-catalog.jsonconfig15.0 KB
references/auto-pipeline/references/pipeline-catalog.mdmarkdown4.3 KB
references/build_dag.pyscript12.5 KB
references/chain-composer.mdmarkdown20.4 KB
references/chain-composer/references/canonical-chains.mdmarkdown13.9 KB
references/comprehensive-review-workflow.jsscript19.3 KB
references/comprehensive-review.mdmarkdown27.8 KB
references/comprehensive-review/references/output-templates.mdmarkdown10.6 KB
references/comprehensive-review/references/wave-0-per-package.mdmarkdown5.6 KB
references/comprehensive-review/references/wave-1-foundation.mdmarkdown10.4 KB
references/comprehensive-review/references/wave-2-deep-dive.mdmarkdown7.3 KB
references/comprehensive-review/references/wave-3-adversarial.mdmarkdown7.4 KB
references/dag-compatibility-matrix.mdmarkdown13.0 KB
references/dag-composition-patterns.mdmarkdown5.0 KB
references/dag-orchestration-advanced.mdmarkdown6.3 KB
references/dag-orchestration-examples.mdmarkdown11.4 KB
references/dag-skill-patterns.mdmarkdown12.5 KB
references/de-ai-pipeline.jsscript14.6 KB
references/de-ai-pipeline.mdmarkdown6.3 KB
references/discover_skills.pyscript12.1 KB
references/do-perspectives.mdmarkdown11.5 KB
references/doc-pipeline.mdmarkdown9.2 KB
references/domain-research.mdmarkdown32.8 KB
references/domain-research/references/task-type-guide.mdmarkdown11.4 KB
references/explore-pipeline.jsscript18.6 KB
references/explore-pipeline.mdmarkdown15.0 KB
references/fan-out-workflow.jsscript9.7 KB
references/fan-out-workflow.pyscript10.4 KB
references/feedback-loop-construction.mdmarkdown14.3 KB
references/fl-design.mdmarkdown9.6 KB
references/fl-error-handling.mdmarkdown8.5 KB
references/fl-implement.mdmarkdown7.6 KB
references/fl-pipeline.mdmarkdown6.0 KB
references/fl-plan.mdmarkdown11.0 KB
references/fl-release.mdmarkdown3.8 KB
references/fl-shared.mdmarkdown3.6 KB
references/fl-validate.mdmarkdown4.5 KB
references/github-profile-rules.mdmarkdown10.5 KB
references/github-profile-rules/references/rule-categories.mdmarkdown6.5 KB
references/hc-SPEC.mdmarkdown3.3 KB
references/hc-domain-playbooks.mdmarkdown15.4 KB
references/hc-ledger.mdmarkdown3.3 KB
references/hc-profiling-tools.mdmarkdown3.7 KB
references/hill-climb.mdmarkdown9.3 KB
references/hook-development-pipeline.mdmarkdown12.9 KB
references/mcp-pipeline-builder.mdmarkdown16.3 KB
references/mcp-pipeline-builder/references/analysis-checklist.mdmarkdown6.2 KB
references/mcp-pipeline-builder/references/design-rules.mdmarkdown7.1 KB
references/mcp-pipeline-builder/references/evaluation-guide.mdmarkdown7.6 KB
references/mcp-pipeline-builder/references/python-scaffold-template.mdmarkdown9.5 KB
references/mcp-pipeline-builder/references/ts-scaffold-template.mdmarkdown1.6 KB
references/mcp-pipeline-builder/scripts/assemble-scaffold.pyscript6.3 KB
references/mcp-pipeline-builder/scripts/register_mcp.pyscript6.9 KB
references/mcp-pipeline-builder/templates/client-cli.ts.tmplother682 B
references/mcp-pipeline-builder/templates/client-http.ts.tmplother1.4 KB
references/mcp-pipeline-builder/templates/index.ts.tmplother1.1 KB
references/mcp-pipeline-builder/templates/package.json.tmplother477 B
references/mcp-pipeline-builder/templates/readme.md.tmplother1.1 KB
references/mcp-pipeline-builder/templates/tools.ts.tmplother3.0 KB
references/mcp-pipeline-builder/templates/ts-scaffold.tmplother556 B
references/mcp-pipeline-builder/templates/tsconfig.json.tmplother408 B
references/ol-SPEC.mdmarkdown2.4 KB
references/ol-state-file.mdmarkdown2.9 KB
references/pipeline-index.jsonconfig23.9 KB
references/pipeline-orchestrator.mdmarkdown15.3 KB
references/pipeline-orchestrator/orchestration-patterns.mdmarkdown8.1 KB
references/pipeline-orchestrator/preferred-patterns.mdmarkdown4.6 KB
references/pipeline-retro.mdmarkdown19.0 KB
references/pipeline-scaffolder.mdmarkdown22.4 KB
references/pipeline-scaffolder/references/architecture-rules.mdmarkdown18.9 KB
references/pipeline-scaffolder/references/generated-skill-template.mdmarkdown1.9 KB
references/pipeline-scaffolder/references/pipeline-spec-format.mdmarkdown36.8 KB
references/pipeline-scaffolder/references/step-menu.mdmarkdown21.5 KB
references/pipeline-scaffolder/scripts/assemble-skill.pyscript6.3 KB
references/pipeline-scaffolder/templates/phases/decision-planning.md.tmplother1.2 KB
references/pipeline-scaffolder/templates/phases/domain-extension.md.tmplother1.5 KB
references/pipeline-scaffolder/templates/phases/generation.md.tmplother427 B
references/pipeline-scaffolder/templates/phases/git-release.md.tmplother1.1 KB
references/pipeline-scaffolder/templates/phases/interaction.md.tmplother965 B
references/pipeline-scaffolder/templates/phases/learning-retro.md.tmplother1.5 KB
references/pipeline-scaffolder/templates/phases/observation.md.tmplother1.3 KB
references/pipeline-scaffolder/templates/phases/research-gathering.md.tmplother1.2 KB
references/pipeline-scaffolder/templates/phases/review.md.tmplother930 B
references/pipeline-scaffolder/templates/phases/safety-guarding.md.tmplother1.7 KB
references/pipeline-scaffolder/templates/phases/structuring.md.tmplother361 B
references/pipeline-scaffolder/templates/phases/synthesis-reporting.md.tmplother1.9 KB
references/pipeline-scaffolder/templates/phases/validation.md.tmplother1.1 KB
references/pipeline-scaffolder/templates/skill-template.md.tmplother12.0 KB
references/pipeline-test-runner.mdmarkdown16.7 KB
references/pl-ambiguity-triage.mdmarkdown2.7 KB
references/pl-check-dimensions.mdmarkdown7.4 KB
references/pl-check-errors.mdmarkdown824 B
references/pl-check-verdict-format.mdmarkdown3.2 KB
references/pl-check.mdmarkdown6.5 KB
references/pl-context-boundary.mdmarkdown1.6 KB
references/pl-depth-first-interview.mdmarkdown11.6 KB
references/pl-empirical-prototype.mdmarkdown825 B
references/pl-executor-ready-plan-template.mdmarkdown7.7 KB
references/pl-human-source-elicitation.mdmarkdown1.5 KB
references/pl-manage.mdmarkdown5.1 KB
references/pl-pause-confirm-and-errors.mdmarkdown2.1 KB
references/pl-pause-extract-decisions.mdmarkdown3.0 KB
references/pl-pause-gather-steps.mdmarkdown2.3 KB
references/pl-pause-synthesize-fields.mdmarkdown2.3 KB
references/pl-pause-write-templates.mdmarkdown5.3 KB
references/pl-pause.mdmarkdown6.5 KB
references/pl-plan-files.mdmarkdown8.4 KB
references/pl-pre-plan.mdmarkdown11.6 KB
references/pl-resume.mdmarkdown12.3 KB
references/pl-spec.mdmarkdown5.2 KB
references/pr-fix-loop.mdmarkdown10.3 KB
references/pr-fix-loop/references/message-formats.mdmarkdown1.6 KB
references/pr-fix-loop/references/publish.mdmarkdown5.4 KB
references/pr-fix-loop/references/review-checklist.mdmarkdown3.4 KB
references/pr-pipeline/references/pr-templates.mdmarkdown5.4 KB
references/pr-pipeline/references/preflight-checklist.mdmarkdown2.8 KB
references/pr-pipeline/references/retro-adr-phases.mdmarkdown2.7 KB
references/pr-pipeline/references/review-fix-loop.mdmarkdown2.0 KB
references/project-coordinator.mdmarkdown6.5 KB
references/project-coordinator/agent-capability-map.mdmarkdown5.4 KB
references/project-coordinator/communication-protocols.mdmarkdown4.5 KB
references/project-coordinator/coordination-playbook.mdmarkdown3.7 KB
references/project-coordinator/death-loop-prevention.mdmarkdown3.6 KB
references/project-coordinator/error-catalog.mdmarkdown2.7 KB
references/project-coordinator/parallel-execution-patterns.mdmarkdown2.8 KB
references/project-coordinator/preferred-patterns.mdmarkdown5.9 KB
references/project-coordinator/todowrite-integration.mdmarkdown5.6 KB
references/research-pipeline.jsscript15.2 KB
references/skill-creation-pipeline.mdmarkdown17.1 KB
references/system-upgrade.mdmarkdown12.8 KB
references/systematic-debugging.mdmarkdown11.0 KB
references/systematic-refactoring.mdmarkdown11.4 KB
references/toolkit-improvement.jsscript39.0 KB
references/toolkit-improvement.mdmarkdown20.5 KB
references/toolkit-improvement/references/adr-template.mdmarkdown10.5 KB
references/toolkit-improvement/references/agent-roster.mdmarkdown15.8 KB
references/workflow-helpers.jsscript12.1 KB
references/workflow-orchestrator.mdmarkdown20.8 KB
references/workflow-orchestrator/references/plan-template.mdmarkdown1.3 KB
references/workflow-orchestrator/references/task-patterns.mdmarkdown23.3 KB
references/workflow-orchestrator/scripts/assemble-plan.pyscript6.9 KB
references/workflow-orchestrator/scripts/validate.pyscript14.4 KB
references/workflow-orchestrator/templates/plan-template.json.tmplother904 B

references/hook-development-pipeline.md

View on GitHub
---
description: "5-phase hook creation pipeline with performance gates."
user-invocable: false
allowed-tools:
  - Read
  - Bash
  - Glob
  - Grep
  - Agent
  - Edit
  - Write
routing:
  triggers:
    - create hook pipeline
    - new hook formal
    - hook with gates
  pairs_with:
    - toolkit
    - systematic-debugging
  complexity: Medium
  category: infrastructure
---

# Hook Development Pipeline

## Overview

This pipeline enforces the full lifecycle of hook creation with three critical gates that prevent silent failures in production:

1. **Spec-before-code gate (Phase 1)**: Hooks fire on every tool use in a live Claude Code session. Decision errors (wrong event type, wrong timing) compound across hundreds of sessions. Phase 1 forces all decisions into a written spec before any code is written. "Should I use PreToolUse or PostToolUse?" must be answered on paper, not in code.

2. **Performance gate (Phase 3)**: A slow hook degrades every tool call permanently. The measured performance test in Phase 3 is mandatory and blocking — if the hook takes ≥50ms, you return to Phase 2 with optimization instructions, no exceptions. "Should be fast" is not the same as "was measured as fast."

3. **Registration gate (Phase 4)**: A hook not wired into `settings.json` is not done. This makes the boundary between "written" and "live" explicit and discoverable.

---

## Instructions

### Phase 1: SPEC

**Goal**: Define the hook contract before writing any code.

Work through the following decisions and record them in a spec block. Do not proceed to Phase 2 until all decisions are made.

**Decision 1 — Event type** (pick one):

| Event | Fires When | Use For |
|-------|-----------|---------|
| `PreToolUse` | Before Claude executes a tool | Block bad calls, inject pre-context |
| `PostToolUse` | After tool returns | Learn from errors, inject post-context |
| `SessionStart` | Session begins | Load context, sync files (use `once: true`) |
| `UserPromptSubmit` | User submits a prompt | Detect complexity, inject skills |
| `Stop` | Session ends | Generate summary, archive |
| `PreCompact` | Before context compression | Archive learnings |

**Constraint**: If you're looking at this table and thinking "both make sense," that's the symptom that needs fixing. PreToolUse and PostToolUse receive different JSON structures at different moments. A hook that fires before a tool runs cannot see the tool's output. A hook that fires after cannot block the call. The event type must map 1:1 to your action type. Spend 2 minutes on this; it prevents half of all hook regressions.

**Decision 2 — Target tools** (if applicable): Which specific tool names trigger logic? Or does the hook respond to all tools?

**Decision 3 — Action type** (pick one or more):

- `block`: Output JSON with `{"decision": "block", "reason": "..."}` to prevent a tool call (PreToolUse only)
- `inject-context`: Output JSON with `{"additionalContext": "..."}` to prepend context before the next prompt
- `learn`: Update a database or file with observed patterns; no output to Claude
- `observe`: Log or record without any output

**Decision 4 — Performance budget**: Default is 50ms hard limit. Is there any reason to expect this hook needs more? If yes, stop and reconsider the design.

**Decision 5 — Once-per-session?**: Should this hook run only once per session (`once: true`)? Applies mainly to SessionStart hooks that load context.

**Decision 6 — External dependencies**: Does the hook import anything outside the Python standard library? **Constraint**: Non-stdlib imports MUST be lazy (inside functions only). Top-level imports add cold-start time and kill the performance budget. If you see `import requests` or `from hooks.lib import learning_db_v2` at the module level, your hook will fail Phase 3. List your dependencies here.

**ADR Session Awareness** (check before proceeding):
If `.adr-session.json` exists, run `python3 ~/.claude/scripts/adr-query.py context --adr {adr_path} --role script-creator` to read hook requirements from the ADR. Include ADR-specified event types, matchers, and behavioral requirements in the spec. Run `adr-query.py list` to check for related ADRs.

**Output**: A spec block like this:

```
HOOK SPEC: {hook-name}
======================
Event:        PostToolUse
Target tools: Edit, Write (or "all tools")
Action:       inject-context — inject fix suggestion when error matches pattern
Performance:  50ms hard limit
Once:         no
Lazy imports: sqlite3 (stdlib, ok), hooks/lib/learning_db_v2.py (local, lazy)
Output format: {"additionalContext": "..."}
```

**Gate**: Spec block written with all six decisions. Proceed to Phase 2.

---

### Phase 2: IMPLEMENT

**Goal**: Write the hook Python file following established patterns.

Dispatch a `general-purpose` worker whose prompt starts "Read ~/.claude/skills/toolkit/references/hook-development.md and follow it", with the spec from Phase 1 as the brief; the worker writes the code. The worker is NOT in pipeline mode and cannot enforce lazy imports or the exit-0 pattern independently — you will validate these in Phase 3.

**Required structure** (verify before accepting Phase 2 output):

1. **Shebang + module docstring** — docstring must state: event type, what the hook does, performance characteristics, dependencies.
2. **Stdlib imports at top level only** — `sys`, `json`, `os` are fine at the top. Everything else: inside functions. This is the performance gate trigger.
3. **Early-exit for non-target tools** — if the hook targets specific tools, check `tool_name` immediately after JSON parse and exit 0 if it doesn't match.
4. **JSON parse with error handling** — wrap `json.loads(sys.stdin.read())` in try/except; on failure, write to debug log and exit 0.
5. **Main logic** — the actual hook behavior.
6. **Exit 0 always** (non-negotiable):
```python
if __name__ == "__main__":
    try:
        main()
    except Exception as e:
        # write to debug log, never raise
        pass
    finally:
        sys.exit(0)
```

**Import pattern for local libs** (lazy, inside the function that needs them):

```python
def _get_db():
    from hooks.lib import learning_db_v2  # lazy import
    return learning_db_v2.open()
```

**Output helpers from `hooks/lib/hook_utils.py`** (if the file exists, prefer these):
- `context_output(text)` — produces `{"additionalContext": text}`
- `empty_output()` — produces `{}`
- `block_output(reason)` — produces `{"decision": "block", "reason": reason}`

**Output**: `hooks/{name}.py` written to disk.

**Gate**: File exists at `hooks/{name}.py`. Proceed to Phase 3.

---

### Phase 3: TEST

**Goal**: Verify performance and correctness. All three checks are required. Any failure returns to Phase 2.

**Check 1 — Syntax**:
```bash
python3 -m py_compile hooks/{name}.py
```
Must complete with exit 0 and no output.

**Check 2 — Non-blocking** (both must exit 0):
```bash
echo '{}' | python3 hooks/{name}.py
echo 'invalid json' | python3 hooks/{name}.py
```
Check with `echo $?` after each. Both must be 0. **Constraint (Blocking Gate)**: If either is non-zero, the hook has an unguarded exit path — return to Phase 2. A crashing hook is worse than no hook. The `finally: sys.exit(0)` block is not optional.

**Check 3 — Performance (MANDATORY hard gate)**:
```bash
time python3 hooks/{name}.py < /dev/null
```
Read the `real` time from the output. **Must be under 50ms.** This is a cold-start measurement — it includes Python interpreter startup, import resolution, and the hook's own logic. **Constraint (Blocking Gate)**: If this check fails, return to Phase 2. No exceptions, no "close enough."

If performance fails:
- Check for any `import X` at module level where X is not `sys`, `json`, `os`, `re`, or other zero-cost stdlib modules.
- Move those imports inside the functions that use them.
- Check if the hook opens a file or DB connection before checking `tool_name` — move those after the early-exit guard.
- Re-run `time python3 hooks/{name}.py < /dev/null` after each change and repeat until you're under 50ms.

**Do not proceed to Phase 4 until all three checks pass.**

**Gate**: All three checks pass. Record measured performance time for Phase 5 documentation. Proceed to Phase 4.

---

### Phase 4: REGISTER

**Goal**: Wire the hook into Claude Code settings so it actually fires. **Constraint**: A hook not registered in `settings.json` is not done. Phase 4 is mandatory.

**Step 1**: Locate the settings file:
```bash
# Project-level (preferred for project-specific hooks)
cat .claude/settings.json

# User-level (for hooks that apply to all projects)
cat ~/.claude/settings.json
```

**Step 2**: Add the hook registration under the correct event type key. Example structure:

```json
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [
          {
            "type": "command",
            "command": "python3 hooks/{name}.py",
            "timeout": 5000
          }
        ]
      }
    ]
  }
}
```

**Timeout defaults** (include in every registration):
- Most hooks: `5000` (5 seconds — generous ceiling above the 50ms target)
- SessionStart hooks: `10000` (10 seconds — loading context can legitimately take longer)
- UserPromptSubmit hooks: `5000`

**Once flag** (add if applicable):
```json
{
  "type": "command",
  "command": "python3 hooks/{name}.py",
  "timeout": 10000,
  "once": true
}
```

**Step 3**: Write the updated settings file with Edit tool. Verify JSON is valid:
```bash
python3 -m json.tool .claude/settings.json > /dev/null
```

**Output**: Settings file updated and valid.

**Gate**: Hook appears in settings.json under the correct event type. JSON validates. Proceed to Phase 5.

---

### Phase 5: DOCUMENT

**Goal**: Make the hook understandable and findable.

**Step 1**: Verify module-level docstring covers all four elements:
- What event it handles
- What it does (one sentence)
- Performance characteristics (measured time from Phase 3)
- Dependencies (if any, note they are lazy-loaded)

If the docstring is missing any element, add it with Edit tool.

**Step 2**: Check for a hooks README or inventory file:
```bash
ls hooks/README* hooks/HOOKS.md hooks/inventory.md 2>/dev/null
```
If one exists, add a one-line entry for the new hook.

**Output**: Docstring complete. README updated (if applicable).

**Gate**: All documentation steps complete or explicitly skipped with reason.

---

## Completion Summary

After Phase 5, produce this summary:

```
HOOK COMPLETE: {name}
=====================
Event:       {event type}
Registered:  {settings file path}
Performance: {measured time}ms (gate: <50ms) ✓
Exit 0:      verified ✓

Files:
  hooks/{name}.py
  {settings file} (updated)

Docs:
  Module docstring: ✓
  README entry: ✓ / skipped (no README found)
  Learning-db: ✓ / skipped (script not available)
```

---

## Error Handling

### Error: Performance gate fails (≥ 50ms)
**Cause**: Top-level imports, eager DB connections, or too much logic before the early-exit check in Phase 3.
**Solution**: 1) Add `import time; t = time.time()` at the very top, `print(time.time() - t, file=sys.stderr)` just before `sys.exit(0)` to profile. 2) Check for any `import X` at module level where X is not `sys`, `json`, `os`, `re`, or other zero-cost stdlib modules. 3) Check if the hook opens a file or DB connection before checking `tool_name` — move those after the early-exit guard. Return to Phase 2 with specific optimization instructions.

### Error: Non-blocking gate fails (exit non-zero)
**Cause**: An unguarded code path that calls `sys.exit(1)`, raises an uncaught exception, or calls `exit()` directly. Common locations: JSON parse without try/except, file open without try/except, missing `finally: sys.exit(0)` in `__main__`.
**Solution**: Identify the specific failure path by running `echo '{}' | python3 hooks/{name}.py; echo $?` and `echo 'invalid json' | python3 hooks/{name}.py; echo $?`. Wrap the failing code path in try/except and ensure the `finally: sys.exit(0)` block exists in `__main__`. Return to Phase 2 with the failure path identified.

### Error: JSON parse fails on settings.json
**Cause**: Settings file has trailing commas, comments, or other non-standard JSON.
**Solution**: Run `python3 -m json.tool .claude/settings.json` to identify the parse error location. Fix the JSON syntax error before proceeding. Do not write a broken settings file.

### Error: Worker produces hook without lazy imports
**Cause**: The Phase 2 hook worker produces top-level imports that violate the performance budget. The worker is not in pipeline mode and may not enforce the lazy-import constraint.
**Solution**: Review the Phase 2 output before accepting it as complete. Move any non-stdlib top-level imports inside the functions that use them. Re-run Phase 3 performance check after refactoring.

---

## References

- [Hook development reference](../../../meta/toolkit/references/hook-development.md) - Loaded by the Phase 2 implementation worker
- [Claude Code Hooks Documentation](https://docs.anthropic.com/en/docs/claude-code/hooks) - Official hooks event types, JSON schemas, and registration format
planning-and-task-breakdownaddyosmani/agent-skillsBreaks work into ordered tasks. Use when you have a spec or clear requirements and need to break work into implementable tasks. Use when a task feels too large to start, when you need to estimate scope, or when parallel work is possible.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
screenpipethedotmack/claude-memSearch screen and audio history recorded by Screenpipe and optionally save selected context into claude-mem. Use when the user asks to recall desktop activity, a meeting, or something seen in another app through Screenpipe.Stars: 118kUpdated Claude CodeCodexVerifiedInstall
contact-widgetnexu-io/open-designSelf-contained floating chat widget with welcome screen, social links, meeting button, and message input. Single HTML file, zero dependencies.Stars: 108kUpdated Claude CodeCodexVerifiedInstall
meeting-notesnexu-io/open-designMeeting notes page — title bar with attendees, agenda checklist, decisions block, action items table with owners + dates, and a "next meeting" footer. Use when the brief mentions "meeting notes", "minutes", "1:1 notes", "all-hands recap", or "会议纪要".Stars: 108kUpdated Claude CodeCodexVerifiedInstall