Commit bcadcac
feat(workflow): Enforce workflow classification via CLAUDE.md (#1686)
* feat(workflow): Enforce workflow classification via CLAUDE.md (#1680)
Problem: Claude consistently ignored workflow instructions even when
explicitly invoked with /ultrathink. Root cause was 4 levels of
indirection (command -> skill -> skill -> workflow) causing context loss.
Solution:
- Add "MANDATORY: Workflow Selection" section to CLAUDE.md
- Create Q&A_WORKFLOW.md (3 steps) for simple questions
- Classify ALL tasks: Q&A, Investigation, or Default workflow
- Deprecate /ultrathink command, ultrathink-orchestrator, default-workflow skills
- Remove all /ultrathink references from CLAUDE.md
Benefits:
- Direct workflow enforcement without skill indirection
- "Always use a workflow" is now enforceable (Q&A for simple questions)
- Workflow classification happens in 3 seconds before any action
- Backward compatibility: deprecated commands still work
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* docs: Add workflow enforcement discovery to DISCOVERIES.md
Documents the root cause (4 levels of indirection) and solution
for issue #1680 where Claude ignored workflow instructions.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* feat(workflow): Add runtime enforcement for DEFAULT_WORKFLOW steps
Implements Issue #1680 - Prevents agents from skipping workflow steps by
enforcing step completion at runtime via hooks.
## Problem
Agents repeatedly skipped workflow steps (Steps 10, 16, 17, 21) despite
Step 0 requiring explicit acknowledgement of all 22 steps. The existing
workflow_tracker.py only logged but never enforced completion.
## Solution
Three-module architecture with fail-open design:
1. **workflow_state.py**: State machine tracking step completion
- Persists to .claude/runtime/workflow/state_{session_id}.json
- Atomic file writes (temp + rename)
- Tracks mandatory steps: {0, 10, 16, 17, 21}
2. **todo_interceptor.py**: Monitors TodoWrite for step tracking
- Detects "Step N:" patterns in todo content
- Validates Step 0 compliance (22 todos required)
- Never blocks - only updates state and warns
3. **workflow_gate.py**: Gates stop hook completion
- Requires Step 21 completion before task ends
- Returns continuation prompt for incomplete workflows
- Fail-open on errors (allows stop rather than blocking)
## Tests
- 56 unit tests covering all three modules
- TDD approach with testing pyramid (60/30/10)
- E2E integration tests verify complete flow
Closes #1680
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix(workflow): Address review feedback for enforcement module
- Simplified regex patterns: consolidated 4 patterns into 1 tolerant pattern
- Added MAX_STEP_NUMBER constant to prevent garbage matches
- Fixed deprecated datetime.utcnow() → datetime.now(timezone.utc)
- Added MAX_DISPLAYED_STEPS constant for continuation prompts
All 56 workflow enforcement tests passing.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* docs(workflow): Add runtime enforcement section to docs
Explains the three-module enforcement system, mandatory steps,
fail-open design, and state file persistence.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Ubuntu <azureuser@azlin-vm-1764012546.ftnmxvem3frujn3lepas045p5c.xx.internal.cloudapp.net>1 parent 84aca90 commit bcadcac
File tree
14 files changed
+2830
-84
lines changed- .claude
- commands/amplihack
- skills
- default-workflow
- ultrathink-orchestrator
- tools/amplihack/hooks
- tests
- workflow
- docs
- tests/unit
14 files changed
+2830
-84
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
5 | 13 | | |
6 | 14 | | |
7 | 15 | | |
| |||
27 | 35 | | |
28 | 36 | | |
29 | 37 | | |
30 | | - | |
| 38 | + | |
31 | 39 | | |
32 | 40 | | |
33 | 41 | | |
| |||
48 | 56 | | |
49 | 57 | | |
50 | 58 | | |
51 | | - | |
52 | | - | |
| 59 | + | |
| 60 | + | |
53 | 61 | | |
54 | 62 | | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
62 | 70 | | |
63 | 71 | | |
64 | | - | |
65 | | - | |
66 | | - | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
67 | 79 | | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | 80 | | |
72 | 81 | | |
73 | 82 | | |
| |||
84 | 93 | | |
85 | 94 | | |
86 | 95 | | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
91 | 100 | | |
92 | 101 | | |
93 | | - | |
94 | | - | |
| 102 | + | |
| 103 | + | |
95 | 104 | | |
96 | | - | |
| 105 | + | |
97 | 106 | | |
98 | 107 | | |
99 | 108 | | |
| |||
178 | 187 | | |
179 | 188 | | |
180 | 189 | | |
181 | | - | |
| 190 | + | |
182 | 191 | | |
183 | 192 | | |
184 | 193 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
9 | 12 | | |
10 | 13 | | |
11 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
6 | 12 | | |
7 | 13 | | |
8 | 14 | | |
| |||
0 commit comments