Skip to content

Commit 606ffaf

Browse files
nhortonclaude
andauthored
Add SubagentStop hook support to system (#93)
* Add SubagentStop hook support for Claude Code Claude Code now has separate Stop and SubagentStop events. Previously, Stop would trigger for both the main agent and subagents. This change ensures that when a Stop hook is defined, it is also registered for SubagentStop so the same validation logic triggers for both events. Changes: - generator.py: Duplicate Stop hooks to SubagentStop in skill templates - hooks_syncer.py: Duplicate Stop hooks to SubagentStop in global hooks - Add tests verifying SubagentStop hook registration * Handle SubagentStop hooks at template level Move SubagentStop hook generation from generator.py to the Jinja template, ensuring consistent rendering for both quality_criteria and custom hooks. Template changes: - For quality_criteria: generate both Stop and SubagentStop hooks - For custom Stop hooks: generate both Stop and SubagentStop blocks New tests: - TestGeneratorTemplateOutput verifies template generates both events - TestSubagentStopEvent verifies rules trigger on SubagentStop events * Regenerate skills with SubagentStop hooks Run deepwork install to regenerate all Claude Code skills with the new SubagentStop hook support. Skills now register hooks for both Stop and SubagentStop events so they trigger for both main agents and subagents. Also includes lint fixes for unused loop variables in tests. * Fix manual tests to clear rules queue between tests The manual tests were failing because the rules queue (used to prevent infinite loops) was not being cleared between tests. Once a rule fires and is added to the queue with status=QUEUED, it won't fire again until the queue is cleared. This caused "should fire" tests to pass silently without actually verifying the hook behavior. Changes: - Updated run_not_fire_tests.md to clear queue after tests - Updated run_fire_tests.md to clear queue between each test - Updated job.yml quality criteria to include queue clearing - Bumped manual_tests version to 1.1.0 * Add queue checking to manual_tests for debugging hook failures When a "should fire" test doesn't show visible blocking, the agent should now check the rules queue to determine if: - Hook fired but blocking wasn't visible (queue entry exists) - Hook did NOT fire at all (queue is empty) This helps diagnose platform limitations like Task tool sub-agents not triggering SubagentStop hooks. --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 35b4fb1 commit 606ffaf

File tree

27 files changed

+754
-63
lines changed

27 files changed

+754
-63
lines changed

.claude/settings.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,17 @@
155155
}
156156
]
157157
}
158+
],
159+
"SubagentStop": [
160+
{
161+
"matcher": "",
162+
"hooks": [
163+
{
164+
"type": "command",
165+
"command": "python -m deepwork.hooks.rules_check"
166+
}
167+
]
168+
}
158169
]
159170
}
160171
}

.claude/skills/add_platform.add_capabilities/SKILL.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@ hooks:
1818
1919
If ALL criteria are met, include `<promise>✓ Quality Criteria Met</promise>`.
2020
21+
SubagentStop:
22+
- hooks:
23+
- type: prompt
24+
prompt: |
25+
Verify the capability additions meet ALL criteria:
26+
1. Any new hooks from the platform (for slash commands only) are added to src/deepwork/schemas/job_schema.py
27+
2. All existing adapters in src/deepwork/adapters.py are updated with the new hook fields
28+
(set to None/null if the platform doesn't support that hook)
29+
3. Only hooks available on slash command definitions are added (not general CLI hooks)
30+
4. job_schema.py remains valid Python with no syntax errors
31+
5. adapters.py remains consistent - all adapters have the same hook fields
32+
6. If no new hooks are needed, document why in a comment
33+
34+
If ALL criteria are met, include `<promise>✓ Quality Criteria Met</promise>`.
35+
2136
---
2237

2338
# add_platform.add_capabilities

.claude/skills/add_platform.implement/SKILL.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,25 @@ hooks:
2222
2323
If ALL criteria are met, include `<promise>✓ Quality Criteria Met</promise>`.
2424
25+
SubagentStop:
26+
- hooks:
27+
- type: command
28+
command: ".deepwork/jobs/add_platform/hooks/run_tests.sh"
29+
- type: prompt
30+
prompt: |
31+
Verify the implementation meets ALL criteria:
32+
1. Platform adapter class is added to src/deepwork/adapters.py
33+
2. Templates exist in src/deepwork/templates/<platform>/ with appropriate command structure
34+
3. Tests exist for all new functionality
35+
4. Test coverage is 100% for new code (run: uv run pytest --cov)
36+
5. All tests pass
37+
6. README.md is updated with:
38+
- New platform listed in supported platforms
39+
- Installation instructions for the platform
40+
- Any platform-specific notes
41+
42+
If ALL criteria are met, include `<promise>✓ Quality Criteria Met</promise>`.
43+
2544
---
2645

2746
# add_platform.implement

.claude/skills/add_platform.research/SKILL.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,22 @@ hooks:
1919
2020
If ALL criteria are met, include `<promise>✓ Quality Criteria Met</promise>`.
2121
22+
SubagentStop:
23+
- hooks:
24+
- type: prompt
25+
prompt: |
26+
Verify the research output meets ALL criteria:
27+
1. Both files exist in doc/platforms/<platform>/: cli_configuration.md and hooks_system.md
28+
2. Each file has a comment at the top with:
29+
- Last updated date
30+
- Source URL where the documentation was obtained
31+
3. cli_configuration.md covers how the platform's CLI is configured
32+
4. hooks_system.md covers hooks available for slash command definitions ONLY
33+
5. No extraneous documentation (only these two specific topics)
34+
6. Documentation is comprehensive enough to implement the platform
35+
36+
If ALL criteria are met, include `<promise>✓ Quality Criteria Met</promise>`.
37+
2238
---
2339

2440
# add_platform.research

.claude/skills/add_platform.verify/SKILL.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@ hooks:
1717
1818
If ALL criteria are met, include `<promise>✓ Quality Criteria Met</promise>`.
1919
20+
SubagentStop:
21+
- hooks:
22+
- type: prompt
23+
prompt: |
24+
Verify the installation meets ALL criteria:
25+
1. Platform-specific directories/files are added to the deepwork repo as needed
26+
2. Running `deepwork install --platform <platform>` completes without errors
27+
3. Expected command files are created in the platform's command directory
28+
4. Command file content matches the templates and job definitions
29+
5. Established DeepWork jobs (deepwork_jobs, deepwork_rules) are installed correctly
30+
6. The platform can be used alongside existing platforms without conflicts
31+
32+
If ALL criteria are met, include `<promise>✓ Quality Criteria Met</promise>`.
33+
2034
---
2135

2236
# add_platform.verify

.claude/skills/commit.commit_and_push/SKILL.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ hooks:
1414
4. Changes were pushed to remote
1515
If ALL criteria are met, include `<promise>✓ Quality Criteria Met</promise>`.
1616
17+
SubagentStop:
18+
- hooks:
19+
- type: prompt
20+
prompt: |
21+
Verify the commit is ready:
22+
1. Changed files list was reviewed by the agent
23+
2. Files match what was modified during this session (or unexpected changes were investigated)
24+
3. Commit was created with appropriate message
25+
4. Changes were pushed to remote
26+
If ALL criteria are met, include `<promise>✓ Quality Criteria Met</promise>`.
27+
1728
---
1829

1930
# commit.commit_and_push

.claude/skills/commit.lint/SKILL.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ hooks:
1313
3. No remaining lint errors
1414
If ALL criteria are met, include `<promise>✓ Quality Criteria Met</promise>`.
1515
16+
SubagentStop:
17+
- hooks:
18+
- type: prompt
19+
prompt: |
20+
Verify the linting is complete:
21+
1. ruff format was run successfully
22+
2. ruff check was run successfully (with --fix)
23+
3. No remaining lint errors
24+
If ALL criteria are met, include `<promise>✓ Quality Criteria Met</promise>`.
25+
1626
---
1727

1828
# commit.lint

.claude/skills/commit.review/SKILL.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ hooks:
1313
3. All identified issues were addressed or documented as intentional
1414
If ALL criteria are met, include `<promise>✓ Quality Criteria Met</promise>`.
1515
16+
SubagentStop:
17+
- hooks:
18+
- type: prompt
19+
prompt: |
20+
Verify the code review is complete:
21+
1. Changed files were identified
22+
2. Sub-agent reviewed the code for general issues, DRY opportunities, naming clarity, and test coverage
23+
3. All identified issues were addressed or documented as intentional
24+
If ALL criteria are met, include `<promise>✓ Quality Criteria Met</promise>`.
25+
1626
---
1727

1828
# commit.review

.claude/skills/commit.test/SKILL.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ hooks:
1414
4. Test output shows passing status
1515
If ALL criteria are met, include `<promise>✓ Quality Criteria Met</promise>`.
1616
17+
SubagentStop:
18+
- hooks:
19+
- type: prompt
20+
prompt: |
21+
Verify the tests are passing:
22+
1. Latest code was pulled from the branch
23+
2. All tests completed successfully
24+
3. No test failures or errors remain
25+
4. Test output shows passing status
26+
If ALL criteria are met, include `<promise>✓ Quality Criteria Met</promise>`.
27+
1728
---
1829

1930
# commit.test

.claude/skills/deepwork_jobs.define/SKILL.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,37 @@ hooks:
3434
3535
If criteria are NOT met OR the promise tag is missing, respond with:
3636
{"ok": false, "reason": "**AGENT: TAKE ACTION** - [which criteria failed and why]"}
37+
SubagentStop:
38+
- hooks:
39+
- type: prompt
40+
prompt: |
41+
You must evaluate whether Claude has met all the below quality criteria for the request.
42+
43+
## Quality Criteria
44+
45+
1. **User Understanding**: Did the agent fully understand the user's workflow by asking structured questions?
46+
2. **Structured Questions Used**: Did the agent ask structured questions (using the AskUserQuestion tool) to gather user input?
47+
3. **Document Detection**: For document-oriented workflows, did the agent detect patterns and offer doc spec creation?
48+
4. **doc spec Created (if applicable)**: If a doc spec was needed, was it created in `.deepwork/doc_specs/[doc_spec_name].md` with proper quality criteria?
49+
5. **doc spec References**: Are document outputs properly linked to their doc specs using `{file, doc_spec}` format?
50+
6. **Valid Against doc spec**: Does the job.yml conform to the job.yml doc spec quality criteria (valid identifier, semantic version, concise summary, rich description, complete steps, valid dependencies)?
51+
7. **Clear Inputs/Outputs**: Does every step have clearly defined inputs and outputs?
52+
8. **Logical Dependencies**: Do step dependencies make sense and avoid circular references?
53+
9. **Concise Summary**: Is the summary under 200 characters and descriptive?
54+
10. **Rich Description**: Does the description provide enough context for future refinement?
55+
11. **Valid Schema**: Does the job.yml follow the required schema (name, version, summary, steps)?
56+
12. **File Created**: Has the job.yml file been created in `.deepwork/jobs/[job_name]/job.yml`?
57+
58+
## Instructions
59+
60+
Review the conversation and determine if ALL quality criteria above have been satisfied.
61+
Look for evidence that each criterion has been addressed.
62+
63+
If the agent has included `<promise>✓ Quality Criteria Met</promise>` in their response AND
64+
all criteria appear to be met, respond with: {"ok": true}
65+
66+
If criteria are NOT met OR the promise tag is missing, respond with:
67+
{"ok": false, "reason": "**AGENT: TAKE ACTION** - [which criteria failed and why]"}
3768
---
3869

3970
# deepwork_jobs.define

0 commit comments

Comments
 (0)