safeword 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (235) hide show
  1. package/.claude/commands/arch-review.md +32 -0
  2. package/.claude/commands/lint.md +6 -0
  3. package/.claude/commands/quality-review.md +13 -0
  4. package/.claude/commands/setup-linting.md +6 -0
  5. package/.claude/hooks/auto-lint.sh +6 -0
  6. package/.claude/hooks/auto-quality-review.sh +170 -0
  7. package/.claude/hooks/check-linting-sync.sh +17 -0
  8. package/.claude/hooks/inject-timestamp.sh +6 -0
  9. package/.claude/hooks/question-protocol.sh +12 -0
  10. package/.claude/hooks/run-linters.sh +8 -0
  11. package/.claude/hooks/run-quality-review.sh +76 -0
  12. package/.claude/hooks/version-check.sh +10 -0
  13. package/.claude/mcp/README.md +96 -0
  14. package/.claude/mcp/arcade.sample.json +9 -0
  15. package/.claude/mcp/context7.sample.json +7 -0
  16. package/.claude/mcp/playwright.sample.json +7 -0
  17. package/.claude/settings.json +62 -0
  18. package/.claude/skills/quality-reviewer/SKILL.md +190 -0
  19. package/.claude/skills/safeword-quality-reviewer/SKILL.md +13 -0
  20. package/.env.arcade.example +4 -0
  21. package/.env.example +11 -0
  22. package/.gitmodules +4 -0
  23. package/.safeword/SAFEWORD.md +33 -0
  24. package/.safeword/eslint/eslint-base.mjs +101 -0
  25. package/.safeword/guides/architecture-guide.md +404 -0
  26. package/.safeword/guides/code-philosophy.md +174 -0
  27. package/.safeword/guides/context-files-guide.md +405 -0
  28. package/.safeword/guides/data-architecture-guide.md +183 -0
  29. package/.safeword/guides/design-doc-guide.md +165 -0
  30. package/.safeword/guides/learning-extraction.md +515 -0
  31. package/.safeword/guides/llm-instruction-design.md +239 -0
  32. package/.safeword/guides/llm-prompting.md +95 -0
  33. package/.safeword/guides/tdd-best-practices.md +570 -0
  34. package/.safeword/guides/test-definitions-guide.md +243 -0
  35. package/.safeword/guides/testing-methodology.md +573 -0
  36. package/.safeword/guides/user-story-guide.md +237 -0
  37. package/.safeword/guides/zombie-process-cleanup.md +214 -0
  38. package/{templates → .safeword}/hooks/agents-md-check.sh +0 -0
  39. package/{templates → .safeword}/hooks/post-tool.sh +0 -0
  40. package/{templates → .safeword}/hooks/pre-commit.sh +0 -0
  41. package/.safeword/planning/002-user-story-quality-evaluation.md +1840 -0
  42. package/.safeword/planning/003-langsmith-eval-setup-prompt.md +363 -0
  43. package/.safeword/planning/004-llm-eval-test-cases.md +3226 -0
  44. package/.safeword/planning/005-architecture-enforcement-system.md +169 -0
  45. package/.safeword/planning/006-reactive-fix-prevention-research.md +135 -0
  46. package/.safeword/planning/011-cli-ux-vision.md +330 -0
  47. package/.safeword/planning/012-project-structure-cleanup.md +154 -0
  48. package/.safeword/planning/README.md +39 -0
  49. package/.safeword/planning/automation-plan-v2.md +1225 -0
  50. package/.safeword/planning/automation-plan-v3.md +1291 -0
  51. package/.safeword/planning/automation-plan.md +3058 -0
  52. package/.safeword/planning/design/005-cli-implementation.md +343 -0
  53. package/.safeword/planning/design/013-cli-self-contained-templates.md +596 -0
  54. package/.safeword/planning/design/013a-eslint-plugin-suite.md +256 -0
  55. package/.safeword/planning/design/013b-implementation-snippets.md +385 -0
  56. package/.safeword/planning/design/013c-config-isolation-strategy.md +242 -0
  57. package/.safeword/planning/design/code-philosophy-improvements.md +60 -0
  58. package/.safeword/planning/mcp-analysis.md +545 -0
  59. package/.safeword/planning/phase2-subagents-vs-skills-analysis.md +451 -0
  60. package/.safeword/planning/settings-improvements.md +970 -0
  61. package/.safeword/planning/test-definitions/005-cli-implementation.md +1301 -0
  62. package/.safeword/planning/test-definitions/cli-self-contained-templates.md +205 -0
  63. package/.safeword/planning/user-stories/001-guides-review-user-stories.md +1381 -0
  64. package/.safeword/planning/user-stories/003-reactive-fix-prevention.md +132 -0
  65. package/.safeword/planning/user-stories/004-technical-constraints.md +86 -0
  66. package/.safeword/planning/user-stories/005-cli-implementation.md +311 -0
  67. package/.safeword/planning/user-stories/cli-self-contained-templates.md +172 -0
  68. package/.safeword/planning/versioned-distribution.md +740 -0
  69. package/.safeword/prompts/arch-review.md +43 -0
  70. package/.safeword/prompts/quality-review.md +11 -0
  71. package/.safeword/scripts/arch-review.sh +235 -0
  72. package/.safeword/scripts/check-linting-sync.sh +58 -0
  73. package/.safeword/scripts/setup-linting.sh +559 -0
  74. package/.safeword/templates/architecture-template.md +136 -0
  75. package/.safeword/templates/ci/architecture-check.yml +79 -0
  76. package/.safeword/templates/design-doc-template.md +127 -0
  77. package/.safeword/templates/test-definitions-feature.md +100 -0
  78. package/.safeword/templates/ticket-template.md +74 -0
  79. package/.safeword/templates/user-stories-template.md +82 -0
  80. package/.safeword/tickets/001-guides-review-user-stories.md +83 -0
  81. package/.safeword/tickets/002-architecture-enforcement.md +211 -0
  82. package/.safeword/tickets/003-reactive-fix-prevention.md +57 -0
  83. package/.safeword/tickets/004-technical-constraints-in-user-stories.md +39 -0
  84. package/.safeword/tickets/005-cli-implementation.md +248 -0
  85. package/.safeword/tickets/006-flesh-out-skills.md +43 -0
  86. package/.safeword/tickets/007-flesh-out-questioning.md +44 -0
  87. package/.safeword/tickets/008-upgrade-questioning.md +58 -0
  88. package/.safeword/tickets/009-naming-conventions.md +41 -0
  89. package/.safeword/tickets/010-safeword-md-cleanup.md +34 -0
  90. package/.safeword/tickets/011-cursor-setup.md +86 -0
  91. package/.safeword/tickets/README.md +73 -0
  92. package/.safeword/version +1 -0
  93. package/AGENTS.md +59 -0
  94. package/CLAUDE.md +12 -0
  95. package/README.md +347 -0
  96. package/docs/001-cli-implementation-plan.md +856 -0
  97. package/docs/elite-dx-implementation-plan.md +1034 -0
  98. package/framework/README.md +131 -0
  99. package/framework/mcp/README.md +96 -0
  100. package/framework/mcp/arcade.sample.json +8 -0
  101. package/framework/mcp/context7.sample.json +6 -0
  102. package/framework/mcp/playwright.sample.json +6 -0
  103. package/framework/scripts/arch-review.sh +235 -0
  104. package/framework/scripts/check-linting-sync.sh +58 -0
  105. package/framework/scripts/load-env.sh +49 -0
  106. package/framework/scripts/setup-claude.sh +223 -0
  107. package/framework/scripts/setup-linting.sh +559 -0
  108. package/framework/scripts/setup-quality.sh +477 -0
  109. package/framework/scripts/setup-safeword.sh +550 -0
  110. package/framework/templates/ci/architecture-check.yml +78 -0
  111. package/learnings/ai-sdk-v5-breaking-changes.md +178 -0
  112. package/learnings/e2e-test-zombie-processes.md +231 -0
  113. package/learnings/milkdown-crepe-editor-property.md +96 -0
  114. package/learnings/prosemirror-fragment-traversal.md +119 -0
  115. package/package.json +19 -43
  116. package/packages/cli/AGENTS.md +1 -0
  117. package/packages/cli/ARCHITECTURE.md +279 -0
  118. package/packages/cli/package.json +51 -0
  119. package/packages/cli/src/cli.ts +63 -0
  120. package/packages/cli/src/commands/check.ts +166 -0
  121. package/packages/cli/src/commands/diff.ts +209 -0
  122. package/packages/cli/src/commands/reset.ts +190 -0
  123. package/packages/cli/src/commands/setup.ts +325 -0
  124. package/packages/cli/src/commands/upgrade.ts +163 -0
  125. package/packages/cli/src/index.ts +3 -0
  126. package/packages/cli/src/templates/config.ts +58 -0
  127. package/packages/cli/src/templates/content.ts +18 -0
  128. package/packages/cli/src/templates/index.ts +12 -0
  129. package/packages/cli/src/utils/agents-md.ts +66 -0
  130. package/packages/cli/src/utils/fs.ts +179 -0
  131. package/packages/cli/src/utils/git.ts +124 -0
  132. package/packages/cli/src/utils/hooks.ts +29 -0
  133. package/packages/cli/src/utils/output.ts +60 -0
  134. package/packages/cli/src/utils/project-detector.test.ts +185 -0
  135. package/packages/cli/src/utils/project-detector.ts +44 -0
  136. package/packages/cli/src/utils/version.ts +28 -0
  137. package/packages/cli/src/version.ts +6 -0
  138. package/packages/cli/templates/SAFEWORD.md +776 -0
  139. package/packages/cli/templates/doc-templates/architecture-template.md +136 -0
  140. package/packages/cli/templates/doc-templates/design-doc-template.md +134 -0
  141. package/packages/cli/templates/doc-templates/test-definitions-feature.md +131 -0
  142. package/packages/cli/templates/doc-templates/ticket-template.md +82 -0
  143. package/packages/cli/templates/doc-templates/user-stories-template.md +92 -0
  144. package/packages/cli/templates/guides/architecture-guide.md +423 -0
  145. package/packages/cli/templates/guides/code-philosophy.md +195 -0
  146. package/packages/cli/templates/guides/context-files-guide.md +457 -0
  147. package/packages/cli/templates/guides/data-architecture-guide.md +200 -0
  148. package/packages/cli/templates/guides/design-doc-guide.md +171 -0
  149. package/packages/cli/templates/guides/learning-extraction.md +552 -0
  150. package/packages/cli/templates/guides/llm-instruction-design.md +248 -0
  151. package/packages/cli/templates/guides/llm-prompting.md +102 -0
  152. package/packages/cli/templates/guides/tdd-best-practices.md +615 -0
  153. package/packages/cli/templates/guides/test-definitions-guide.md +334 -0
  154. package/packages/cli/templates/guides/testing-methodology.md +618 -0
  155. package/packages/cli/templates/guides/user-story-guide.md +256 -0
  156. package/packages/cli/templates/guides/zombie-process-cleanup.md +219 -0
  157. package/packages/cli/templates/hooks/agents-md-check.sh +27 -0
  158. package/packages/cli/templates/hooks/post-tool.sh +4 -0
  159. package/packages/cli/templates/hooks/pre-commit.sh +10 -0
  160. package/packages/cli/templates/prompts/arch-review.md +43 -0
  161. package/packages/cli/templates/prompts/quality-review.md +10 -0
  162. package/packages/cli/templates/skills/safeword-quality-reviewer/SKILL.md +207 -0
  163. package/packages/cli/tests/commands/check.test.ts +129 -0
  164. package/packages/cli/tests/commands/cli.test.ts +89 -0
  165. package/packages/cli/tests/commands/diff.test.ts +115 -0
  166. package/packages/cli/tests/commands/reset.test.ts +310 -0
  167. package/packages/cli/tests/commands/self-healing.test.ts +170 -0
  168. package/packages/cli/tests/commands/setup-blocking.test.ts +71 -0
  169. package/packages/cli/tests/commands/setup-core.test.ts +135 -0
  170. package/packages/cli/tests/commands/setup-git.test.ts +139 -0
  171. package/packages/cli/tests/commands/setup-hooks.test.ts +334 -0
  172. package/packages/cli/tests/commands/setup-linting.test.ts +189 -0
  173. package/packages/cli/tests/commands/setup-noninteractive.test.ts +80 -0
  174. package/packages/cli/tests/commands/setup-templates.test.ts +181 -0
  175. package/packages/cli/tests/commands/upgrade.test.ts +215 -0
  176. package/packages/cli/tests/helpers.ts +243 -0
  177. package/packages/cli/tests/npm-package.test.ts +83 -0
  178. package/packages/cli/tests/technical-constraints.test.ts +96 -0
  179. package/packages/cli/tsconfig.json +25 -0
  180. package/packages/cli/tsup.config.ts +11 -0
  181. package/packages/cli/vitest.config.ts +23 -0
  182. package/promptfoo.yaml +3270 -0
  183. package/dist/check-M73LGONJ.js +0 -129
  184. package/dist/check-M73LGONJ.js.map +0 -1
  185. package/dist/chunk-2XWIUEQK.js +0 -190
  186. package/dist/chunk-2XWIUEQK.js.map +0 -1
  187. package/dist/chunk-GZRQL3SX.js +0 -146
  188. package/dist/chunk-GZRQL3SX.js.map +0 -1
  189. package/dist/chunk-V5G6BGOK.js +0 -26
  190. package/dist/chunk-V5G6BGOK.js.map +0 -1
  191. package/dist/chunk-W66Z3C5H.js +0 -21
  192. package/dist/chunk-W66Z3C5H.js.map +0 -1
  193. package/dist/cli.d.ts +0 -1
  194. package/dist/cli.js +0 -34
  195. package/dist/cli.js.map +0 -1
  196. package/dist/diff-FSFDCBL5.js +0 -166
  197. package/dist/diff-FSFDCBL5.js.map +0 -1
  198. package/dist/index.d.ts +0 -11
  199. package/dist/index.js +0 -7
  200. package/dist/index.js.map +0 -1
  201. package/dist/reset-3ACTIYYE.js +0 -143
  202. package/dist/reset-3ACTIYYE.js.map +0 -1
  203. package/dist/setup-MKVVQTVA.js +0 -266
  204. package/dist/setup-MKVVQTVA.js.map +0 -1
  205. package/dist/upgrade-FQOL6AF5.js +0 -134
  206. package/dist/upgrade-FQOL6AF5.js.map +0 -1
  207. /package/{templates → framework}/SAFEWORD.md +0 -0
  208. /package/{templates → framework}/guides/architecture-guide.md +0 -0
  209. /package/{templates → framework}/guides/code-philosophy.md +0 -0
  210. /package/{templates → framework}/guides/context-files-guide.md +0 -0
  211. /package/{templates → framework}/guides/data-architecture-guide.md +0 -0
  212. /package/{templates → framework}/guides/design-doc-guide.md +0 -0
  213. /package/{templates → framework}/guides/learning-extraction.md +0 -0
  214. /package/{templates → framework}/guides/llm-instruction-design.md +0 -0
  215. /package/{templates → framework}/guides/llm-prompting.md +0 -0
  216. /package/{templates → framework}/guides/tdd-best-practices.md +0 -0
  217. /package/{templates → framework}/guides/test-definitions-guide.md +0 -0
  218. /package/{templates → framework}/guides/testing-methodology.md +0 -0
  219. /package/{templates → framework}/guides/user-story-guide.md +0 -0
  220. /package/{templates → framework}/guides/zombie-process-cleanup.md +0 -0
  221. /package/{templates → framework}/prompts/arch-review.md +0 -0
  222. /package/{templates → framework}/prompts/quality-review.md +0 -0
  223. /package/{templates/skills/safeword-quality-reviewer → framework/skills/quality-reviewer}/SKILL.md +0 -0
  224. /package/{templates/doc-templates → framework/templates}/architecture-template.md +0 -0
  225. /package/{templates/doc-templates → framework/templates}/design-doc-template.md +0 -0
  226. /package/{templates/doc-templates → framework/templates}/test-definitions-feature.md +0 -0
  227. /package/{templates/doc-templates → framework/templates}/ticket-template.md +0 -0
  228. /package/{templates/doc-templates → framework/templates}/user-stories-template.md +0 -0
  229. /package/{templates → packages/cli/templates}/commands/arch-review.md +0 -0
  230. /package/{templates → packages/cli/templates}/commands/lint.md +0 -0
  231. /package/{templates → packages/cli/templates}/commands/quality-review.md +0 -0
  232. /package/{templates → packages/cli/templates}/hooks/inject-timestamp.sh +0 -0
  233. /package/{templates → packages/cli/templates}/lib/common.sh +0 -0
  234. /package/{templates → packages/cli/templates}/lib/jq-fallback.sh +0 -0
  235. /package/{templates → packages/cli/templates}/markdownlint.jsonc +0 -0
@@ -0,0 +1,1291 @@
1
+ # Claude Code Automation Plan v3: Quality Control Workflow
2
+
3
+ ## THE GOAL
4
+
5
+ **Problem**: You repeat the same cycle 100+ times per project:
6
+
7
+ ```
8
+ Your workflow pattern (discovered from conversation logs):
9
+
10
+ 1. You: "double check and critique [X]. is it correct? elegant? best practices? avoid bloat."
11
+ → Claude: [finds 5 issues, proposes fixes] {"proposedChanges": true, "madeChanges": false}
12
+
13
+ 2. You: "make all your suggested changes" (or "yes please")
14
+ → Claude: [implements all 5 fixes] {"proposedChanges": false, "madeChanges": true}
15
+
16
+ 3. You: "double check and critique again. correct? elegant? avoid bloat."
17
+ → Loop back to step 1
18
+
19
+ Total keystrokes per cycle: ~180 characters × 100 cycles = 18,000 characters per project
20
+ ```
21
+
22
+ **Your most frequent prompts** (from chat/soulless-monorepo conversation logs):
23
+
24
+ - "make all your suggested changes" (3 instances with typo "yuour")
25
+ - "yes please" (5 instances)
26
+ - "double check and critique [X]. is it correct? elegant? does it follow best practices? avoid bloat." (10+ variations)
27
+ - "check" or "check." (shorthand for critique)
28
+
29
+ **Goal**: Eliminate the manual "make changes → critique" loop using automated hooks.
30
+
31
+ **Solution**: PostToolUse hook detects `{"madeChanges": true}` responses, auto-runs tests, auto-commits, and auto-triggers critique. Implementation Cycle Manager Skill detects `{"proposedChanges": true}` and offers to implement immediately.
32
+
33
+ **Success Criteria**:
34
+
35
+ - **Phase 1**: 60% reduction in prompt length (180 → 72 chars via slash commands)
36
+ - **Phase 2**: 95% reduction in cycle prompts (100 cycles → 5 manual interventions per project)
37
+ - **Reality check**: Skills activate 50-70% of time, NOT 100% - `/implement` fallback needed 30-50%
38
+
39
+ **Based on**: Analysis of 1,319 messages (soulless-monorepo) + 8,732 messages (bitd) + chat project logs
40
+
41
+ - 7% of soulless-monorepo prompts = quality control rituals
42
+ - Most frequent user prompts identified: "make all your suggested changes", "yes please", "double check and critique"
43
+
44
+ **Updated**: 2025-11-01 - v3: Added JSON response tracking workflow automation, exact prompt pattern matching
45
+
46
+ ---
47
+
48
+ ## 🚨 CRITICAL WARNINGS - READ FIRST
49
+
50
+ ### Warning 1: Hooks Broken in Current Versions
51
+
52
+ **AS OF 2025-10-30: All hooks silently fail in Claude Code v2.0.27 and later (including v2.0.30)**
53
+
54
+ **Issue status**: GitHub Issue #10399 - **Still OPEN** (not fixed yet)
55
+
56
+ **Affected versions**: v2.0.27, v2.0.28, v2.0.29, v2.0.30+ (likely all versions until fix released)
57
+
58
+ **Check your version**:
59
+
60
+ ```bash
61
+ claude --version
62
+ ```
63
+
64
+ **Workaround** (required for Phase 2 - hooks won't work otherwise):
65
+
66
+ ```bash
67
+ # Launch with debug flag every time
68
+ claude --debug
69
+
70
+ # Or create permanent alias
71
+ alias claude='claude --debug'
72
+ ```
73
+
74
+ **Test hooks work before Phase 2**:
75
+
76
+ ```bash
77
+ # Create test hook
78
+ mkdir -p ~/.claude/hooks
79
+ echo '#!/bin/bash' > ~/.claude/hooks/test.sh
80
+ echo 'echo "🎉 Hook fired!"' >> ~/.claude/hooks/test.sh
81
+ chmod +x ~/.claude/hooks/test.sh
82
+
83
+ # Add to settings.json
84
+ jq '.hooks.Stop = [{matcher: "*", hooks: [{type: "command", command: "~/.claude/hooks/test.sh"}]}]' ~/.claude/settings.json > tmp.json && mv tmp.json ~/.claude/settings.json
85
+
86
+ # Test with debug flag
87
+ claude --debug
88
+ # (Ask Claude something, should see "🎉 Hook fired!" when it finishes)
89
+ # If you DON'T see "🎉 Hook fired!", hooks are still broken - don't proceed to Phase 2
90
+ ```
91
+
92
+ **Impact**: Phase 2 requires `--debug` workaround or downgrade to v2.0.25. Phase 1 unaffected.
93
+
94
+ **Source**: [GitHub Issue #10399](https://github.com/anthropics/claude-code/issues/10399) (still open)
95
+
96
+ ---
97
+
98
+ ### Warning 2: Skills Don't Activate Reliably
99
+
100
+ **Reality**: Skills activation rate = 50-70% typical, NOT 100%
101
+
102
+ **What this means**:
103
+
104
+ - ❌ You CANNOT eliminate 100% of quality check prompts
105
+ - ✅ You CAN reduce by 50-70% (still need manual checks 30-50% of time)
106
+
107
+ **Why Skills fail to activate**:
108
+
109
+ - Vague descriptions (Claude doesn't know when to use them)
110
+ - Missing trigger keywords (no pattern matching)
111
+ - Description >1024 chars (reduces reliability)
112
+ - Unpredictable behavior (works perfectly for days, then stops)
113
+
114
+ **Mitigation**: Always provide Slash Command alternatives for manual invocation when Skills don't fire.
115
+
116
+ **Community quote**: "The #1 problem with Claude Code skills is they don't activate on their own. They just sit there and you have to remember to use them."
117
+
118
+ ---
119
+
120
+ ## Recommended Approach: 2 Phases
121
+
122
+ | Phase | Mechanisms | Impact | Effort | Status |
123
+ | ----------- | -------------------------- | -------------------- | ------- | -------------------------- |
124
+ | **Phase 1** | Slash Commands + CLAUDE.md | 60% prompt reduction | 30 min | ⭐ START HERE |
125
+ | **Phase 2** | 2 Skills + 1-2 Hooks | 50-70% automation | 2 hours | ⭐ IF PHASE 1 INSUFFICIENT |
126
+
127
+ **Why 2 phases, not 5**:
128
+
129
+ - Test Phase 1 for 1 week before building Phase 2
130
+ - Iterate based on real usage patterns
131
+ - Avoid over-engineering (automation anti-pattern)
132
+
133
+ **Agentic coding best practice (2025 research)**: "Guide yields better outcomes than pure autonomy. Ask for a plan first."
134
+
135
+ **Why NOT more**:
136
+
137
+ - ❌ Subagents: Too slow (context switching), lack conversation history
138
+ - ❌ MCP Servers: External dependencies, cost, no conversation context
139
+
140
+ ---
141
+
142
+ ## Phase 1: Slash Commands + CLAUDE.md (START HERE)
143
+
144
+ **Goal**: Immediate 60% reduction in repetitive prompts
145
+
146
+ **Effort**: 30 minutes
147
+
148
+ **Impact**: Replaces 250-char prompt with 10-char command
149
+
150
+ **Pros**:
151
+
152
+ - ✅ Works immediately (no complex setup)
153
+ - ✅ Easy to test and iterate
154
+ - ✅ No risk of automation misbehaving
155
+ - ✅ Foundation for Phase 2
156
+
157
+ **Cons**:
158
+
159
+ - ❌ Still requires manual invocation (not automatic)
160
+
161
+ ---
162
+
163
+ ### 1.1: Slash Commands (20 min)
164
+
165
+ **Create in ONE of these locations**:
166
+
167
+ **Personal commands** (available in all projects):
168
+ `~/.claude/commands/critique.md`
169
+
170
+ **Project commands** (shared with team via git):
171
+ `.claude/commands/critique.md`
172
+
173
+ **Recommendation**: Start with personal (~/.claude), move to project later if team needs them.
174
+
175
+ ---
176
+
177
+ #### Command 1: `/critique` (PRIMARY)
178
+
179
+ **File**: `~/.claude/commands/critique.md`
180
+
181
+ ```markdown
182
+ ---
183
+ description: Run quality critique on current work
184
+ ---
185
+
186
+ Double check and critique your work again just in case.
187
+
188
+ Evaluate against these criteria:
189
+
190
+ 1. **Correctness**
191
+ - Will it actually work?
192
+ - Edge cases handled?
193
+ - Error handling complete?
194
+
195
+ 2. **Elegance**
196
+ - Simplest solution possible?
197
+ - Any bloat or over-engineering?
198
+ - Readable and maintainable?
199
+
200
+ 3. **Standards Adherence**
201
+ - Follows project CLAUDE.md conventions?
202
+ - Matches existing code patterns?
203
+ - Latest best practices for: $ARGUMENTS
204
+
205
+ 4. **Testing**
206
+ - Can we test this?
207
+ - Test strategy clear?
208
+
209
+ Ask any non-obvious questions you need answered that you can't research yourself online or in the codebase. Don't be lazy.
210
+
211
+ Provide your critique, then wait for approval before implementing.
212
+ ```
213
+
214
+ **Usage**:
215
+
216
+ - `/critique react typescript blades`
217
+ - `/critique electron desktop-app`
218
+
219
+ ---
220
+
221
+ #### Command 2: `/latest-docs` (DOCUMENTATION LOOKUP)
222
+
223
+ **File**: `~/.claude/commands/latest-docs.md`
224
+
225
+ ```markdown
226
+ ---
227
+ description: Look up latest documentation before proceeding
228
+ ---
229
+
230
+ Before proceeding, look up the very latest documentation for: $ARGUMENTS
231
+
232
+ For each library/framework, verify:
233
+
234
+ - API compatibility with our version (check package.json)
235
+ - Best practices haven't changed since your training data
236
+ - No deprecated patterns in our current approach
237
+ - New features that might be better
238
+
239
+ Then provide your findings and continue with your recommendation.
240
+ ```
241
+
242
+ **Usage**:
243
+
244
+ - `/latest-docs @anthropic/sdk react-19`
245
+ - `/latest-docs playwright zustand`
246
+
247
+ ---
248
+
249
+ #### Command 3: `/check-and-proceed` (ONE-SHOT)
250
+
251
+ **File**: `~/.claude/commands/check-and-proceed.md`
252
+
253
+ ```markdown
254
+ ---
255
+ description: Quality check then immediate implementation
256
+ ---
257
+
258
+ Run full quality verification, then implement if passing:
259
+
260
+ **STEP 1: Quality Check**
261
+
262
+ - Correct? Elegant? Standards-compliant?
263
+ - Latest docs verified?
264
+ - Tests planned?
265
+ - Bloat avoided?
266
+
267
+ **STEP 2: If all checks pass**
268
+
269
+ - Implement immediately (approval implicit)
270
+ - Run tests
271
+ - Report results
272
+
273
+ **STEP 3: If issues found**
274
+
275
+ - List concerns
276
+ - Wait for user guidance
277
+
278
+ This is a "one-shot" command - check thoroughly, then proceed automatically if confident.
279
+ ```
280
+
281
+ **Usage**: `/check-and-proceed` (combines critique + approval + implementation)
282
+
283
+ ---
284
+
285
+ #### Command 4: `/implement` (FALLBACK FOR WHEN SKILLS DON'T ACTIVATE)
286
+
287
+ **File**: `~/.claude/commands/implement.md`
288
+
289
+ ```markdown
290
+ ---
291
+ description: Implement all proposed changes from previous response
292
+ ---
293
+
294
+ Implement all changes you proposed in your previous response.
295
+
296
+ After implementing:
297
+
298
+ - Use Write/Edit tools for all changes
299
+ - PostToolUse hook will automatically:
300
+ - Run tests (for code changes)
301
+ - Commit changes
302
+ - Trigger critique
303
+
304
+ Respond with your critique results and final JSON status.
305
+ ```
306
+
307
+ **Usage**:
308
+
309
+ - When Claude responds with `{"proposedChanges": true}` but doesn't offer to implement
310
+ - Type `/implement` instead of "make all your suggested changes"
311
+ - Saves typing, consistent trigger
312
+
313
+ **Why this exists**:
314
+
315
+ - Skills activate 50-70% of time (not 100%)
316
+ - When Implementation Cycle Manager Skill doesn't activate, use `/implement` as manual fallback
317
+ - Still saves keystrokes: `/implement` (10 chars) vs "make all your suggested changes" (29 chars)
318
+
319
+ **Fallback strategy**:
320
+
321
+ ```
322
+ Best case: Skill activates (50-70%) → Offers to implement → User says "yes" → Implements
323
+ Fallback: Skill doesn't activate (30-50%) → User types `/implement` → Implements
324
+
325
+ Both paths → PostToolUse hook → tests + commit + critique
326
+ ```
327
+
328
+ ---
329
+
330
+ ### 1.2: Enhanced CLAUDE.md (10 min)
331
+
332
+ **Add to ONE of these files**:
333
+
334
+ **Personal** (all projects): `~/.claude/CLAUDE.md`
335
+ **Project-wide** (shared with team): `CLAUDE.md` in project root
336
+ **Project-local** (your settings only): `CLAUDE.local.md` in project root (add to .gitignore)
337
+
338
+ **Recommendation**: Start with personal (~/.claude/CLAUDE.md)
339
+
340
+ ---
341
+
342
+ **Add this content**:
343
+
344
+ ```markdown
345
+ ## Quality Standards (CRITICAL - Always Follow)
346
+
347
+ ### 0. Explore → Plan → Code → Commit Workflow
348
+
349
+ **EXPLORE**: Read relevant files, understand patterns (no code yet)
350
+ **PLAN**: Create plan, get approval
351
+ **CODE**: Implement, run tests, report results
352
+ **COMMIT**: Commit with message, create PR if needed
353
+
354
+ **Skip only if**: Trivial changes (typos, formatting) or user says "just do it"
355
+
356
+ **Agentic best practice**: "Ask for a plan first" yields better outcomes than jumping to code.
357
+
358
+ ---
359
+
360
+ ### 1. Latest Documentation Check
361
+
362
+ **IMPORTANT**: NEVER assume API compatibility. Training cutoff: January 2025.
363
+
364
+ **Process**:
365
+
366
+ - Identify libraries/frameworks used
367
+ - Check package.json for versions
368
+ - Look up latest docs (WebFetch/WebSearch)
369
+ - Verify API still works as expected
370
+ - Note deprecated patterns
371
+ - Report findings before proposing
372
+
373
+ ---
374
+
375
+ ### 2. Self-Critique Against Quality Criteria
376
+
377
+ Every proposal must pass:
378
+
379
+ **Correctness**: Works? Edge cases? Errors? Type-safe?
380
+
381
+ **Elegance**: Simplest solution? Any bloat? Readable?
382
+
383
+ **Standards**: Matches CLAUDE.md? Follows patterns? File organization?
384
+
385
+ **Testability**: Can write tests? Strategy clear?
386
+
387
+ ---
388
+
389
+ ### 3. Output Format
390
+ ```
391
+
392
+ PROPOSAL: [What to implement]
393
+ QUALITY CHECK: ✓ Docs | ✓ Correct | ✓ Elegant | ✓ Standards | ✓ Testable [reasoning]
394
+ CONCERNS: [Trade-offs if any]
395
+ READY FOR APPROVAL
396
+
397
+ ```
398
+
399
+ ---
400
+
401
+ ### 4. When User Approves
402
+
403
+ **YOU MUST**: When user says "yes"/"proceed"/"implement":
404
+ 1. ✓ Execute immediately (approval given)
405
+ 2. ✓ Run relevant tests after implementation
406
+ 3. ✓ Report test results
407
+ 4. ✓ Only then mark complete
408
+
409
+ Do not ask for approval again or skip tests.
410
+
411
+ ---
412
+
413
+ ### 5. Non-Obvious Questions Only
414
+
415
+ Ask ONLY if: Multiple valid approaches, domain knowledge needed, breaking changes, can't find answer after search.
416
+
417
+ DON'T ask: Questions in docs, implementation details, preferences in CLAUDE.md, standard practices.
418
+
419
+ ---
420
+
421
+ ### 6. Avoid Bloat
422
+
423
+ **Red flags**:
424
+ - Adding dependencies when stdlib sufficient
425
+ - Over-abstraction (framework for 1 use case)
426
+ - Premature optimization (no performance issue)
427
+ - Duplicating existing functionality
428
+
429
+ **Principle**: Simplest solution that solves the problem.
430
+
431
+ ---
432
+
433
+ ### 7. Context Management
434
+
435
+ **CRITICAL**: Use `/clear` frequently to prevent "dumber after compaction" issue.
436
+
437
+ **Use /clear**: After completing task, switching topics, when unfocused
438
+ **Don't use /clear**: Mid multi-step task, during active debugging
439
+
440
+ ---
441
+
442
+ ### 8. Testing Standards
443
+
444
+ **After any code changes**:
445
+ - Run existing test suite
446
+ - Report results before completion
447
+ - If tests fail: fix them (don't ask user)
448
+
449
+ For TDD workflow: See `@./.safeword/guides/testing-methodology.md`
450
+ ```
451
+
452
+ **Pro tip**: During coding, press **#** and type an instruction. Claude will automatically add it to the relevant CLAUDE.md file for you.
453
+
454
+ ---
455
+
456
+ ### Phase 1 Testing
457
+
458
+ **Test in both projects** (soulless-monorepo, bitd):
459
+
460
+ 1. Make small change proposal
461
+ 2. Type `/critique [stack]`
462
+ 3. Verify comprehensive review appears
463
+ 4. Type `/check-and-proceed`
464
+ 5. Verify one-shot execution
465
+
466
+ **Pass criteria**:
467
+
468
+ - Commands work reliably
469
+ - Save typing (250 → 10 chars)
470
+ - Maintain quality
471
+
472
+ **Measure after 1 week**:
473
+
474
+ - How often do you use slash commands?
475
+ - Is prompt length reduced?
476
+ - Is quality maintained?
477
+
478
+ **Then decide**: Is Phase 2 needed, or is this sufficient?
479
+
480
+ ---
481
+
482
+ ## Phase 2: Skills + Hooks (IF PHASE 1 INSUFFICIENT)
483
+
484
+ **⚠️ Prerequisites**:
485
+
486
+ - ✓ Phase 1 tested for 1 week
487
+ - ✓ Phase 1 proves insufficient (still too much manual work)
488
+ - ✓ Hooks verified working (see Critical Warning above)
489
+
490
+ **Goal**: 50-70% reduction in quality check prompts (NOT 100% - see Warning 2)
491
+
492
+ **Effort**: 2 hours
493
+
494
+ **Impact**: Auto-invoked checks (when Skills activate) + post-code validation
495
+
496
+ **Reality check**:
497
+
498
+ - Skills activate 50-70% of time
499
+ - Manual fallback needed 30-50% (use slash commands)
500
+ - Description tuning requires iteration
501
+
502
+ ---
503
+
504
+ ### 2.1: Recommended Skills (Choose 1-2)
505
+
506
+ **Start with 1-2 Skills, NOT all at once**. Add 3rd only if first 2 working well.
507
+
508
+ **Option A: Docs Verifier** - Check latest docs before proposing code
509
+ **Option B: Quality Gates** - Final review before Write/Edit tools
510
+
511
+ **Anthropic 2025 guidance**: "Keep Skills lean" - focused descriptions <1024 chars
512
+
513
+ **LLM research 2025**: Progressive disclosure - load details when Skill invoked, not in description
514
+
515
+ **What to load when Skill invoked**:
516
+
517
+ - **Docs Verifier** - Full protocol for library version checking and API deprecation detection
518
+ - **Quality Gates** - Edge case checklist (null, empty, boundary values) + bloat patterns + CLAUDE.md conventions
519
+ - **Implementation Cycle Manager** - Protocol for detecting proposals, asking confirmation, and implementing changes
520
+
521
+ ---
522
+
523
+ ### Skill 1: Docs Verifier (30 min)
524
+
525
+ **File**: `~/.claude/skills/docs-verifier/SKILL.md`
526
+
527
+ ```yaml
528
+ ---
529
+ name: docs-verifier
530
+ description: |
531
+ Check latest documentation before proposing code changes.
532
+
533
+ Use PROACTIVELY when:
534
+ - About to propose implementation using external libraries
535
+ - User mentions library/framework names (react, electron, vitest, etc.)
536
+ - Writing code that calls external APIs
537
+
538
+ DO NOT use for:
539
+ - Standard library features (Array.map, Promise, console.log)
540
+ - Reading/exploring code without proposing changes
541
+
542
+ Returns: VERIFIED / DEPRECATED / VERSION_MISMATCH
543
+
544
+ (See below for full verification protocol)
545
+
546
+ allowed-tools: Read, WebFetch, WebSearch
547
+ ---
548
+
549
+ # Documentation Verification Protocol
550
+
551
+ **Process**:
552
+ 1. Read package.json for library versions
553
+ 2. WebSearch "[library] v[version] documentation"
554
+ 3. Check for deprecated APIs: "[library] deprecated [version]"
555
+ 4. Return structured output
556
+
557
+ **Example output**:
558
+ ```
559
+
560
+ DOCS VERIFICATION:
561
+ ✓ react v18.3.1 - API unchanged
562
+ ⚠️ electron v32 - ipcRenderer.sendSync deprecated, use invoke
563
+ ✗ zustand - Project uses v3, docs for v4 (VERSION_MISMATCH)
564
+
565
+ RECOMMENDATION: PROCEED / UPDATE_LIBRARY / FIX_DEPRECATED
566
+
567
+ ```
568
+
569
+ **Edge cases**:
570
+ - No package.json: Search "[library] latest documentation"
571
+ - Monorepo: Check package.json in nearest parent or specific package
572
+ - Version mismatch: Warn if docs are newer/older than installed version
573
+ ```
574
+
575
+ **Supporting file** (optional): `~/.claude/skills/docs-verifier/examples.md` (loaded only when Skill runs)
576
+
577
+ **Activation test**:
578
+
579
+ ```
580
+ You: "Let's add a new feature using react hooks"
581
+ Expected: Docs Verifier Skill activates, checks react docs
582
+ ```
583
+
584
+ ---
585
+
586
+ ### Skill 2: Quality Gates (30 min)
587
+
588
+ **File**: `~/.claude/skills/quality-gates/SKILL.md`
589
+
590
+ ```yaml
591
+ ---
592
+ name: quality-gates
593
+ description: |
594
+ Final review before Write/Edit for .ts/.tsx/.js/.jsx files.
595
+
596
+ Use when ABOUT TO:
597
+ - Write/Edit source files (not config/docs)
598
+ - User approves implementation ("yes", "proceed", "implement")
599
+
600
+ Checks: Edge cases (null, undefined, empty), bloat (simplest solution), standards (CLAUDE.md patterns)
601
+
602
+ Returns: PROCEED / REVISE / USER_INPUT
603
+
604
+ (See below for full review protocol)
605
+
606
+ allowed-tools: Read, Grep, Glob
607
+ ---
608
+
609
+ # Quality Gates Review Protocol
610
+
611
+ **Check proposed code for**:
612
+ 1. **Edge cases**: Null/undefined, empty arrays/objects/strings, boundary values (0, -1, MAX_INT), async errors, race conditions
613
+ 2. **Bloat**: Simplest solution? Unnecessary dependencies/abstractions? Premature optimization?
614
+ 3. **Standards**: Read project CLAUDE.md for file organization, naming conventions, coding patterns
615
+
616
+ **Return one of**:
617
+ - PROCEED (all checks pass)
618
+ - REVISE (list specific issues to fix)
619
+ - USER_INPUT (need user decision)
620
+
621
+ **Example output**:
622
+ ```
623
+
624
+ QUALITY GATES:
625
+ ✓ Edge cases: Handles null, empty, errors
626
+ ✗ Bloat: Adds lodash just for \_.isEmpty
627
+ ✓ Standards: Follows naming conventions
628
+
629
+ RECOMMENDATION: REVISE
630
+
631
+ - Replace lodash: Object.keys(obj).length === 0
632
+
633
+ ```
634
+
635
+ ```
636
+
637
+ **Activation test**:
638
+
639
+ ```
640
+ You: "Let's implement the login handler"
641
+ Expected: Quality Gates Skill activates, checks edge cases/bloat/standards
642
+ ```
643
+
644
+ ---
645
+
646
+ ### Skill 3: Implementation Cycle Manager (30 min)
647
+
648
+ **File**: `~/.claude/skills/implementation-cycle/SKILL.md`
649
+
650
+ ```yaml
651
+ ---
652
+ name: implementation-cycle-manager
653
+ description: |
654
+ Detects when you've proposed changes (proposedChanges true) and offers to implement them immediately.
655
+
656
+ Use when YOU JUST:
657
+ - Responded with proposals/suggestions/fixes
658
+ - Listed changes to make
659
+ - Found issues in critique
660
+ - Responded with {"proposedChanges": true}
661
+
662
+ Eliminates user typing "make all your suggested changes" or "yes please".
663
+
664
+ Returns: Asks user "Should I implement all suggested changes now?" → If yes, implement → PostToolUse hook handles rest.
665
+
666
+ (See below for full protocol)
667
+
668
+ allowed-tools: Read, Write, Edit, Bash, Grep, Glob
669
+ ---
670
+
671
+ # Implementation Cycle Manager Protocol
672
+
673
+ **When to activate**: You just responded with `{"proposedChanges": true, "madeChanges": false}`
674
+
675
+ **Detection signals**:
676
+ - You listed numbered changes (1. Fix X, 2. Add Y, 3. Update Z)
677
+ - You used phrases: "Here's what needs to change", "I found N issues", "Proposed changes:"
678
+ - Your response ended with `{"proposedChanges": true, "madeChanges": false}`
679
+
680
+ **What to do**:
681
+
682
+ 1. **Ask user for confirmation**:
683
+ ```
684
+
685
+ I found [N] issues/changes. Should I implement all suggested changes now?
686
+
687
+ (Type "yes", "proceed", "do it", or "implement" to continue)
688
+
689
+ ```
690
+
691
+ 2. **If user says YES** (matches: yes, proceed, do it, implement, make the changes, go ahead):
692
+ - Implement ALL proposed changes using Write/Edit tools
693
+ - PostToolUse hook will automatically:
694
+ - Run tests (if code changes)
695
+ - Commit changes
696
+ - Trigger critique
697
+ - Respond with final JSON status
698
+
699
+ 3. **If user says NO** (matches: no, not yet, wait, hold on):
700
+ - Acknowledge: "Understood. Let me know when you're ready."
701
+ - Wait for further instructions
702
+
703
+ 4. **If user asks question or modifies request**:
704
+ - Answer question first
705
+ - Then re-offer implementation
706
+
707
+ **Example flow**:
708
+
709
+ ```
710
+
711
+ User: "double check and critique the authentication module"
712
+ You: [critique finds 5 issues]
713
+ {"proposedChanges": true, "madeChanges": false}
714
+
715
+ You (Skill activates): "I found 5 issues. Should I implement all suggested changes now?"
716
+
717
+ User: "yes"
718
+
719
+ You: [uses Edit tool to fix all 5 issues]
720
+ PostToolUse Hook: [runs tests, commits, injects critique]
721
+ You: [responds with critique of implemented changes]
722
+ {"proposedChanges": false, "madeChanges": true}
723
+
724
+ ```
725
+
726
+ **What this eliminates**:
727
+ - ✅ User typing "make all your suggested changes" (27 chars)
728
+ - ✅ User typing "yes please" (10 chars)
729
+ - ✅ User typing "do it" (5 chars)
730
+
731
+ **Activation rate reality**: 50-70% (fallback: user types `/implement` when Skill doesn't activate)
732
+ ```
733
+
734
+ **Activation test**:
735
+
736
+ ```
737
+ You: "critique the user authentication code"
738
+ Claude: [finds 3 issues] {"proposedChanges": true}
739
+ Expected: Skill activates, asks "Should I implement all suggested changes now?"
740
+ You: "yes"
741
+ Expected: Claude implements all 3 fixes
742
+ ```
743
+
744
+ ---
745
+
746
+ ### Skills: Common Mistakes & Fixes
747
+
748
+ | Mistake | Symptom | Fix | Verify |
749
+ | ----------------------- | ----------------------- | ---------------------------------------------------------------------- | ------------------------------------ |
750
+ | Invalid YAML | Skill doesn't load | Run `yamllint` | `yamllint SKILL.md` |
751
+ | Description >1024 chars | Low activation rate | Count chars, move details below YAML | `grep -A 50 "description:" \| wc -c` |
752
+ | No trigger keywords | Never activates | Add user vocab keywords (library names, file extensions, action verbs) | Test with trigger phrases |
753
+ | Name invalid format | Skill doesn't load | Lowercase, hyphens only, ≤64 chars | `echo -n "name" \| wc -c` |
754
+ | Vague description | Inconsistent activation | Add specific "Use when" bullets with examples | Track activation rate |
755
+
756
+ **Testing protocol**:
757
+
758
+ 1. **Positive test** (should activate): Say trigger phrase → Verify Skill invoked
759
+ 2. **Negative test** (should NOT activate): Say unrelated phrase → Verify Skill NOT invoked
760
+ 3. **Iterate descriptions**: Track false positives/negatives, refine weekly
761
+
762
+ ---
763
+
764
+ ### Skills: Activation Mitigation
765
+
766
+ **Realistic expectations**: Skills activate 50-70% of time. Manual fallback needed 30-50%.
767
+
768
+ **Mitigation strategies**:
769
+
770
+ **1. Slash command alternatives**
771
+
772
+ | Skill | Slash Command | Use When |
773
+ | ------------- | ------------------------ | --------------------------- |
774
+ | Docs Verifier | `/latest-docs [library]` | Skill doesn't activate |
775
+ | Quality Gates | `/critique` | Need to force quality check |
776
+
777
+ **2. Track activation rate weekly**
778
+
779
+ ```bash
780
+ # Create log: ~/.claude/skills/activation-log.txt
781
+ # Format: Date | Skill | Activated (Y/N) | Expected (Y/N)
782
+
783
+ # After 1 week, calculate rate
784
+ grep docs-verifier ~/.claude/skills/activation-log.txt | \
785
+ awk '{total++; if($4=="Y" && $6=="Y") correct++} END {print "Rate:", correct/total*100"%"}'
786
+ ```
787
+
788
+ **3. Iterate descriptions based on real usage**
789
+
790
+ Week 1 → Week 2 → Week 3 → Week 4: Add missed trigger keywords, measure improvement
791
+
792
+ **Example iteration**:
793
+
794
+ ```yaml
795
+ # v1 (40% activation)
796
+ description: "Review code before Write/Edit"
797
+
798
+ # v2 (60% activation) - Added triggers
799
+ description: "Review .ts/.tsx/.js/.jsx before Write/Edit. Use when proposing changes, user says 'implement', 'fix', 'yes'."
800
+
801
+ # v3 (70% activation) - Added library names
802
+ description: "Review .ts/.tsx/.js/.jsx before Write/Edit using react/electron/vitest. Use when proposing changes, user says 'implement'."
803
+ ```
804
+
805
+ **4. Document manual fallback in project CLAUDE.md**
806
+
807
+ ```markdown
808
+ ## When Skills Don't Activate
809
+
810
+ If Quality Gates doesn't activate: Type `/critique [stack]` or say "use the quality-gates skill"
811
+ ```
812
+
813
+ ---
814
+
815
+ ### 2.2: PostToolUse Hook - Auto-Critique After Changes (45 min)
816
+
817
+ **⚠️ Requires**: Hooks working (see Critical Warning above)
818
+
819
+ **What**: Detect `{"madeChanges": true}` responses, auto-run tests for code changes, auto-commit, and trigger full critique
820
+
821
+ **This replaces your manual workflow**:
822
+
823
+ - ❌ Old: You type "make all your suggested changes" → Claude implements → You type "double check and critique" → loop
824
+ - ✅ New: Claude implements → Hook auto-runs tests + commits + triggers critique → done
825
+
826
+ **File**: Create `~/.claude/hooks/PostToolUse.sh`
827
+
828
+ ```bash
829
+ #!/bin/bash
830
+
831
+ # Parse tool name and file paths
832
+ TOOL_NAME="$CLAUDE_TOOL_NAME"
833
+ FILE_PATHS="$CLAUDE_FILE_PATHS" # Comma-separated
834
+
835
+ # Only trigger on file modification tools
836
+ if [[ ! "$TOOL_NAME" =~ ^(Write|Edit|MultiEdit|NotebookEdit)$ ]]; then
837
+ exit 0
838
+ fi
839
+
840
+ # Extract file extensions
841
+ CODE_EXTENSIONS="ts|tsx|js|jsx|py|go|rs|java|c|cpp|h|hpp"
842
+ CHANGED_CODE=false
843
+
844
+ IFS=',' read -ra FILES <<< "$FILE_PATHS"
845
+ for file in "${FILES[@]}"; do
846
+ if [[ "$file" =~ \.($CODE_EXTENSIONS)$ ]]; then
847
+ CHANGED_CODE=true
848
+ break
849
+ fi
850
+ done
851
+
852
+ # Run tests for code changes
853
+ if [ "$CHANGED_CODE" = true ]; then
854
+ echo "📝 Code changes detected. Running tests..."
855
+
856
+ # Detect test command from package.json or common patterns
857
+ if [ -f "package.json" ] && grep -q '"test":' package.json; then
858
+ npm test 2>&1 | head -50
859
+ elif [ -f "pytest.ini" ] || [ -f "setup.py" ]; then
860
+ pytest 2>&1 | head -50
861
+ elif [ -f "go.mod" ]; then
862
+ go test ./... 2>&1 | head -50
863
+ elif [ -f "Cargo.toml" ]; then
864
+ cargo test 2>&1 | head -50
865
+ fi
866
+
867
+ echo ""
868
+ fi
869
+
870
+ # Auto-commit changes
871
+ echo "💾 Committing changes..."
872
+
873
+ # Generate commit message from changed files
874
+ COMMIT_MSG="update: $(basename ${FILES[0]})"
875
+ if [ ${#FILES[@]} -gt 1 ]; then
876
+ COMMIT_MSG="update: ${#FILES[@]} files"
877
+ fi
878
+
879
+ git add ${FILES[@]} 2>/dev/null
880
+ git commit -m "$COMMIT_MSG
881
+
882
+ 🤖 Generated with Claude Code
883
+
884
+ Co-Authored-By: Claude <noreply@anthropic.com>" 2>&1 | grep -E "(commit|changed|insertion|deletion)"
885
+
886
+ echo ""
887
+ echo "✅ Changes committed: $COMMIT_MSG"
888
+ echo ""
889
+
890
+ # Trigger full critique (matches user's exact prompt pattern)
891
+ cat <<'CRITIQUE'
892
+ IMPORTANT: Now double check and critique your changes:
893
+
894
+ 1. **Correctness**: Will it actually work? Any bugs?
895
+ 2. **Elegance**: Is it clean, maintainable, avoiding bloat?
896
+ 3. **Best Practices**: Following language/framework conventions? Check latest docs.
897
+ 4. **Test Coverage**: Did tests pass? Any gaps?
898
+ 5. **Documentation**: Does CLAUDE.md need updating?
899
+
900
+ Be honest and thorough. Respond with JSON status at the end.
901
+ CRITIQUE
902
+ ```
903
+
904
+ **Make executable**:
905
+
906
+ ```bash
907
+ chmod +x ~/.claude/hooks/PostToolUse.sh
908
+ ```
909
+
910
+ **Register in settings.json**:
911
+
912
+ ```json
913
+ {
914
+ "hooks": {
915
+ "PostToolUse": [
916
+ {
917
+ "matcher": "Write|Edit|MultiEdit|NotebookEdit",
918
+ "hooks": [
919
+ {
920
+ "type": "command",
921
+ "command": "~/.claude/hooks/PostToolUse.sh"
922
+ }
923
+ ]
924
+ }
925
+ ]
926
+ }
927
+ }
928
+ ```
929
+
930
+ **How it works**:
931
+
932
+ 1. Claude uses Write/Edit/NotebookEdit tool
933
+ 2. Hook fires automatically
934
+ 3. Detects if code files were changed (by extension)
935
+ 4. Runs tests if code changed
936
+ 5. Auto-commits changes with consistent message format
937
+ 6. Injects critique prompt into Claude's context
938
+ 7. Claude sees the prompt and responds with critique
939
+
940
+ **What this automates** (your exact workflow):
941
+
942
+ - ✅ "make all your suggested changes" → Claude implements (you still type this)
943
+ - ✅ Test execution → Hook runs automatically
944
+ - ✅ Git commit → Hook runs automatically
945
+ - ✅ "double check and critique" → Hook injects automatically
946
+ - ✅ Loop prevention → You only intervene when Claude finds issues
947
+
948
+ **Data sources**:
949
+
950
+ - `$CLAUDE_TOOL_NAME` - Tool that was used (Write/Edit/NotebookEdit)
951
+ - `$CLAUDE_FILE_PATHS` - Comma-separated list of modified files
952
+ - `$CLAUDE_PROJECT_DIR` - Current working directory
953
+
954
+ **Pros**:
955
+
956
+ - ✅ Eliminates 100+ "double check and critique" prompts per project
957
+ - ✅ Deterministic (always runs after file modifications)
958
+ - ✅ Matches your exact prompt pattern ("is it correct? elegant? best practices? avoid bloat?")
959
+ - ✅ Auto-runs tests only for code changes (not docs/config)
960
+ - ✅ Consistent commit messages
961
+
962
+ **Cons**:
963
+
964
+ - ❌ Adds ~10-30 seconds per change (test + commit time)
965
+ - ❌ May generate noisy commits if making many small changes (solution: use `/implement` for big changes)
966
+ - ❌ Broken in v2.0.27+ without `--debug` workaround
967
+ - ❌ Cannot detect `{"madeChanges": true}` in JSON (hook runs after tool, not after response)
968
+
969
+ ---
970
+
971
+ ### 2.3: SessionStart Hook (OPTIONAL, 20 min)
972
+
973
+ **What**: Load quality standards at session start
974
+
975
+ **File**: Create `~/.claude/hooks/session-start.sh`
976
+
977
+ ```bash
978
+ #!/bin/bash
979
+
980
+ echo "🚀 Session started: $CLAUDE_PROJECT_DIR"
981
+ echo ""
982
+
983
+ # Set project env vars
984
+ echo "export PROJECT_ROOT=$CLAUDE_PROJECT_DIR" >> "$CLAUDE_ENV_FILE"
985
+
986
+ # Check for uncommitted changes
987
+ cd "$CLAUDE_PROJECT_DIR"
988
+ if ! git diff --quiet 2>/dev/null; then
989
+ echo "⚠️ Warning: Uncommitted changes detected"
990
+ fi
991
+ ```
992
+
993
+ **Make executable**:
994
+
995
+ ```bash
996
+ chmod +x ~/.claude/hooks/session-start.sh
997
+ ```
998
+
999
+ **Register in settings.json**:
1000
+
1001
+ ```json
1002
+ {
1003
+ "hooks": {
1004
+ "SessionStart": [
1005
+ {
1006
+ "matcher": "*",
1007
+ "hooks": [
1008
+ {
1009
+ "type": "command",
1010
+ "command": "~/.claude/hooks/session-start.sh"
1011
+ }
1012
+ ]
1013
+ }
1014
+ ]
1015
+ }
1016
+ }
1017
+ ```
1018
+
1019
+ **Pros**:
1020
+
1021
+ - ✅ Loads context automatically
1022
+ - ✅ Sets up environment consistently
1023
+ - ✅ Runs once per session (not repeatedly)
1024
+
1025
+ **Cons**:
1026
+
1027
+ - ❌ Adds to initial context (uses tokens)
1028
+ - ❌ Broken in v2.0.27+ (including v2.0.30) without `--debug` workaround
1029
+
1030
+ ---
1031
+
1032
+ ### 2.4: Stop Hook for Context Management (OPTIONAL, 10 min)
1033
+
1034
+ **What**: Reminds to `/clear` context after tasks
1035
+
1036
+ **File**: Add to `~/.claude/settings.json`
1037
+
1038
+ ```json
1039
+ {
1040
+ "hooks": {
1041
+ "Stop": [
1042
+ {
1043
+ "matcher": "*",
1044
+ "hooks": [
1045
+ {
1046
+ "type": "command",
1047
+ "command": "echo '💡 Task complete. Consider: /clear before next task (prevents context pollution)'"
1048
+ }
1049
+ ]
1050
+ }
1051
+ ]
1052
+ }
1053
+ }
1054
+ ```
1055
+
1056
+ **Agentic best practice**: "Use /clear between distinct tasks" - prevents context window clutter
1057
+
1058
+ **Pros**:
1059
+
1060
+ - ✅ Prevents "dumber after compaction" issue
1061
+ - ✅ Non-invasive (suggestion, not manipulation)
1062
+ - ✅ No context bloat
1063
+
1064
+ **Cons**:
1065
+
1066
+ - ❌ User must manually type `/clear`
1067
+ - ❌ May be repetitive if working on single task
1068
+
1069
+ ---
1070
+
1071
+ ### Common Gotchas for Hooks
1072
+
1073
+ | Issue | Symptom | Fix |
1074
+ | ------------------------------- | ----------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- | --- | --------------------------------------- | -------- | --- | ----- |
1075
+ | **JSON parsing in PostToolUse** | Hook can't detect `{"madeChanges": true}` | Hooks run AFTER tool execution, before response text. Cannot parse JSON from response. Use file extension detection instead. |
1076
+ | **Hook output not visible** | Hook runs but Claude doesn't see output | Use `echo` to print output. Hook stdout/stderr is shown to Claude. |
1077
+ | **Commit message formatting** | Commit message has broken newlines | Use HEREDOC: `git commit -m "$(cat <<'EOF' ... EOF)"` |
1078
+ | **Test commands not found** | Hook fails to find `npm`/`pytest` | Check `$PATH` in hook environment. Use full paths: `/usr/local/bin/npm test` |
1079
+ | **Hook hangs session** | Claude waits forever | Add timeout or use ` | | true`to prevent blocking:`npm test 2>&1 | head -50 | | true` |
1080
+ | **Git not in repo** | Hook fails with git errors | Check if in git repo: `[ -d .git ] && git add ...` |
1081
+ | **File paths with spaces** | Hook fails to process files | Quote file paths: `git add "${FILES[@]}"` not `git add $FILES` |
1082
+
1083
+ **Why you can't parse `{"madeChanges": true}` in PostToolUse hook**:
1084
+
1085
+ - PostToolUse hook executes AFTER Write/Edit tool completes
1086
+ - But BEFORE Claude generates response text (which includes the JSON)
1087
+ - Hook only has access to: `$CLAUDE_TOOL_NAME`, `$CLAUDE_FILE_PATHS`, `$CLAUDE_PROJECT_DIR`
1088
+ - Solution: Detect file types by extension (`*.ts, *.tsx`) instead of parsing JSON
1089
+
1090
+ **Testing protocol**:
1091
+
1092
+ 1. **Echo test**: Add `echo "🎉 Hook fired!"` to verify hook runs
1093
+ 2. **Dry run**: Comment out git commands, test file detection logic
1094
+ 3. **Check logs**: Look at Claude Code debug logs (if using `--debug` flag)
1095
+
1096
+ ---
1097
+
1098
+ ### Phase 2 Testing
1099
+
1100
+ **After implementing Skills + Hooks**:
1101
+
1102
+ **Skills testing**:
1103
+
1104
+ 1. Propose code change → Verify Skill activates
1105
+ 2. Answer question (no code) → Verify Skill does NOT activate
1106
+ 3. Track activation rate for 1 week
1107
+
1108
+ **Hooks testing**:
1109
+
1110
+ 1. Make code change → Verify linter runs automatically
1111
+ 2. Check Claude responds to linter results
1112
+ 3. Verify tests run (if configured)
1113
+
1114
+ **Pass criteria**:
1115
+
1116
+ - Skills activate 50-70% of time (track in log)
1117
+ - Slash commands provide smooth fallback for missed activations
1118
+ - Hooks run reliably (if working in your version)
1119
+ - Quality maintained or improved
1120
+
1121
+ **Measure after 1-2 weeks**:
1122
+
1123
+ - Quality check prompts reduced by 50-70%?
1124
+ - Skills activation trending up week-over-week?
1125
+ - Manual fallback workflow feels natural (not frustrating)?
1126
+
1127
+ ---
1128
+
1129
+ ## Success Metrics (Realistic Targets)
1130
+
1131
+ **⚠️ Updated based on Skills 50-70% activation rate**
1132
+
1133
+ ### Quantitative Targets
1134
+
1135
+ | Metric | Before | Phase 1 Target | Phase 2 Target |
1136
+ | --------------------------------- | --------------- | -------------- | -------------- |
1137
+ | Avg prompt length (chars) | 250 | 150 (-40%) | 100 (-60%) |
1138
+ | Quality check prompts per session | 15 | 6 (-60%) | 4-8 (-50-70%) |
1139
+ | **Implementation cycle prompts** | **100/project** | **40 (-60%)** | **5 (-95%)** |
1140
+ | Time to implementation (min) | 10 | 7 (-30%) | 5-6 (-40-50%) |
1141
+ | Docs lookup prompts | 8 | 3 (-62%) | 1-3 (-62-87%) |
1142
+ | **Skills activation rate** | N/A | N/A | **50-70%** |
1143
+ | **Manual fallback needed** | N/A | N/A | **30-50%** |
1144
+
1145
+ **Key principles**:
1146
+
1147
+ - ❌ Removed "0 (-100%)" targets - unrealistic
1148
+ - ✅ Accept 30-50% manual fallback as success
1149
+ - ✅ Skills activation trending up = success (even if not 100%)
1150
+
1151
+ **Implementation cycle prompts explained**:
1152
+
1153
+ - **Before**: You type "double check and critique" → Claude finds 5 issues → You type "make all your suggested changes" → Claude implements → You type "double check and critique" again → Loop 100 times per project
1154
+ - **Phase 1 (slash commands)**: Replace long prompts with `/critique` and `/implement` → Saves 60% keystrokes
1155
+ - **Phase 2 (hooks + skills)**: PostToolUse hook auto-triggers critique after changes, Implementation Cycle Manager Skill auto-offers to implement → 95% reduction (only 5 manual interventions per 100 cycles)
1156
+
1157
+ ### Qualitative Goals
1158
+
1159
+ - **Quality maintained**: No increase in bugs or refactoring needs
1160
+ - **Developer experience**: Feels faster, less repetitive _even with 30-50% manual_
1161
+ - **False positives**: <5% of hook/skill triggers are wrong
1162
+ - **Skills trending up**: Activation rate improves week-over-week with description tuning
1163
+ - **Fallback smooth**: Slash commands feel natural, not frustrating
1164
+
1165
+ **Measure at**: Week 1 (Phase 1), Week 3 (Phase 2), Week 5 (Phase 2 iteration)
1166
+
1167
+ ---
1168
+
1169
+ ## Rollback Plan
1170
+
1171
+ If automation causes issues:
1172
+
1173
+ ### Phase 1 (Slash Commands)
1174
+
1175
+ - **Issue**: Command doesn't work
1176
+ - **Fix**: Edit `.md` file, reload session
1177
+ - **Rollback**: Delete command file
1178
+
1179
+ ### Phase 2 (Skills/Hooks)
1180
+
1181
+ - **Issue**: Skill fires at wrong times
1182
+ - **Fix**: Refine description in SKILL.md
1183
+ - **Rollback**: Delete skill directory
1184
+
1185
+ - **Issue**: Hook breaks workflow
1186
+ - **Fix**: Adjust script or conditions
1187
+ - **Rollback**: Remove from settings.json
1188
+
1189
+ **Recovery**: All automation is additive - removing files returns to manual workflow
1190
+
1191
+ **Quick undo**: Press **Esc twice** to rewind conversation to last checkpoint (v2.0.10+)
1192
+
1193
+ ---
1194
+
1195
+ ## Iterative Development Process
1196
+
1197
+ **Critical principle**: Test each phase for 1 week before building next phase.
1198
+
1199
+ **Agentic best practice (2025)**: "Guide yields better outcomes than pure autonomy. Ask for a plan first, then execute."
1200
+
1201
+ ### Week 1: Phase 1
1202
+
1203
+ 1. ✅ Implement slash commands + CLAUDE.md
1204
+ 2. ✅ Use in both projects (soulless-monorepo, bitd)
1205
+ 3. ✅ Measure prompt length reduction
1206
+ 4. ✅ Track command usage frequency
1207
+ 5. ❓ **Decision point**: Is this sufficient, or is Phase 2 needed?
1208
+
1209
+ ### Week 2-3: Phase 2 (if needed)
1210
+
1211
+ 1. ✅ Verify hooks working (test hook, workaround if needed)
1212
+ 2. ✅ Implement 1-2 Skills (not all at once - start small)
1213
+ 3. ✅ Implement PostToolUse Hook (if hooks working)
1214
+ 4. ✅ Test activation with positive/negative cases
1215
+ 5. ✅ Track Skills activation rate daily
1216
+
1217
+ ### Week 4-5: Phase 2 Iteration
1218
+
1219
+ 1. ✅ Review activation log (false positives/negatives)
1220
+ 2. ✅ Refine Skill descriptions (add missed trigger keywords)
1221
+ 3. ✅ Add 3rd automation if first 2 working well
1222
+ 4. ✅ Measure improvement (activation rate trending up?)
1223
+ 5. ❓ **Decision point**: Is 50-70% reduction sufficient?
1224
+
1225
+ ### Week 6+: Maintenance
1226
+
1227
+ - **Weekly**: Review activation logs, refine descriptions
1228
+ - **Monthly**: Assess if new repetitive patterns emerged
1229
+ - **Quarterly**: Evaluate if automation still provides value
1230
+
1231
+ **Stop building when**: You reach 60-90% reduction in repetitive prompts, NOT when you hit 100% (unrealistic).
1232
+
1233
+ ---
1234
+
1235
+ ## Appendix: Why NOT Other Approaches
1236
+
1237
+ ### Why NOT Subagents
1238
+
1239
+ **What they are**: Separate AI agents in isolated context windows
1240
+
1241
+ **Why NOT for quality checks**:
1242
+
1243
+ - ❌ Slow (context switching overhead)
1244
+ - ❌ No conversation history (can't see requirements)
1245
+ - ❌ Overkill for simple quality checks
1246
+
1247
+ **When to use instead**:
1248
+
1249
+ - ✅ Comprehensive PR reviews (entire diff analysis)
1250
+ - ✅ Architecture audits (long, detailed analysis)
1251
+ - ✅ Exhaustive code searches (already using Explore correctly)
1252
+
1253
+ ---
1254
+
1255
+ ### Why NOT MCP Servers
1256
+
1257
+ **What they are**: External integrations (GitHub, databases, external linters)
1258
+
1259
+ **Why NOT for quality checks**:
1260
+
1261
+ - ❌ External API costs ($$ for GPT-4/Gemini calls)
1262
+ - ❌ Network latency (slower than in-context)
1263
+ - ❌ No conversation context
1264
+ - ❌ Complex setup (install + config + API keys)
1265
+ - ❌ Hooks already handle linting (simpler)
1266
+
1267
+ **When to use instead** (future):
1268
+
1269
+ - ✅ GitHub PR automation ("Review PR #123 and post comments")
1270
+ - ✅ Database validation ("Will this schema change break production?")
1271
+ - ✅ Company-specific external tools
1272
+
1273
+ ---
1274
+
1275
+ ## Next Steps
1276
+
1277
+ **Choose your starting point**:
1278
+
1279
+ 1. **"implement phase 1"** → I'll create slash commands + CLAUDE.md updates
1280
+ 2. **"show me examples first"** → I'll demonstrate each command in action
1281
+ 3. **"modify the plan"** → Tell me what to change
1282
+
1283
+ **Remember**:
1284
+
1285
+ - ✅ Test Phase 1 for 1 week before Phase 2
1286
+ - ⚠️ Skills activate 50-70% (not 100%) - accept manual fallback
1287
+ - 🚨 Verify hooks working before Phase 2 (see Critical Warning)
1288
+ - 🎯 Goal is 60-90% reduction (not 100%)
1289
+ - 📋 "Ask for a plan first" - agentic best practice
1290
+
1291
+ **Ready to start?**