Agent skill
workflow-state-patterns
Hook-based state machine patterns for multi-phase workflows. Use when designing sequential workflows with quality gates.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/design/workflow-state-patterns-chkim-su-skillmaker
SKILL.md
Workflow State Patterns
Multi-phase workflows need phase enforcement, session continuity, and quality gates. This pattern uses file-based state + hooks.
Quick Start
- Define phases: analyze → plan → execute → verify
- Create state files on phase completion:
.workflow-phase-done - Add PreToolUse hooks to check required state files
- Add PostToolUse hooks to create state files
Core Concept
Phase 1 → [POST HOOK] → .analysis-done
Phase 2 → [POST HOOK] → .plan-approved
Phase 3 → [PRE HOOK checks] → [POST HOOK] → .execution-done
Phase 4 → PASS: cleanup all / FAIL: preserve for retry
State Files
| File | Purpose |
|---|---|
.{workflow}-analysis-done |
Unlocks planning |
.{workflow}-plan-approved |
Unlocks execution |
.{workflow}-execution-done |
Marks modification complete |
.{workflow}-audit-passed |
Final success marker |
Hook Template (Claude Code 1.0.40+)
{
"hooks": {
"PreToolUse": [{
"matcher": "Task",
"hooks": [{
"type": "command",
"command": "python3 scripts/workflow-gate.py",
"timeout": 5
}]
}]
}
}
Gate script checks tool_input.subagent_type and state files.
Best Practices
- Prefix state files -
.refactor-*,.migration-* - gitignore state files - Don't commit workflow state
- Clean up on success - Remove all state files on completion
- Preserve on failure - Keep state for retry capability
References
- Complete Workflow Example - Full 4-phase implementation
- Hook Details - Detailed hook configurations
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?