@hasna/hooks 0.0.1

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 (110) hide show
  1. package/.npmrc.example +2 -0
  2. package/AGENTS.md +54 -0
  3. package/CLAUDE.md +70 -0
  4. package/CONTRIBUTING.md +45 -0
  5. package/README.md +232 -0
  6. package/bin/index.js +5171 -0
  7. package/hooks/hook-agentmessages/CLAUDE.md +79 -0
  8. package/hooks/hook-agentmessages/LICENSE +21 -0
  9. package/hooks/hook-agentmessages/README.md +107 -0
  10. package/hooks/hook-agentmessages/package.json +31 -0
  11. package/hooks/hook-agentmessages/src/check-messages.ts +151 -0
  12. package/hooks/hook-agentmessages/src/install.ts +126 -0
  13. package/hooks/hook-agentmessages/src/session-start.ts +255 -0
  14. package/hooks/hook-agentmessages/src/uninstall.ts +89 -0
  15. package/hooks/hook-branchprotect/CLAUDE.md +23 -0
  16. package/hooks/hook-branchprotect/README.md +25 -0
  17. package/hooks/hook-branchprotect/package.json +42 -0
  18. package/hooks/hook-branchprotect/src/cli.ts +126 -0
  19. package/hooks/hook-branchprotect/src/hook.ts +88 -0
  20. package/hooks/hook-branchprotect/tsconfig.json +25 -0
  21. package/hooks/hook-checkbugs/LICENSE +21 -0
  22. package/hooks/hook-checkbugs/README.md +140 -0
  23. package/hooks/hook-checkbugs/package.json +58 -0
  24. package/hooks/hook-checkbugs/src/cli.ts +628 -0
  25. package/hooks/hook-checkbugs/src/hook.ts +335 -0
  26. package/hooks/hook-checkbugs/tsconfig.json +15 -0
  27. package/hooks/hook-checkdocs/README.md +137 -0
  28. package/hooks/hook-checkdocs/package.json +57 -0
  29. package/hooks/hook-checkdocs/src/cli.ts +628 -0
  30. package/hooks/hook-checkdocs/src/hook.ts +310 -0
  31. package/hooks/hook-checkdocs/tsconfig.json +15 -0
  32. package/hooks/hook-checkfiles/LICENSE +21 -0
  33. package/hooks/hook-checkfiles/README.md +141 -0
  34. package/hooks/hook-checkfiles/package.json +56 -0
  35. package/hooks/hook-checkfiles/src/cli.ts +545 -0
  36. package/hooks/hook-checkfiles/src/hook.ts +321 -0
  37. package/hooks/hook-checkfiles/tsconfig.json +15 -0
  38. package/hooks/hook-checklint/LICENSE +21 -0
  39. package/hooks/hook-checklint/README.md +147 -0
  40. package/hooks/hook-checklint/package.json +57 -0
  41. package/hooks/hook-checklint/src/cli-patch.ts +32 -0
  42. package/hooks/hook-checklint/src/cli.ts +667 -0
  43. package/hooks/hook-checklint/src/hook.ts +473 -0
  44. package/hooks/hook-checklint/tsconfig.json +15 -0
  45. package/hooks/hook-checkpoint/CLAUDE.md +23 -0
  46. package/hooks/hook-checkpoint/README.md +37 -0
  47. package/hooks/hook-checkpoint/package.json +58 -0
  48. package/hooks/hook-checkpoint/src/cli.ts +191 -0
  49. package/hooks/hook-checkpoint/src/hook.ts +207 -0
  50. package/hooks/hook-checkpoint/tsconfig.json +25 -0
  51. package/hooks/hook-checksecurity/LICENSE +21 -0
  52. package/hooks/hook-checksecurity/README.md +158 -0
  53. package/hooks/hook-checksecurity/package.json +57 -0
  54. package/hooks/hook-checksecurity/src/cli.ts +601 -0
  55. package/hooks/hook-checksecurity/src/hook.ts +334 -0
  56. package/hooks/hook-checksecurity/tsconfig.json +15 -0
  57. package/hooks/hook-checktasks/README.md +144 -0
  58. package/hooks/hook-checktasks/package.json +55 -0
  59. package/hooks/hook-checktasks/src/cli.ts +578 -0
  60. package/hooks/hook-checktasks/src/hook.ts +308 -0
  61. package/hooks/hook-checktasks/tsconfig.json +20 -0
  62. package/hooks/hook-checktests/LICENSE +21 -0
  63. package/hooks/hook-checktests/README.md +137 -0
  64. package/hooks/hook-checktests/package.json +57 -0
  65. package/hooks/hook-checktests/src/cli.ts +627 -0
  66. package/hooks/hook-checktests/src/hook.ts +334 -0
  67. package/hooks/hook-checktests/tsconfig.json +15 -0
  68. package/hooks/hook-contextrefresh/CLAUDE.md +23 -0
  69. package/hooks/hook-contextrefresh/README.md +42 -0
  70. package/hooks/hook-contextrefresh/package.json +42 -0
  71. package/hooks/hook-contextrefresh/src/cli.ts +152 -0
  72. package/hooks/hook-contextrefresh/src/hook.ts +148 -0
  73. package/hooks/hook-contextrefresh/tsconfig.json +25 -0
  74. package/hooks/hook-gitguard/CLAUDE.md +22 -0
  75. package/hooks/hook-gitguard/README.md +30 -0
  76. package/hooks/hook-gitguard/package.json +57 -0
  77. package/hooks/hook-gitguard/src/cli.ts +159 -0
  78. package/hooks/hook-gitguard/src/hook.ts +129 -0
  79. package/hooks/hook-gitguard/tsconfig.json +25 -0
  80. package/hooks/hook-packageage/CLAUDE.md +23 -0
  81. package/hooks/hook-packageage/README.md +33 -0
  82. package/hooks/hook-packageage/package.json +42 -0
  83. package/hooks/hook-packageage/src/cli.ts +165 -0
  84. package/hooks/hook-packageage/src/hook.ts +177 -0
  85. package/hooks/hook-packageage/tsconfig.json +25 -0
  86. package/hooks/hook-phonenotify/CLAUDE.md +25 -0
  87. package/hooks/hook-phonenotify/README.md +44 -0
  88. package/hooks/hook-phonenotify/package.json +42 -0
  89. package/hooks/hook-phonenotify/src/cli.ts +196 -0
  90. package/hooks/hook-phonenotify/src/hook.ts +139 -0
  91. package/hooks/hook-phonenotify/tsconfig.json +25 -0
  92. package/hooks/hook-precompact/CLAUDE.md +23 -0
  93. package/hooks/hook-precompact/README.md +36 -0
  94. package/hooks/hook-precompact/package.json +42 -0
  95. package/hooks/hook-precompact/src/cli.ts +168 -0
  96. package/hooks/hook-precompact/src/hook.ts +122 -0
  97. package/hooks/hook-precompact/tsconfig.json +25 -0
  98. package/package.json +61 -0
  99. package/src/cli/components/App.tsx +191 -0
  100. package/src/cli/components/CategorySelect.tsx +37 -0
  101. package/src/cli/components/DataTable.tsx +133 -0
  102. package/src/cli/components/Header.tsx +18 -0
  103. package/src/cli/components/HookSelect.tsx +29 -0
  104. package/src/cli/components/InstallProgress.tsx +105 -0
  105. package/src/cli/components/SearchView.tsx +86 -0
  106. package/src/cli/index.tsx +218 -0
  107. package/src/index.ts +31 -0
  108. package/src/lib/installer.ts +288 -0
  109. package/src/lib/registry.ts +205 -0
  110. package/tsconfig.json +17 -0
package/.npmrc.example ADDED
@@ -0,0 +1,2 @@
1
+ @hasna:registry=https://registry.npmjs.org/
2
+ //registry.npmjs.org/:_authToken=${NPM_TOKEN}
package/AGENTS.md ADDED
@@ -0,0 +1,54 @@
1
+ # AGENTS.md
2
+
3
+ Guidance for AI agents working with this repository.
4
+
5
+ ## Overview
6
+
7
+ This is `@hasna/hooks`, an open-source monorepo of Claude Code hooks providing CLI installation and management of 15+ lifecycle hooks.
8
+
9
+ ## Quick Commands
10
+
11
+ ```bash
12
+ bun install # Install dependencies
13
+ bun run dev # Run CLI
14
+ bun run build # Build
15
+ bun run typecheck # Type check
16
+ ```
17
+
18
+ ## Adding Hooks
19
+
20
+ 1. Copy to `hooks/hook-{name}/`
21
+ 2. Ensure it follows the standard hook pattern (stdin JSON → stdout JSON)
22
+ 3. Remove any internal references (hasnaxyz, etc.)
23
+ 4. Verify no secrets or API keys are committed
24
+ 5. Update `src/lib/registry.ts` to include the hook
25
+
26
+ ## Structure
27
+
28
+ ```
29
+ hooks/hook-{name}/
30
+ ├── src/
31
+ │ ├── hook.ts # Main hook logic
32
+ │ ├── cli.ts # CLI commands
33
+ │ └── index.ts # Exports
34
+ ├── package.json
35
+ ├── CLAUDE.md
36
+ └── README.md
37
+ ```
38
+
39
+ ## Hook Events
40
+
41
+ | Event | Timing | Can Block | Use Case |
42
+ |-------|--------|-----------|----------|
43
+ | PreToolUse | Before tool | Yes | Security, safety guards |
44
+ | PostToolUse | After tool | No | Quality checks, async tasks |
45
+ | Stop | Session end | No | Notifications, cleanup |
46
+ | Notification | On notify | No | Context management |
47
+
48
+ ## Security Checks
49
+
50
+ Before committing any hook:
51
+ - [ ] No hardcoded API keys/tokens
52
+ - [ ] No internal references (hasnaxyz)
53
+ - [ ] Uses `@hasna` namespace for public packages
54
+ - [ ] .env.example has placeholders only
package/CLAUDE.md ADDED
@@ -0,0 +1,70 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code when working with this repository.
4
+
5
+ ## Project Overview
6
+
7
+ `@hasna/hooks` is an open-source monorepo of Claude Code hooks. It provides a CLI to install hooks into projects and register them in Claude settings.
8
+
9
+ ## Build & Run Commands
10
+
11
+ ```bash
12
+ # Install dependencies
13
+ bun install
14
+
15
+ # Run CLI in development
16
+ bun run dev
17
+
18
+ # Build for distribution
19
+ bun run build
20
+
21
+ # Type check
22
+ bun run typecheck
23
+ ```
24
+
25
+ ## Code Style
26
+
27
+ - TypeScript with strict mode
28
+ - ESM modules (`type: module`)
29
+ - Async/await for all async operations
30
+ - Minimal dependencies: commander, chalk, ink (for CLI)
31
+ - Type annotations required everywhere
32
+
33
+ ## Project Structure
34
+
35
+ ```
36
+ ├── src/
37
+ │ ├── cli/ # Interactive CLI (Ink/React)
38
+ │ │ ├── components/
39
+ │ │ └── index.tsx
40
+ │ ├── lib/ # Core library
41
+ │ │ ├── installer.ts
42
+ │ │ └── registry.ts
43
+ │ └── index.ts # Library exports
44
+ ├── hooks/ # Individual hook packages
45
+ │ └── hook-*/ # Each hook
46
+ └── bin/ # Built CLI output
47
+ ```
48
+
49
+ ## Adding New Hooks
50
+
51
+ When adding hooks:
52
+
53
+ 1. Copy to `hooks/hook-{name}/`
54
+ 2. Update `src/lib/registry.ts` to include the hook
55
+ 3. Ensure no secrets or API keys are committed
56
+ 4. Follow the standard hook structure (src/hook.ts, src/cli.ts)
57
+
58
+ ## Hook Events
59
+
60
+ - **PreToolUse**: Fires before tool execution, can block
61
+ - **PostToolUse**: Fires after tool execution, async
62
+ - **Stop**: Fires on session end, async
63
+ - **Notification**: Fires on notification events, async
64
+
65
+ ## Dependencies
66
+
67
+ - commander: CLI argument parsing
68
+ - chalk: Terminal styling
69
+ - ink: React-based interactive CLI
70
+ - ink-select-input: Selection component for Ink
@@ -0,0 +1,45 @@
1
+ # Contributing
2
+
3
+ Thanks for helping improve the hooks. Please follow these guidelines so we can keep publishing safe and consistent.
4
+
5
+ ## NPM Auth (Optional)
6
+
7
+ If you need a scoped registry token (publish or private installs), copy an example file and set `NPM_TOKEN`:
8
+
9
+ ```bash
10
+ cp .npmrc.example .npmrc
11
+ ```
12
+
13
+ - Do not commit `.npmrc` files with real tokens.
14
+ - Use environment variables in CI: `NPM_TOKEN` only.
15
+
16
+ ## Adding a New Hook
17
+
18
+ 1. Create the hook directory: `hooks/hook-{name}/`
19
+ 2. Follow the standard structure:
20
+ ```
21
+ hook-{name}/
22
+ ├── src/
23
+ │ ├── hook.ts # Main hook logic
24
+ │ ├── cli.ts # CLI commands
25
+ │ └── index.ts # Exports
26
+ ├── package.json
27
+ ├── CLAUDE.md
28
+ ├── README.md
29
+ └── tsconfig.json
30
+ ```
31
+ 3. Register it in `src/lib/registry.ts`
32
+ 4. Test with `bun run dev`
33
+
34
+ ## Hook Conventions
35
+
36
+ - Hooks receive JSON on stdin and output JSON on stdout
37
+ - PreToolUse hooks return `{ "decision": "approve" | "block", "reason": "..." }`
38
+ - PostToolUse/Stop/Notification hooks return `{ "continue": true }`
39
+ - Log diagnostic info to stderr, not stdout
40
+ - No external dependencies (use Node.js builtins only)
41
+
42
+ ## Secrets
43
+
44
+ - Never commit `.env` files with real values.
45
+ - Keep credentials in your local environment only.
package/README.md ADDED
@@ -0,0 +1,232 @@
1
+ # Hooks
2
+
3
+ Open source library of 15 Claude Code hooks. Install any hook with a single command.
4
+
5
+ ## Quick Start
6
+
7
+ ```bash
8
+ # Interactive mode - browse and select hooks
9
+ npx @hasna/hooks
10
+
11
+ # Install specific hooks
12
+ npx @hasna/hooks install gitguard branchprotect checkpoint
13
+
14
+ # List all available hooks
15
+ npx @hasna/hooks list
16
+ ```
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ # Global install
22
+ bun install -g @hasna/hooks
23
+
24
+ # Or use npx (no install needed)
25
+ npx @hasna/hooks
26
+ ```
27
+
28
+ ## NPM Auth (Optional)
29
+
30
+ If you need a scoped registry token (publish or private installs), copy an example file and set `NPM_TOKEN`:
31
+
32
+ ```bash
33
+ cp .npmrc.example .npmrc
34
+ ```
35
+
36
+ See `CONTRIBUTING.md` for publishing and secrets guidance.
37
+
38
+ ## Usage
39
+
40
+ ### Interactive Mode
41
+
42
+ Run without arguments to browse hooks by category:
43
+
44
+ ```bash
45
+ hooks
46
+ ```
47
+
48
+ ### Install Hooks
49
+
50
+ ```bash
51
+ # Install one or more hooks
52
+ hooks install gitguard branchprotect checkpoint
53
+
54
+ # Hooks are installed to .hooks/ and registered in ~/.claude/settings.json
55
+ ```
56
+
57
+ ### Search
58
+
59
+ ```bash
60
+ # Search by name, description, or tags
61
+ hooks search security
62
+ hooks search git
63
+ ```
64
+
65
+ ### List by Category
66
+
67
+ ```bash
68
+ hooks list --category "Git Safety"
69
+ hooks list --category "Code Quality"
70
+ ```
71
+
72
+ ### Hook Info
73
+
74
+ ```bash
75
+ hooks info gitguard
76
+ ```
77
+
78
+ ### Check Registered Hooks
79
+
80
+ ```bash
81
+ hooks list --registered
82
+ ```
83
+
84
+ ### Remove
85
+
86
+ ```bash
87
+ hooks remove gitguard
88
+ ```
89
+
90
+ ## Available Hooks (15)
91
+
92
+ ### Git Safety (3)
93
+ | Hook | Event | Description |
94
+ |------|-------|-------------|
95
+ | gitguard | PreToolUse | Blocks destructive git operations like reset --hard, push --force, clean -f |
96
+ | branchprotect | PreToolUse | Prevents editing files directly on main/master branch |
97
+ | checkpoint | PreToolUse | Creates shadow git snapshots before file modifications for easy rollback |
98
+
99
+ ### Code Quality (6)
100
+ | Hook | Event | Description |
101
+ |------|-------|-------------|
102
+ | checktests | PostToolUse | Checks for missing tests after file edits |
103
+ | checklint | PostToolUse | Runs linting after file edits and creates tasks for errors |
104
+ | checkfiles | PostToolUse | Runs headless agent to review files and create tasks |
105
+ | checkbugs | PostToolUse | Checks for bugs via Codex headless agent |
106
+ | checkdocs | PostToolUse | Checks for missing documentation and creates tasks |
107
+ | checktasks | PostToolUse | Validates task completion and tracks progress |
108
+
109
+ ### Security (2)
110
+ | Hook | Event | Description |
111
+ |------|-------|-------------|
112
+ | checksecurity | PostToolUse | Runs security checks via Claude and Codex headless agents |
113
+ | packageage | PreToolUse | Checks package age before install to prevent typosquatting |
114
+
115
+ ### Notifications (2)
116
+ | Hook | Event | Description |
117
+ |------|-------|-------------|
118
+ | phonenotify | Stop | Sends push notifications to phone via ntfy.sh |
119
+ | agentmessages | Stop | Inter-agent messaging integration for service-message |
120
+
121
+ ### Context Management (2)
122
+ | Hook | Event | Description |
123
+ |------|-------|-------------|
124
+ | contextrefresh | Notification | Re-injects important context every N prompts to prevent drift |
125
+ | precompact | Notification | Saves session state before context compaction |
126
+
127
+ ## How Hooks Work
128
+
129
+ Claude Code hooks are lifecycle interceptors that run during agent sessions:
130
+
131
+ - **PreToolUse**: Runs before a tool executes. Can **block** the operation.
132
+ - **PostToolUse**: Runs after a tool executes. Async, non-blocking.
133
+ - **Stop**: Runs when a session ends. Async, non-blocking.
134
+ - **Notification**: Runs on notification events. Async, non-blocking.
135
+
136
+ Each hook receives JSON on stdin and outputs JSON on stdout:
137
+
138
+ ```json
139
+ // PreToolUse input
140
+ {
141
+ "session_id": "abc123",
142
+ "cwd": "/path/to/project",
143
+ "tool_name": "Bash",
144
+ "tool_input": { "command": "git push --force" }
145
+ }
146
+
147
+ // PreToolUse output (block)
148
+ { "decision": "block", "reason": "Destructive git operation blocked" }
149
+
150
+ // PreToolUse output (approve)
151
+ { "decision": "approve" }
152
+ ```
153
+
154
+ ## Hook Structure
155
+
156
+ Each hook follows a consistent structure:
157
+
158
+ ```
159
+ hook-{name}/
160
+ ├── src/
161
+ │ ├── hook.ts # Main hook logic (stdin → stdout)
162
+ │ ├── cli.ts # CLI for install/uninstall/status
163
+ │ └── index.ts # Library exports
164
+ ├── package.json
165
+ ├── CLAUDE.md
166
+ ├── README.md
167
+ └── tsconfig.json
168
+ ```
169
+
170
+ ## Installing Individual Hooks
171
+
172
+ You can also install hooks individually as npm packages:
173
+
174
+ ```bash
175
+ bun install -g @hasna/hook-gitguard
176
+ bun install -g @hasna/hook-branchprotect
177
+ bun install -g @hasna/hook-checkpoint
178
+ ```
179
+
180
+ Then use their built-in CLI:
181
+
182
+ ```bash
183
+ hook-gitguard install # Register in Claude settings
184
+ hook-gitguard status # Check if registered
185
+ hook-gitguard uninstall # Unregister
186
+ ```
187
+
188
+ ## Configuration
189
+
190
+ Hooks are registered in `~/.claude/settings.json`:
191
+
192
+ ```json
193
+ {
194
+ "hooks": {
195
+ "PreToolUse": [
196
+ {
197
+ "matcher": "Bash",
198
+ "hooks": [
199
+ { "type": "command", "command": "hook-gitguard" }
200
+ ]
201
+ }
202
+ ]
203
+ }
204
+ }
205
+ ```
206
+
207
+ ## Development
208
+
209
+ ```bash
210
+ # Install dependencies
211
+ bun install
212
+
213
+ # Run CLI in development
214
+ bun run dev
215
+
216
+ # Build
217
+ bun run build
218
+
219
+ # Type check
220
+ bun run typecheck
221
+ ```
222
+
223
+ ## Contributing
224
+
225
+ 1. Fork the repository
226
+ 2. Create a new hook in `hooks/hook-{name}/`
227
+ 3. Follow the existing hook patterns
228
+ 4. Submit a pull request
229
+
230
+ ## License
231
+
232
+ MIT