worclaude 2.2.6 → 2.4.0

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 (54) hide show
  1. package/CHANGELOG.md +113 -0
  2. package/README.md +114 -37
  3. package/package.json +7 -2
  4. package/src/commands/doctor.js +507 -104
  5. package/src/commands/init.js +103 -19
  6. package/src/core/detector.js +34 -10
  7. package/src/core/merger.js +48 -3
  8. package/src/core/scaffolder.js +58 -1
  9. package/src/data/agent-registry.js +17 -2
  10. package/src/data/agents.js +7 -0
  11. package/src/index.js +2 -1
  12. package/src/prompts/claude-md-merge.js +5 -0
  13. package/templates/agents/universal/build-validator.md +23 -0
  14. package/templates/agents/universal/code-simplifier.md +11 -0
  15. package/templates/agents/universal/plan-reviewer.md +39 -0
  16. package/templates/agents/universal/test-writer.md +25 -0
  17. package/templates/agents/universal/upstream-watcher.md +120 -0
  18. package/templates/agents/universal/verify-app.md +12 -0
  19. package/templates/commands/build-fix.md +5 -0
  20. package/templates/commands/commit-push-pr.md +6 -0
  21. package/templates/commands/compact-safe.md +5 -0
  22. package/templates/commands/conflict-resolver.md +5 -0
  23. package/templates/commands/end.md +10 -0
  24. package/templates/commands/learn.md +33 -0
  25. package/templates/commands/refactor-clean.md +10 -0
  26. package/templates/commands/review-changes.md +5 -0
  27. package/templates/commands/review-plan.md +5 -0
  28. package/templates/commands/setup.md +5 -0
  29. package/templates/commands/start.md +10 -0
  30. package/templates/commands/status.md +5 -0
  31. package/templates/commands/sync.md +5 -0
  32. package/templates/commands/techdebt.md +5 -0
  33. package/templates/commands/test-coverage.md +5 -0
  34. package/templates/commands/update-claude-md.md +5 -0
  35. package/templates/commands/upstream-check.md +85 -0
  36. package/templates/commands/verify.md +11 -0
  37. package/templates/core/agents-md.md +25 -0
  38. package/templates/core/claude-md.md +17 -0
  39. package/templates/hooks/README.md +106 -0
  40. package/templates/hooks/correction-detect.cjs +48 -0
  41. package/templates/hooks/examples/prompt-hook-commit-validator.json +16 -0
  42. package/templates/hooks/learn-capture.cjs +179 -0
  43. package/templates/hooks/pre-compact-save.cjs +60 -0
  44. package/templates/hooks/skill-hint.cjs +66 -0
  45. package/templates/memory/decisions.md +11 -0
  46. package/templates/memory/preferences.md +17 -0
  47. package/templates/settings/base.json +56 -8
  48. package/templates/skills/templates/backend-conventions.md +1 -0
  49. package/templates/skills/templates/frontend-design-system.md +1 -0
  50. package/templates/skills/templates/project-patterns.md +1 -0
  51. package/templates/skills/universal/coding-principles.md +60 -0
  52. package/templates/skills/universal/context-management.md +21 -0
  53. package/templates/skills/universal/planning-with-files.md +11 -0
  54. package/templates/skills/universal/verification.md +18 -0
@@ -91,6 +91,31 @@ After writing tests, report:
91
91
  | src/core/merger.js | 8 | 74% → 91% | Added edge cases for conflict resolution |
92
92
  | src/utils/hash.js | 3 | 100% | Empty input + large file + encoding |
93
93
 
94
+ ## Severity Classification
95
+
96
+ When reporting coverage gaps, classify by severity:
97
+
98
+ | Severity | When | Priority |
99
+ |----------|------|----------|
100
+ | CRITICAL | Auth, payment, data validation — user-facing correctness | Test immediately |
101
+ | HIGH | Core business logic, state transitions, error recovery | Test in this session |
102
+ | MEDIUM | Integration points, config variations, concurrent scenarios | Test if time allows |
103
+ | LOW | Formatting, logging, pure delegation | Skip unless requested |
104
+
105
+ Focus effort on CRITICAL and HIGH. Report MEDIUM and LOW without writing tests for them.
106
+
107
+ ## Edge Case Categories
108
+
109
+ When testing a function, systematically consider:
110
+ 1. **Empty/zero**: empty string, empty array, 0, null, undefined
111
+ 2. **Boundary**: first, last, max, min, off-by-one
112
+ 3. **Type**: wrong type, NaN, Infinity, negative where positive expected
113
+ 4. **State**: uninitialized, already-completed, concurrent modification
114
+ 5. **Format**: unicode, special characters, very long strings, whitespace-only
115
+ 6. **Environment**: missing file, no network, permission denied
116
+ 7. **Sequence**: out-of-order operations, duplicate calls, rapid succession
117
+ 8. **Scale**: single item, many items, items exceeding expected max
118
+
94
119
  ## Rules
95
120
  - Follow the project's existing test patterns — match file naming, framework, assertion style
96
121
  - Aim for meaningful coverage (>80% on changed code), not 100% everywhere
@@ -0,0 +1,120 @@
1
+ ---
2
+ name: upstream-watcher
3
+ description: "Cross-references new Anthropic upstream changes against the current project's scaffolded infrastructure and produces an impact report"
4
+ model: sonnet
5
+ isolation: none
6
+ memory: project
7
+ disallowedTools:
8
+ - Edit
9
+ - Write
10
+ - NotebookEdit
11
+ maxTurns: 30
12
+ criticalSystemReminder: "CRITICAL: You CANNOT edit files. Report findings only. Suggest actions but do not implement them."
13
+ ---
14
+
15
+ You are an upstream-awareness specialist. You fetch the anthropic-watch feeds,
16
+ read the current project's Claude Code infrastructure, and produce a focused
17
+ impact report describing which upstream changes matter for THIS project.
18
+
19
+ You are read-only. Report findings and recommend actions — do not implement them.
20
+
21
+ ## 1. Fetch Upstream Feeds
22
+
23
+ Feed base: `https://sefaertunc.github.io/anthropic-watch/feeds/`
24
+
25
+ Fetch both feeds in parallel to keep the worst-case wait bounded by a single
26
+ `--max-time`:
27
+
28
+ ```bash
29
+ curl -s --max-time 10 https://sefaertunc.github.io/anthropic-watch/feeds/run-report.json &
30
+ curl -s --max-time 10 https://sefaertunc.github.io/anthropic-watch/feeds/all.json &
31
+ wait
32
+ ```
33
+
34
+ If either fetch fails (non-zero exit, empty body, or non-JSON), report
35
+ "Could not reach anthropic-watch feeds" and stop — no impact analysis is
36
+ possible without the feed data.
37
+
38
+ `run-report.json` gives per-source health and `newItemCount`. `all.json` gives
39
+ the full list of items across all 16 sources, sorted newest-first. Each item
40
+ carries `source`, `sourceCategory`, `title`, `date`, `url`, `snippet`.
41
+
42
+ ## 2. Read Project Infrastructure
43
+
44
+ Enumerate the scaffolded surface area so you know what upstream changes could
45
+ affect:
46
+
47
+ - `.claude/agents/*.md` — every agent and its frontmatter (model, isolation, tools)
48
+ - `.claude/commands/*.md` — every slash command
49
+ - `.claude/skills/*/SKILL.md` — every skill
50
+ - `.claude/hooks/*` — every hook script, especially `pre-compact-save.cjs`
51
+ - `.claude/settings.json` and `.claude/settings.local.json` — permissions, env, hooks wiring
52
+ - `CLAUDE.md` and `AGENTS.md` — project conventions
53
+ - `package.json` (or equivalent) — whether the project imports `@anthropic-ai/sdk`
54
+ or `anthropic` directly
55
+
56
+ Use `ls`, `cat`, and `grep` via the Read/Bash tools. You do not need to read
57
+ every file in full — frontmatter and imports are usually enough.
58
+
59
+ ## 3. Impact Classification
60
+
61
+ For each new upstream item, classify it into one of these buckets:
62
+
63
+ | Source family | What to check in this project |
64
+ |---|---|
65
+ | Claude Code releases / changelog / npm-claude-code | Agent frontmatter syntax, hook event names, command syntax, tool names used by agents |
66
+ | Agent SDK TS/Py changelog | Spawned-agent capabilities, tool schemas, isolation semantics, hook input/output shapes |
67
+ | Anthropic API SDK / docs | Relevant **only** if the project imports the SDK directly — skip otherwise |
68
+ | Engineering blog | New patterns or best practices worth adopting; never blocking |
69
+ | Status page | Informational only; no action required |
70
+ | Other sources | Classify by content — prefer informational unless it names something the project uses |
71
+
72
+ ## 4. Report Format
73
+
74
+ Produce three sections:
75
+
76
+ ### Direct impact
77
+
78
+ Items that affect this project's scaffolded infrastructure. For each item:
79
+
80
+ - **[Source] Title** — `url`
81
+ - Affected: which agent / command / hook / skill / setting, and why
82
+ - Why it matters: 1-2 sentences
83
+
84
+ ### Informational
85
+
86
+ Items worth knowing about but requiring no action. One bullet per item: title,
87
+ source, one-line reason it is informational.
88
+
89
+ ### Recommended actions
90
+
91
+ Concrete, actionable follow-ups tied to direct-impact items. Examples:
92
+
93
+ - "Review `pre-compact-save.cjs` — PreCompact hook input shape changed in Claude Code vX.Y"
94
+ - "Update `verify-app` agent frontmatter — new `isolation: ephemeral` option available"
95
+ - "Check `@anthropic-ai/sdk` pinned version — Y.Z deprecates {feature} used in src/foo.js"
96
+
97
+ Each action must name the specific file and the specific upstream change that
98
+ prompts it.
99
+
100
+ ## 5. Empty Case
101
+
102
+ If the feeds report no new items, or if no new items affect this project, say
103
+ so in one line. Do not pad the report.
104
+
105
+ > No new upstream items since {timestamp}.
106
+
107
+ or
108
+
109
+ > {N} new upstream items. None affect this project's scaffolded infrastructure.
110
+
111
+ ## Rules
112
+
113
+ - You are read-only. Never edit files. Never run destructive commands.
114
+ - Be specific: name the affected file, frontmatter field, or import — not "some agents".
115
+ - Skip items that are clearly informational (blog think-pieces, status incidents)
116
+ after a one-line mention.
117
+ - If confidence is low that an upstream change affects this project, list it as
118
+ informational rather than direct-impact. Do not cry wolf.
119
+ - Keep the report scannable. Direct-impact and actions are the parts the user
120
+ will act on — lead with them.
@@ -116,6 +116,18 @@ You will feel the urge to skip checks. These are the excuses — recognize them:
116
116
  - **Database migrations**: run migration up → verify schema matches intent → run migration down (reversibility) → test against existing data, not just empty DB
117
117
  - **Data/ML pipeline**: run with sample input → verify output shape/schema/types → test empty input and NaN/null handling → check row counts in vs out for silent data loss
118
118
 
119
+ ## Verification Depth Levels
120
+
121
+ Every check targets a depth level. Cover all 4 for critical features:
122
+
123
+ 1. **Exists** — file/function/endpoint is present
124
+ 2. **Substantive** — real implementation, not a stub or placeholder
125
+ 3. **Wired** — connected to the rest of the system (imported, routed, configured)
126
+ 4. **Functional** — actually works when invoked with real input
127
+
128
+ Before issuing PASS, scan for stubs: `grep -rn "TODO\|FIXME\|placeholder\|not.implemented" --include="*.js" --include="*.ts" --include="*.py" src/ || true`
129
+ Do not flag test fixtures, documentation examples, or planned future work in SPEC.md.
130
+
119
131
  ## Before Issuing PASS
120
132
 
121
133
  Your report must include at least one adversarial probe (boundary value, concurrent request,
@@ -38,3 +38,8 @@ for diagnosis and resolution.
38
38
  - Tests failing after dependency update
39
39
  - CI is red and you need to fix locally before pushing
40
40
  - After a large refactor that introduced errors
41
+
42
+ ## Trigger Phrases
43
+ - "fix the build"
44
+ - "build is broken"
45
+ - "tests are failing"
@@ -64,3 +64,9 @@ Only used for release merges after /sync has been run.
64
64
  Ask the user which base branch to target before creating a PR.
65
65
 
66
66
  Use gh pr create for PR creation.
67
+
68
+ ## Trigger Phrases
69
+ - "commit and push"
70
+ - "create a PR"
71
+ - "ship it"
72
+ - "push my changes"
@@ -10,3 +10,8 @@ After compaction, briefly confirm:
10
10
  - Current task
11
11
  - Current branch
12
12
  - What was just being worked on
13
+
14
+ ## Trigger Phrases
15
+ - "compact context"
16
+ - "free up context"
17
+ - "running low on context"
@@ -43,3 +43,8 @@ If anything fails, fix it.
43
43
  Use exactly this message format — no trailers or Co-Authored-By lines.
44
44
 
45
45
  Do NOT push. Do NOT create a PR. The user will run /sync next.
46
+
47
+ ## Trigger Phrases
48
+ - "resolve conflicts"
49
+ - "fix merge conflicts"
50
+ - "merge conflict"
@@ -4,6 +4,10 @@ description: "Mid-task stop — writes handoff file and session summary for next
4
4
 
5
5
  Use this ONLY when stopping work mid-task without committing.
6
6
 
7
+ When invoked with arguments, use them as the description of current work. Example: `/end implementing user registration`
8
+
9
+ Arguments: $ARGUMENTS
10
+
7
11
  Do NOT update PROGRESS.md — /sync handles that on develop after merging.
8
12
 
9
13
  ## Pre-flight: Worktree Safety
@@ -35,3 +39,9 @@ If you are working in a git worktree (not the main checkout):
35
39
  5. git commit -m "wip: handoff for [task description]"
36
40
  Use exactly this message format — no trailers or Co-Authored-By lines.
37
41
  6. git push
42
+
43
+ ## Trigger Phrases
44
+ - "stop working"
45
+ - "end session"
46
+ - "save and stop"
47
+ - "I need to go"
@@ -0,0 +1,33 @@
1
+ ---
2
+ description: "Capture a correction or convention as a persistent learning"
3
+ ---
4
+
5
+ The user wants to capture a learning from this session.
6
+
7
+ When invoked with arguments, use them as the learning to capture.
8
+ Example: `/learn Always use conventional commits for this project`
9
+
10
+ If no arguments provided, ask the user what they want to remember.
11
+
12
+ Format it as a [LEARN] block:
13
+
14
+ [LEARN] Category: One-line rule description
15
+ Mistake: What went wrong (optional)
16
+ Correction: What should happen instead (optional)
17
+
18
+ Write this to `.claude/learnings/{category-slug}.md` with YAML frontmatter:
19
+ - created: today's date (YYYY-MM-DD)
20
+ - category: from the [LEARN] block
21
+ - project: current project name (from package.json name field, or directory name)
22
+ - times_applied: 0
23
+
24
+ Update `.claude/learnings/index.json` to include the new entry.
25
+ If index.json doesn't exist, create it with `{ "learnings": [] }`.
26
+
27
+ Confirm to the user what was saved and where.
28
+
29
+ ## Trigger Phrases
30
+ - "remember this"
31
+ - "learn this"
32
+ - "save this rule"
33
+ - "capture this correction"
@@ -7,6 +7,10 @@ runs INLINE in your current session — it reads uncommitted changes,
7
7
  improves them in place, and leaves everything uncommitted for
8
8
  /commit-push-pr.
9
9
 
10
+ When invoked with arguments, use them to scope the cleanup. Example: `/refactor-clean src/core/merger.js`
11
+
12
+ Arguments: $ARGUMENTS
13
+
10
14
  Do NOT spawn a subagent or worktree for this. Work directly on
11
15
  the files in the current working directory.
12
16
 
@@ -54,3 +58,9 @@ the files in the current working directory.
54
58
  - After implementing a feature, before /verify and /commit-push-pr
55
59
  - Weekly maintenance pass
56
60
  - When /review-changes flagged issues you want to fix
61
+
62
+ ## Trigger Phrases
63
+ - "clean up the code"
64
+ - "refactor this"
65
+ - "simplify"
66
+ - "tidy up"
@@ -22,3 +22,8 @@ Only analyze and report.
22
22
 
23
23
  The user will decide which findings to act on and apply fixes themselves.
24
24
  Do NOT apply any fixes. Do NOT touch any files. REPORT ONLY.
25
+
26
+ ## Trigger Phrases
27
+ - "review my changes"
28
+ - "what did I change"
29
+ - "code review"
@@ -12,3 +12,8 @@ review the plan for:
12
12
  - SPEC.md alignment
13
13
 
14
14
  Wait for the review and address all feedback before proceeding.
15
+
16
+ ## Trigger Phrases
17
+ - "review this plan"
18
+ - "check my implementation plan"
19
+ - "plan review"
@@ -114,3 +114,8 @@ these files with real, project-specific content:
114
114
  features from the interview, marking completed items.
115
115
 
116
116
  Show the user what files were updated and offer to review each one.
117
+
118
+ ## Trigger Phrases
119
+ - "set up the project"
120
+ - "configure this project"
121
+ - "project interview"
@@ -5,6 +5,10 @@ description: "Load session context, check for handoff files, detect drift since
5
5
  The SessionStart hook has already loaded CLAUDE.md, PROGRESS.md,
6
6
  and the most recent session summary into context.
7
7
 
8
+ When invoked with arguments, use them as the task focus. Example: `/start implement auth module`
9
+
10
+ Arguments: $ARGUMENTS
11
+
8
12
  Your job is to supplement that with drift detection and additional context.
9
13
 
10
14
  ## 1. Drift Detection
@@ -73,3 +77,9 @@ Summarize:
73
77
  - What was last completed (from session summary loaded by hook)
74
78
  - What's next (from PROGRESS.md loaded by hook)
75
79
  - Any blockers or notes
80
+
81
+ ## Trigger Phrases
82
+ - "start a new session"
83
+ - "begin working"
84
+ - "load context"
85
+ - "what changed since last time"
@@ -8,3 +8,8 @@ Report current session state:
8
8
  - Test status (last run results)
9
9
  - Context usage estimate
10
10
  - Any blockers or pending decisions
11
+
12
+ ## Trigger Phrases
13
+ - "what's the status"
14
+ - "where am I"
15
+ - "what am I working on"
@@ -52,3 +52,8 @@ and tell the user to run /conflict-resolver first.
52
52
  Use exactly this message format — no trailers or Co-Authored-By lines.
53
53
  10. git push origin develop
54
54
  11. gh pr create --base main with description of what was merged
55
+
56
+ ## Trigger Phrases
57
+ - "sync progress"
58
+ - "update shared files"
59
+ - "post-merge sync"
@@ -11,3 +11,8 @@ Scan the codebase for technical debt:
11
11
  - Inconsistent patterns
12
12
 
13
13
  Report findings organized by severity. Fix quick wins directly.
14
+
15
+ ## Trigger Phrases
16
+ - "find tech debt"
17
+ - "scan for issues"
18
+ - "code quality scan"
@@ -55,3 +55,8 @@ Delegates to the test-writer agent for test creation.
55
55
  - After implementing a large feature
56
56
  - When coverage drops below project threshold (check CLAUDE.md)
57
57
  - During periodic maintenance
58
+
59
+ ## Trigger Phrases
60
+ - "check test coverage"
61
+ - "what needs tests"
62
+ - "coverage gaps"
@@ -11,3 +11,8 @@ Review what happened:
11
11
 
12
12
  Write the proposed additions to the Gotchas section or
13
13
  Critical Rules section. Show the diff before applying.
14
+
15
+ ## Trigger Phrases
16
+ - "update CLAUDE.md"
17
+ - "add to rules"
18
+ - "update project rules"
@@ -0,0 +1,85 @@
1
+ ---
2
+ description: "On-demand check of Anthropic upstream feeds (Claude Code releases, SDK changelogs, blog, status)"
3
+ ---
4
+
5
+ Fetch the anthropic-watch feeds and report a concise summary of upstream changes.
6
+ This is a stateless, on-demand status check — no caching, no persistence.
7
+
8
+ Feed base URL: `https://sefaertunc.github.io/anthropic-watch/feeds/`
9
+
10
+ ## 1. Fetch Run Report
11
+
12
+ ```bash
13
+ curl -s --max-time 10 https://sefaertunc.github.io/anthropic-watch/feeds/run-report.json
14
+ ```
15
+
16
+ If the fetch fails (non-zero exit, empty body, or non-JSON output), report:
17
+
18
+ ```
19
+ Could not reach anthropic-watch feeds.
20
+ ```
21
+
22
+ and stop.
23
+
24
+ Otherwise, parse the JSON and extract:
25
+
26
+ - `timestamp` — when the scraper last ran
27
+ - `sources[]` — list of all 16 sources with `{key, name, category, status, newItemCount, error}`
28
+
29
+ Count how many sources have `status: "ok"` vs errored sources. List each errored source
30
+ with its error message.
31
+
32
+ ## 2. Fetch All Items
33
+
34
+ ```bash
35
+ curl -s --max-time 10 https://sefaertunc.github.io/anthropic-watch/feeds/all.json
36
+ ```
37
+
38
+ Apply the same failure handling.
39
+
40
+ Otherwise, parse and take the **10 most recent items** (they are already sorted
41
+ newest-first). Group them by `sourceCategory` (`core` vs `extended`).
42
+
43
+ For each item show:
44
+
45
+ - Title
46
+ - Source name (`sourceName`)
47
+ - Date (relative like "2 days ago" when you can compute it, otherwise ISO date)
48
+ - URL
49
+
50
+ ## 3. Highlight Claude Code-Critical Items
51
+
52
+ Any item whose `source` is one of:
53
+
54
+ - `claude-code-releases`
55
+ - `claude-code-changelog`
56
+ - `npm-claude-code`
57
+ - `agent-sdk-ts-changelog`
58
+ - `agent-sdk-py-changelog`
59
+
60
+ directly affects scaffolded worclaude infrastructure. Flag these with a `[CRITICAL]`
61
+ prefix in the listing so the user notices them first.
62
+
63
+ ## 4. Closing Summary
64
+
65
+ End with a single line:
66
+
67
+ ```
68
+ X new items since {timestamp}. Y/16 sources healthy.
69
+ ```
70
+
71
+ Where X is the total item count across all sources (sum of `newItemCount` from the
72
+ run report) and Y is the healthy-source count.
73
+
74
+ ## Rules
75
+
76
+ - Use only `curl` and shell builtins. Do not invoke `node` or `npm`.
77
+ - Do not cache, persist, or diff against prior runs — this command is stateless.
78
+ - Keep the output concise. This is a status check, not a research report.
79
+ - If both feeds fail, stop after the first failure message.
80
+
81
+ ## Trigger Phrases
82
+ - "check upstream"
83
+ - "what changed in claude code"
84
+ - "any anthropic updates"
85
+ - "upstream status"
@@ -3,6 +3,11 @@ description: "Run full project verification — tests, build, lint, type checkin
3
3
  ---
4
4
 
5
5
  Run full project verification:
6
+
7
+ When invoked with arguments, use them to scope what to verify. Example: `/verify just the auth module`
8
+
9
+ Arguments: $ARGUMENTS
10
+
6
11
  1. Run the test suite
7
12
  2. Run the build
8
13
  3. Run the linter
@@ -10,3 +15,9 @@ Run full project verification:
10
15
  5. Run any domain-specific verification
11
16
 
12
17
  Report results clearly. Do not proceed if any check fails.
18
+
19
+ ## Trigger Phrases
20
+ - "verify everything"
21
+ - "run all checks"
22
+ - "is this working"
23
+ - "test and lint"
@@ -0,0 +1,25 @@
1
+ # AGENTS.md
2
+
3
+ {project_name} — {description}
4
+
5
+ ## Tech Stack
6
+ {tech_stack_filled_during_init}
7
+
8
+ ## Build & Test Commands
9
+ {commands_filled_during_init}
10
+
11
+ ## Code Conventions
12
+ - Follow existing patterns in the codebase
13
+ - Test before committing
14
+ - Read source files before modifying them
15
+ - Ask if ambiguous, do not guess
16
+
17
+ ## Project Structure
18
+ - `src/` — Source code
19
+ - `tests/` — Test files
20
+ - `docs/` — Documentation
21
+
22
+ ## Key Principles
23
+ - Source of truth: docs/spec/SPEC.md
24
+ - One task at a time, verify each before moving on
25
+ - Never invent features not in the specification
@@ -16,6 +16,7 @@
16
16
  See `.claude/skills/` — load only what's relevant:
17
17
  - context-management/SKILL.md — Session lifecycle
18
18
  - claude-md-maintenance/SKILL.md — CLAUDE.md self-healing
19
+ - coding-principles/SKILL.md — Behavioral principles: assumptions, simplicity, surgical changes, verification
19
20
  - git-conventions/SKILL.md — Commits, branches, versioning
20
21
  - planning-with-files/SKILL.md — Implementation planning
21
22
  - prompt-engineering/SKILL.md — Prompting patterns and quality
@@ -45,6 +46,22 @@ See `.claude/skills/` — load only what's relevant:
45
46
  7. Mediocre fix → scrap it, implement elegantly.
46
47
  8. Feature branches NEVER modify shared-state files. Those are updated only on develop via /sync after merging PRs. See git-conventions.md Shared-State Files for the canonical list.
47
48
  9. Never add Co-Authored-By trailers, AI attribution footers, or "Generated with" signatures to commits or PRs.
49
+ 10. Surgical changes only — every changed line must trace to the request. Don't "improve" adjacent code, comments, or formatting.
50
+ 11. Push back when simpler approaches exist. Present alternatives, don't pick silently.
51
+ 12. Transform tasks to success criteria. "Fix the bug" → "Write a failing test, then make it pass."
52
+
53
+ ## Memory Architecture
54
+
55
+ - This file: static project rules. Keep under 200 lines.
56
+ - Native memory (`/memory`): auto-captured project knowledge.
57
+ - Persistent corrections: `.claude/learnings/` via [LEARN] blocks or `/learn`.
58
+ - Path-scoped rules: `.claude/rules/` with YAML frontmatter.
59
+ - Session state: `.claude/sessions/` (gitignored).{memory_architecture_extras}
60
+ - Do NOT write session learnings or auto-captured patterns here.
61
+
62
+ ## Learnings
63
+
64
+ Corrections captured via [LEARN] blocks live in `.claude/learnings/`. SessionStart loads recent ones automatically.
48
65
 
49
66
  ## Gotchas
50
67
  [Grows during development]
@@ -0,0 +1,106 @@
1
+ # Worclaude Hooks
2
+
3
+ This directory holds Node.js hook scripts that `worclaude init` copies
4
+ into `.claude/hooks/` of the scaffolded project. Each script corresponds
5
+ to a `hooks[<event>]` entry in `templates/settings/base.json`.
6
+
7
+ `scaffoldHooks()` only copies `*.cjs` and `*.js` files — this `README.md`
8
+ and everything under `examples/` stays in the Worclaude repo and is NOT
9
+ shipped into user projects.
10
+
11
+ ## Scaffolded hooks
12
+
13
+ | File | Event | Purpose |
14
+ |---|---|---|
15
+ | `pre-compact-save.cjs` | `PreCompact` | Writes a git context snapshot to `.claude/sessions/` before auto-compaction so nothing is lost if compaction truncates state. |
16
+ | `correction-detect.cjs` | `UserPromptSubmit` | Regex-matches user prompts against correction patterns and learn signals. On match, writes a hint to `.claude/.correction-hint`. |
17
+ | `learn-capture.cjs` | `Stop` | Scans the session transcript for `[LEARN] …` blocks and persists them to `.claude/learnings/` with an `index.json`. Uses a file-based re-entry flag to tolerate hypothetical re-entrant Stop events. |
18
+ | `skill-hint.cjs` | `UserPromptSubmit` | Token-overlap match between the user's prompt and installed skill directory names. Emits a `[Skill hint]` line when a match is found. |
19
+
20
+ All scripts:
21
+ - use the `.cjs` extension so `require()` works regardless of the host project's `package.json` `"type": "module"` setting
22
+ - read JSON from stdin, handle malformed input gracefully, and always exit 0
23
+ - suppress stderr noise from git or filesystem helpers
24
+
25
+ ## Hook profiles
26
+
27
+ Every hook except `SessionStart`, `PostCompact`, and `PreCompact` is
28
+ gated by the `WORCLAUDE_HOOK_PROFILE` environment variable:
29
+
30
+ | Profile | Runs |
31
+ |---|---|
32
+ | `minimal` | Only context-loading hooks (`SessionStart`, `PostCompact`, `PreCompact`). All other hooks exit immediately. |
33
+ | `standard` (default) | All hooks including formatter on `PostToolUse`, learnings capture on `Stop`, notifications on `SessionEnd`/`Notification`. |
34
+ | `strict` | Standard + TypeScript type-checking after every `Write`/`Edit`. |
35
+
36
+ Users override the profile via shell env: `export WORCLAUDE_HOOK_PROFILE=minimal`.
37
+
38
+ ## Handler types
39
+
40
+ Claude Code supports three hook handler types. Worclaude scaffolds
41
+ `type: "command"` hooks; the others are available for custom use.
42
+
43
+ ### `command` (what we scaffold)
44
+
45
+ Runs a shell command. Stdin receives JSON context; stdout/stderr are
46
+ surfaced in the session.
47
+
48
+ ```json
49
+ {
50
+ "type": "command",
51
+ "command": "node .claude/hooks/my-hook.cjs",
52
+ "async": true
53
+ }
54
+ ```
55
+
56
+ ### `prompt` (cheap LLM-powered validation)
57
+
58
+ Runs a small prompt through a Claude model (defaults to Haiku).
59
+ `$ARGUMENTS` is replaced with the hook's input JSON. The model must
60
+ reply with `{"ok": true}` or `{"ok": false, "reason": "..."}`. An `ok:
61
+ false` response blocks the tool with the reason displayed.
62
+
63
+ ```json
64
+ {
65
+ "type": "prompt",
66
+ "prompt": "Check this: $ARGUMENTS. Reply {\"ok\": true} or {\"ok\": false, \"reason\": \"...\"}.",
67
+ "model": "haiku",
68
+ "timeout": 30
69
+ }
70
+ ```
71
+
72
+ `model` is a sibling of `type`; the `model` field accepts aliases
73
+ (`haiku`, `sonnet`, `opus`) or full model IDs. Default timeout is 30s.
74
+
75
+ ### `agent` (full subagent invocation)
76
+
77
+ Runs a subagent. Heaviest option — use sparingly.
78
+
79
+ ## Prompt-hook example
80
+
81
+ `examples/prompt-hook-commit-validator.json` is a complete, valid
82
+ `PreToolUse` prompt hook that validates git commit messages against
83
+ Conventional Commits. To enable it in a scaffolded project:
84
+
85
+ 1. Open the project's `.claude/settings.json`.
86
+ 2. Merge the `PreToolUse` entry from the example into the `hooks`
87
+ object (or append if `PreToolUse` already exists).
88
+ 3. Test by running `git commit -m 'bad message'` inside a Claude Code
89
+ session — the hook should reject with a reason.
90
+
91
+ Prompt hooks consume Haiku tokens. Expect a few cents per 1000 commits.
92
+
93
+ ## Adding custom hooks
94
+
95
+ - Drop a new `.cjs` or `.js` into `.claude/hooks/`.
96
+ - Reference it from `.claude/settings.json` under the appropriate event.
97
+ - Gate it on `WORCLAUDE_HOOK_PROFILE` if it is expensive or optional.
98
+ - `disableSkillShellExecution` in Claude Code settings does NOT affect
99
+ hook scripts — hooks are executed by the Claude Code hook runtime,
100
+ not by skill inline-shell evaluation. Hook scripts run even when
101
+ `disableSkillShellExecution` is enabled.
102
+
103
+ ## Further reading
104
+
105
+ - Claude Code hooks reference: `/docs/reference/hooks.md` in this repo.
106
+ - Worclaude hook profiles: `CLAUDE.md` of this repo, "Hook Profiles" section.