claude-mem 3.3.7 → 3.3.9

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 (96) hide show
  1. package/README.md +183 -46
  2. package/dist/bin/cli.d.ts +2 -0
  3. package/dist/bin/cli.js +179 -0
  4. package/dist/commands/compress.d.ts +2 -0
  5. package/dist/commands/compress.js +27 -0
  6. package/dist/commands/hooks.d.ts +19 -0
  7. package/dist/commands/hooks.js +131 -0
  8. package/dist/commands/install.d.ts +2 -0
  9. package/dist/commands/install.js +836 -0
  10. package/dist/commands/load-context.d.ts +2 -0
  11. package/dist/commands/load-context.js +151 -0
  12. package/dist/commands/logs.d.ts +2 -0
  13. package/dist/commands/logs.js +76 -0
  14. package/dist/commands/migrate-to-jsonl.d.ts +5 -0
  15. package/dist/commands/migrate-to-jsonl.js +99 -0
  16. package/dist/commands/restore.d.ts +1 -0
  17. package/dist/commands/restore.js +20 -0
  18. package/dist/commands/status.d.ts +1 -0
  19. package/dist/commands/status.js +136 -0
  20. package/dist/commands/trash-empty.d.ts +3 -0
  21. package/dist/commands/trash-empty.js +56 -0
  22. package/dist/commands/trash-view.d.ts +1 -0
  23. package/dist/commands/trash-view.js +101 -0
  24. package/dist/commands/trash.d.ts +6 -0
  25. package/dist/commands/trash.js +49 -0
  26. package/dist/commands/uninstall.d.ts +2 -0
  27. package/dist/commands/uninstall.js +107 -0
  28. package/dist/constants.d.ts +271 -0
  29. package/dist/constants.js +199 -0
  30. package/dist/core/compression/TranscriptCompressor.d.ts +79 -0
  31. package/dist/core/compression/TranscriptCompressor.js +585 -0
  32. package/dist/core/orchestration/PromptOrchestrator.d.ts +165 -0
  33. package/dist/core/orchestration/PromptOrchestrator.js +182 -0
  34. package/dist/lib/time-utils.d.ts +5 -0
  35. package/dist/lib/time-utils.js +70 -0
  36. package/dist/prompts/constants.d.ts +126 -0
  37. package/dist/prompts/constants.js +161 -0
  38. package/dist/prompts/index.d.ts +10 -0
  39. package/dist/prompts/index.js +11 -0
  40. package/dist/prompts/templates/analysis/AnalysisTemplates.d.ts +13 -0
  41. package/dist/prompts/templates/analysis/AnalysisTemplates.js +94 -0
  42. package/dist/prompts/templates/context/ContextTemplates.d.ts +119 -0
  43. package/dist/prompts/templates/context/ContextTemplates.js +399 -0
  44. package/dist/prompts/templates/hooks/HookTemplates.d.ts +175 -0
  45. package/dist/prompts/templates/hooks/HookTemplates.js +394 -0
  46. package/dist/prompts/templates/hooks/HookTemplates.test.d.ts +7 -0
  47. package/dist/prompts/templates/hooks/HookTemplates.test.js +127 -0
  48. package/dist/shared/config.d.ts +4 -0
  49. package/dist/shared/config.js +41 -0
  50. package/dist/shared/error-handler.d.ts +22 -0
  51. package/dist/shared/error-handler.js +142 -0
  52. package/dist/shared/logger.d.ts +19 -0
  53. package/dist/shared/logger.js +51 -0
  54. package/dist/shared/paths.d.ts +28 -0
  55. package/dist/shared/paths.js +100 -0
  56. package/dist/shared/settings.d.ts +41 -0
  57. package/dist/shared/settings.js +81 -0
  58. package/dist/shared/types.d.ts +145 -0
  59. package/dist/shared/types.js +78 -0
  60. package/docs/STATUS.md +155 -0
  61. package/docs/chroma-backend-migration.md +161 -0
  62. package/docs/landing-page-outline.md +287 -0
  63. package/docs/multi-platform-builds.md +96 -0
  64. package/docs/plans/cloud-service-plan.md +274 -0
  65. package/docs/plans/fix-response-format-issue.md +61 -0
  66. package/docs/plans/restructure-session-hook-output.md +102 -0
  67. package/docs/plans/session-start-hook-investigation.md +45 -0
  68. package/docs/plans/src-reorganization-plan.md +181 -0
  69. package/docs/plans/terminal-effects-decision.md +22 -0
  70. package/docs/plans/terminal-effects-integration.md +82 -0
  71. package/docs/plans/trash-bin-feature-plan.md +240 -0
  72. package/docs/plans/trash-bin-minimal-plan.md +102 -0
  73. package/docs/reference/bun-single-executable.md +584 -0
  74. package/docs/reference/cc-output-styles.md +99 -0
  75. package/docs/reference/chroma-mcp-project-memory-example.md +80 -0
  76. package/docs/reference/chroma-mcp-team-example.md +92 -0
  77. package/docs/reference/claude-code/cc-hooks.md +787 -0
  78. package/docs/reference/claude-code/cc-status-line.md +202 -0
  79. package/docs/reference/claude-code/hook-configuration.md +173 -0
  80. package/docs/reference/claude-code/hook-responses.md +127 -0
  81. package/docs/reference/claude-code/hooks.md +175 -0
  82. package/docs/reference/claude-code/mcp-configuration.md +133 -0
  83. package/docs/reference/claude-code/session-start-hook.md +82 -0
  84. package/docs/reference/load-context-format-example.md +33 -0
  85. package/docs/reference/mcp-sdk/mcp-typescript-sdk-readme.md +1323 -0
  86. package/docs/reference/mcp-sdk/server-implementation.md +286 -0
  87. package/docs/reference/mcp-sdk/stdio-transport.md +345 -0
  88. package/docs/todos/fix-response-format-tasks.md +43 -0
  89. package/docs/todos/implementation-todos.md +280 -0
  90. package/docs/todos/restructure-hook-output-tasks.md +103 -0
  91. package/docs/todos/session-start-hook-fix.md +26 -0
  92. package/docs/todos/terminal-effects-tasks.md +42 -0
  93. package/docs/todos/trash-bin-implementation-todos.md +348 -0
  94. package/docs/todos/trash-bin-minimal-todos.md +27 -0
  95. package/package.json +56 -6
  96. package/claude-mem +0 -0
@@ -0,0 +1,202 @@
1
+ # Status line configuration
2
+
3
+ > Create a custom status line for Claude Code to display contextual information
4
+
5
+ Make Claude Code your own with a custom status line that displays at the bottom of the Claude Code interface, similar to how terminal prompts (PS1) work in shells like Oh-my-zsh.
6
+
7
+ ## Create a custom status line
8
+
9
+ You can either:
10
+
11
+ * Run `/statusline` to ask Claude Code to help you set up a custom status line. By default, it will try to reproduce your terminal's prompt, but you can provide additional instructions about the behavior you want to Claude Code, such as `/statusline show the model name in orange`
12
+
13
+ * Directly add a `statusLine` command to your `.claude/settings.json`:
14
+
15
+ ```json
16
+ {
17
+ "statusLine": {
18
+ "type": "command",
19
+ "command": "~/.claude/statusline.sh",
20
+ "padding": 0 // Optional: set to 0 to let status line go to edge
21
+ }
22
+ }
23
+ ```
24
+
25
+ ## How it Works
26
+
27
+ * The status line is updated when the conversation messages update
28
+ * Updates run at most every 300ms
29
+ * The first line of stdout from your command becomes the status line text
30
+ * ANSI color codes are supported for styling your status line
31
+ * Claude Code passes contextual information about the current session (model, directories, etc.) as JSON to your script via stdin
32
+
33
+ ## JSON Input Structure
34
+
35
+ Your status line command receives structured data via stdin in JSON format:
36
+
37
+ ```json
38
+ {
39
+ "hook_event_name": "Status",
40
+ "session_id": "abc123...",
41
+ "transcript_path": "/path/to/transcript.json",
42
+ "cwd": "/current/working/directory",
43
+ "model": {
44
+ "id": "claude-opus-4-1",
45
+ "display_name": "Opus"
46
+ },
47
+ "workspace": {
48
+ "current_dir": "/current/working/directory",
49
+ "project_dir": "/original/project/directory"
50
+ },
51
+ "version": "1.0.80",
52
+ "output_style": {
53
+ "name": "default"
54
+ },
55
+ "cost": {
56
+ "total_cost_usd": 0.01234,
57
+ "total_duration_ms": 45000,
58
+ "total_api_duration_ms": 2300,
59
+ "total_lines_added": 156,
60
+ "total_lines_removed": 23
61
+ }
62
+ }
63
+ ```
64
+
65
+ ## Example Scripts
66
+
67
+ ### Simple Status Line
68
+
69
+ ```bash
70
+ #!/bin/bash
71
+ # Read JSON input from stdin
72
+ input=$(cat)
73
+
74
+ # Extract values using jq
75
+ MODEL_DISPLAY=$(echo "$input" | jq -r '.model.display_name')
76
+ CURRENT_DIR=$(echo "$input" | jq -r '.workspace.current_dir')
77
+
78
+ echo "[$MODEL_DISPLAY] 📁 ${CURRENT_DIR##*/}"
79
+ ```
80
+
81
+ ### Git-Aware Status Line
82
+
83
+ ```bash
84
+ #!/bin/bash
85
+ # Read JSON input from stdin
86
+ input=$(cat)
87
+
88
+ # Extract values using jq
89
+ MODEL_DISPLAY=$(echo "$input" | jq -r '.model.display_name')
90
+ CURRENT_DIR=$(echo "$input" | jq -r '.workspace.current_dir')
91
+
92
+ # Show git branch if in a git repo
93
+ GIT_BRANCH=""
94
+ if git rev-parse --git-dir > /dev/null 2>&1; then
95
+ BRANCH=$(git branch --show-current 2>/dev/null)
96
+ if [ -n "$BRANCH" ]; then
97
+ GIT_BRANCH=" | 🌿 $BRANCH"
98
+ fi
99
+ fi
100
+
101
+ echo "[$MODEL_DISPLAY] 📁 ${CURRENT_DIR##*/}$GIT_BRANCH"
102
+ ```
103
+
104
+ ### Python Example
105
+
106
+ ```python
107
+ #!/usr/bin/env python3
108
+ import json
109
+ import sys
110
+ import os
111
+
112
+ # Read JSON from stdin
113
+ data = json.load(sys.stdin)
114
+
115
+ # Extract values
116
+ model = data['model']['display_name']
117
+ current_dir = os.path.basename(data['workspace']['current_dir'])
118
+
119
+ # Check for git branch
120
+ git_branch = ""
121
+ if os.path.exists('.git'):
122
+ try:
123
+ with open('.git/HEAD', 'r') as f:
124
+ ref = f.read().strip()
125
+ if ref.startswith('ref: refs/heads/'):
126
+ git_branch = f" | 🌿 {ref.replace('ref: refs/heads/', '')}"
127
+ except:
128
+ pass
129
+
130
+ print(f"[{model}] 📁 {current_dir}{git_branch}")
131
+ ```
132
+
133
+ ### Node.js Example
134
+
135
+ ```javascript
136
+ #!/usr/bin/env node
137
+
138
+ const fs = require('fs');
139
+ const path = require('path');
140
+
141
+ // Read JSON from stdin
142
+ let input = '';
143
+ process.stdin.on('data', chunk => input += chunk);
144
+ process.stdin.on('end', () => {
145
+ const data = JSON.parse(input);
146
+
147
+ // Extract values
148
+ const model = data.model.display_name;
149
+ const currentDir = path.basename(data.workspace.current_dir);
150
+
151
+ // Check for git branch
152
+ let gitBranch = '';
153
+ try {
154
+ const headContent = fs.readFileSync('.git/HEAD', 'utf8').trim();
155
+ if (headContent.startsWith('ref: refs/heads/')) {
156
+ gitBranch = ` | 🌿 ${headContent.replace('ref: refs/heads/', '')}`;
157
+ }
158
+ } catch (e) {
159
+ // Not a git repo or can't read HEAD
160
+ }
161
+
162
+ console.log(`[${model}] 📁 ${currentDir}${gitBranch}`);
163
+ });
164
+ ```
165
+
166
+ ### Helper Function Approach
167
+
168
+ For more complex bash scripts, you can create helper functions:
169
+
170
+ ```bash
171
+ #!/bin/bash
172
+ # Read JSON input once
173
+ input=$(cat)
174
+
175
+ # Helper functions for common extractions
176
+ get_model_name() { echo "$input" | jq -r '.model.display_name'; }
177
+ get_current_dir() { echo "$input" | jq -r '.workspace.current_dir'; }
178
+ get_project_dir() { echo "$input" | jq -r '.workspace.project_dir'; }
179
+ get_version() { echo "$input" | jq -r '.version'; }
180
+ get_cost() { echo "$input" | jq -r '.cost.total_cost_usd'; }
181
+ get_duration() { echo "$input" | jq -r '.cost.total_duration_ms'; }
182
+ get_lines_added() { echo "$input" | jq -r '.cost.total_lines_added'; }
183
+ get_lines_removed() { echo "$input" | jq -r '.cost.total_lines_removed'; }
184
+
185
+ # Use the helpers
186
+ MODEL=$(get_model_name)
187
+ DIR=$(get_current_dir)
188
+ echo "[$MODEL] 📁 ${DIR##*/}"
189
+ ```
190
+
191
+ ## Tips
192
+
193
+ * Keep your status line concise - it should fit on one line
194
+ * Use emojis (if your terminal supports them) and colors to make information scannable
195
+ * Use `jq` for JSON parsing in Bash (see examples above)
196
+ * Test your script by running it manually with mock JSON input: `echo '{"model":{"display_name":"Test"},"workspace":{"current_dir":"/test"}}' | ./statusline.sh`
197
+ * Consider caching expensive operations (like git status) if needed
198
+
199
+ ## Troubleshooting
200
+
201
+ * If your status line doesn't appear, check that your script is executable (`chmod +x`)
202
+ * Ensure your script outputs to stdout (not stderr)
@@ -0,0 +1,173 @@
1
+ # Claude Code Hook Configuration Documentation
2
+
3
+ **LOCKED by @docs-agent | Change to 🔑 to allow @docs-agent edits**
4
+
5
+ ## Official Documentation Reference
6
+
7
+ - **Source**: Claude Code Hooks API Documentation
8
+ - **Version**: v2025
9
+ - **Last Verified**: 2025-08-31
10
+ - **Official URL**: https://docs.anthropic.com/en/docs/claude-code/hooks
11
+
12
+ ## Hook Configuration Structure
13
+
14
+ ### Two Categories of Hooks
15
+
16
+ Claude Code hooks are divided into two distinct categories with different configuration structures:
17
+
18
+ #### 1. Tool-Related Hooks
19
+ These hooks are triggered in relation to tool usage and require a `matcher` field:
20
+ - `PreToolUse`: Executed before a tool is invoked
21
+ - `PostToolUse`: Executed after a tool completes
22
+
23
+ **Configuration Structure:**
24
+ ```json
25
+ {
26
+ "hooks": {
27
+ "PreToolUse": [
28
+ {
29
+ "matcher": "Edit|MultiEdit|Write",
30
+ "hooks": [
31
+ {
32
+ "type": "command",
33
+ "command": "/path/to/script.js",
34
+ "timeout": 60000
35
+ }
36
+ ]
37
+ }
38
+ ]
39
+ }
40
+ }
41
+ ```
42
+
43
+ #### 2. Non-Tool Hooks
44
+ These hooks are triggered by system events and **MUST NOT** have a `matcher` or `pattern` field:
45
+ - `PreCompact`: Before conversation compaction
46
+ - `SessionStart`: When a new session begins
47
+ - `SessionEnd`: When a session ends
48
+ - `UserPromptSubmit`: When user submits a prompt
49
+ - `Notification`: For system notifications
50
+ - `Stop`: When Claude is stopping
51
+ - `SubagentStop`: When a subagent is stopping
52
+
53
+ **Configuration Structure:**
54
+ ```json
55
+ {
56
+ "hooks": {
57
+ "SessionStart": [
58
+ {
59
+ "hooks": [
60
+ {
61
+ "type": "command",
62
+ "command": "/path/to/script.js",
63
+ "timeout": 30000
64
+ }
65
+ ]
66
+ }
67
+ ]
68
+ }
69
+ }
70
+ ```
71
+
72
+ ## Common Configuration Mistakes
73
+
74
+ ### ❌ INCORRECT: Adding `pattern` field to non-tool hooks
75
+ ```json
76
+ {
77
+ "hooks": {
78
+ "PreCompact": [
79
+ {
80
+ "pattern": "*", // WRONG: Non-tool hooks don't use patterns
81
+ "hooks": [...]
82
+ }
83
+ ]
84
+ }
85
+ }
86
+ ```
87
+
88
+ ### ✅ CORRECT: Non-tool hooks without matcher
89
+ ```json
90
+ {
91
+ "hooks": {
92
+ "PreCompact": [
93
+ {
94
+ "hooks": [
95
+ {
96
+ "type": "command",
97
+ "command": "/path/to/pre-compact.js",
98
+ "timeout": 180000
99
+ }
100
+ ]
101
+ }
102
+ ]
103
+ }
104
+ }
105
+ ```
106
+
107
+ ## Hook Field Reference
108
+
109
+ ### Common Fields (All Hooks)
110
+ - `type`: Always `"command"` for external scripts
111
+ - `command`: Absolute path to the executable script
112
+ - `timeout`: Optional timeout in milliseconds (default: 60000)
113
+
114
+ ### Tool Hook Specific
115
+ - `matcher`: Regex pattern to match tool names
116
+ - Example: `"Edit|MultiEdit|Write"`
117
+ - Example: `"mcp__.*__write.*"`
118
+ - Example: `"Bash"`
119
+
120
+ ### Environment Variables Available to Hooks
121
+ - `$CLAUDE_PROJECT_DIR`: Project root directory
122
+ - Standard environment variables from the shell
123
+
124
+ ## Hook Input/Output
125
+
126
+ ### Input (via stdin)
127
+ All hooks receive JSON input with common fields:
128
+ ```json
129
+ {
130
+ "session_id": "string",
131
+ "transcript_path": "string",
132
+ "cwd": "string",
133
+ "hook_event_name": "string",
134
+ // Additional event-specific fields
135
+ }
136
+ ```
137
+
138
+ ### Output Options
139
+ Hooks can output:
140
+ 1. **Plain text** (stdout): Added as context
141
+ 2. **JSON** (stdout): Structured response for decisions
142
+ 3. **Exit codes**:
143
+ - `0`: Success, continue normally
144
+ - `1`: General error
145
+ - `2`: Block operation (for PreToolUse)
146
+
147
+ ## Implementation Notes
148
+
149
+ ### File Locations
150
+ - User settings: `~/.claude/settings.json`
151
+ - Project settings: `./.claude/settings.json`
152
+ - Local settings: `./.claude/settings.local.json`
153
+
154
+ ### Settings Precedence (Highest to Lowest)
155
+ 1. Enterprise managed policies
156
+ 2. Command line arguments
157
+ 3. Local project settings
158
+ 4. Shared project settings
159
+ 5. User settings
160
+
161
+ ## Cross-References
162
+
163
+ - Code Implementation: `/Users/alexnewman/Scripts/claude-mem/src/commands/install.ts:263-320`
164
+ - Hook Files: `/Users/alexnewman/Scripts/claude-mem/hooks/`
165
+ - User Guide: `/Users/alexnewman/Scripts/claude-mem/README-npm.md`
166
+
167
+ ## Version History
168
+
169
+ - **2025-08-31**: Fixed hook configuration to remove incorrect `pattern` field from non-tool hooks
170
+ - **2025-08-31**: Documented official hook structure requirements per Claude Code API
171
+
172
+ ---
173
+ *This documentation is maintained by @docs-agent and verified against official Anthropic documentation.*
@@ -0,0 +1,127 @@
1
+ # Claude Code Hook Response Format Documentation
2
+ ## Source: Official Claude Code Docs v2025
3
+ ## Last Verified: 2025-08-31
4
+
5
+ ## Common Hook Response Fields
6
+
7
+ All hooks can return these common fields:
8
+
9
+ ```json
10
+ {
11
+ "continue": true, // Whether Claude should continue (default: true)
12
+ "stopReason": "string", // Message shown when continue is false
13
+ "suppressOutput": true, // Hide stdout from transcript (default: false)
14
+ "systemMessage": "string" // Optional warning message shown to user
15
+ }
16
+ ```
17
+
18
+ ## Hook-Specific Response Formats
19
+
20
+ ### PreCompact Hook
21
+ **IMPORTANT**: PreCompact does NOT support `hookSpecificOutput`
22
+
23
+ ```json
24
+ {
25
+ "continue": true,
26
+ "suppressOutput": true
27
+ }
28
+ ```
29
+
30
+ ### SessionStart Hook
31
+ SessionStart DOES support `hookSpecificOutput`:
32
+
33
+ ```json
34
+ {
35
+ "continue": true,
36
+ "hookSpecificOutput": {
37
+ "hookEventName": "SessionStart",
38
+ "additionalContext": "Context string to add to session"
39
+ }
40
+ }
41
+ ```
42
+
43
+ ### PreToolUse Hook
44
+ ```json
45
+ {
46
+ "continue": true,
47
+ "hookSpecificOutput": {
48
+ "hookEventName": "PreToolUse",
49
+ "permissionDecision": "allow" | "deny" | "ask",
50
+ "permissionDecisionReason": "Reason for decision"
51
+ }
52
+ }
53
+ ```
54
+
55
+ ### PostToolUse Hook
56
+ ```json
57
+ {
58
+ "decision": "block", // Optional - blocks further processing
59
+ "reason": "Explanation",
60
+ "hookSpecificOutput": {
61
+ "hookEventName": "PostToolUse",
62
+ "additionalContext": "Additional information for Claude"
63
+ }
64
+ }
65
+ ```
66
+
67
+ ### UserPromptSubmit Hook
68
+ ```json
69
+ {
70
+ "decision": "block", // Optional - blocks the prompt
71
+ "reason": "Security policy violation",
72
+ "hookSpecificOutput": {
73
+ "hookEventName": "UserPromptSubmit",
74
+ "additionalContext": "Additional context for the prompt"
75
+ }
76
+ }
77
+ ```
78
+
79
+ ## Exit Codes
80
+
81
+ - `0`: Success - hook executed successfully
82
+ - `1`: Error - shown to user with stdout
83
+ - `2`: Error - shown to Claude with stderr
84
+
85
+ ## Common Mistakes to Avoid
86
+
87
+ ### \u274c INCORRECT: Using wrong field names
88
+ ```javascript
89
+ // WRONG
90
+ {
91
+ "decision": "block", // \u274c Wrong field
92
+ "reason": "Error message" // \u274c Wrong field
93
+ }
94
+ ```
95
+
96
+ ### \u2705 CORRECT: Using official field names
97
+ ```javascript
98
+ // RIGHT
99
+ {
100
+ "continue": false,
101
+ "stopReason": "Error message"
102
+ }
103
+ ```
104
+
105
+ ### \u274c INCORRECT: Adding hookSpecificOutput to PreCompact
106
+ ```javascript
107
+ // WRONG - PreCompact doesn't support this
108
+ {
109
+ "hookSpecificOutput": {
110
+ "hookEventName": "PreCompact",
111
+ "status": "success"
112
+ }
113
+ }
114
+ ```
115
+
116
+ ### \u2705 CORRECT: Simple response for PreCompact
117
+ ```javascript
118
+ // RIGHT
119
+ {
120
+ "continue": true,
121
+ "suppressOutput": true
122
+ }
123
+ ```
124
+
125
+ ## References
126
+ - Official Docs: https://docs.anthropic.com/en/docs/claude-code/hooks
127
+ - Hook Examples: https://docs.anthropic.com/en/docs/claude-code/hooks-guide
@@ -0,0 +1,175 @@
1
+ # Claude Code Hooks Configuration Documentation
2
+ ## Source: Official Claude Code Docs v2025
3
+ ## Last Verified: 2025-08-31
4
+
5
+ ## Hook Configuration Structure
6
+
7
+ ### For Tool-Based Hooks (PreToolUse, PostToolUse)
8
+ These hooks use the `matcher` field to match tool patterns:
9
+
10
+ ```json
11
+ {
12
+ "hooks": {
13
+ "PreToolUse": [
14
+ {
15
+ "matcher": "ToolPattern", // Required for tool hooks
16
+ "hooks": [
17
+ {
18
+ "type": "command",
19
+ "command": "your-command-here",
20
+ "timeout": 60000 // Optional, in milliseconds
21
+ }
22
+ ]
23
+ }
24
+ ]
25
+ }
26
+ }
27
+ ```
28
+
29
+ ### For Non-Tool Hooks (PreCompact, SessionStart, etc.)
30
+ These hooks DO NOT use matcher/pattern fields:
31
+
32
+ ```json
33
+ {
34
+ "hooks": {
35
+ "PreCompact": [
36
+ {
37
+ // NO matcher or pattern field!
38
+ "hooks": [
39
+ {
40
+ "type": "command",
41
+ "command": "/path/to/script.js",
42
+ "timeout": 180000
43
+ }
44
+ ]
45
+ }
46
+ ]
47
+ }
48
+ }
49
+ ```
50
+
51
+ ## Available Hook Events
52
+
53
+ ### Tool-Related Hooks (use matcher)
54
+ - **PreToolUse**: Before tool execution
55
+ - **PostToolUse**: After tool execution
56
+
57
+ ### System Event Hooks (no matcher)
58
+ - **PreCompact**: Before conversation compaction
59
+ - **SessionStart**: When session begins
60
+ - **SessionEnd**: When session ends (not in official docs)
61
+ - **UserPromptSubmit**: When user submits prompt
62
+ - **Notification**: When Claude needs user input
63
+ - **Stop**: When stop is requested
64
+ - **SubagentStop**: When subagent stop is requested
65
+
66
+ ## Hook Payload Structure
67
+
68
+ ### Common Fields (all hooks)
69
+ ```json
70
+ {
71
+ "session_id": "string",
72
+ "transcript_path": "string",
73
+ "hook_event_name": "string",
74
+ "cwd": "string" // Current working directory
75
+ }
76
+ ```
77
+
78
+ ### PreCompact Specific
79
+ ```json
80
+ {
81
+ "hook_event_name": "PreCompact",
82
+ "trigger": "manual" | "auto",
83
+ "custom_instructions": "string"
84
+ }
85
+ ```
86
+
87
+ ### SessionStart Specific
88
+ ```json
89
+ {
90
+ "hook_event_name": "SessionStart",
91
+ "source": "startup" | "compact" | "vscode" | "web"
92
+ }
93
+ ```
94
+
95
+ ### PreToolUse/PostToolUse Specific
96
+ ```json
97
+ {
98
+ "tool_name": "string",
99
+ "tool_input": { /* tool specific */ },
100
+ "tool_response": { /* PostToolUse only */ }
101
+ }
102
+ ```
103
+
104
+ ## Common Configuration Mistakes
105
+
106
+ ### \u274c INCORRECT: Using 'pattern' for non-tool hooks
107
+ ```json
108
+ {
109
+ "hooks": {
110
+ "PreCompact": [{
111
+ "pattern": "*", // \u274c WRONG - non-tool hooks don't use this
112
+ "hooks": [...]
113
+ }]
114
+ }
115
+ }
116
+ ```
117
+
118
+ ### \u2705 CORRECT: No matcher for non-tool hooks
119
+ ```json
120
+ {
121
+ "hooks": {
122
+ "PreCompact": [{
123
+ // No pattern or matcher field
124
+ "hooks": [...]
125
+ }]
126
+ }
127
+ }
128
+ ```
129
+
130
+ ### \u274c INCORRECT: Wrong matcher field name
131
+ ```json
132
+ {
133
+ "hooks": {
134
+ "PreToolUse": [{
135
+ "pattern": "Bash", // \u274c WRONG field name
136
+ "hooks": [...]
137
+ }]
138
+ }
139
+ }
140
+ ```
141
+
142
+ ### \u2705 CORRECT: Using 'matcher' for tool hooks
143
+ ```json
144
+ {
145
+ "hooks": {
146
+ "PreToolUse": [{
147
+ "matcher": "Bash", // \u2705 Correct field name
148
+ "hooks": [...]
149
+ }]
150
+ }
151
+ }
152
+ ```
153
+
154
+ ## Matcher Patterns for Tool Hooks
155
+
156
+ - **Exact match**: `"Bash"` - matches only Bash tool
157
+ - **Multiple tools**: `"Edit|MultiEdit|Write"` - matches any of these
158
+ - **MCP tools**: `"mcp__memory__.*"` - matches all memory server tools
159
+ - **All tools**: `"*"` - matches everything
160
+
161
+ ## Environment Variables
162
+
163
+ Hooks have access to:
164
+ - `$CLAUDE_PROJECT_DIR` - Project root directory
165
+
166
+ ## Settings File Locations
167
+
168
+ 1. **User settings**: `~/.claude/settings.json`
169
+ 2. **Project settings**: `./.claude/settings.json`
170
+ 3. **Local settings**: `./.claude/settings.local.json`
171
+ 4. **Managed settings**: `/Library/Application Support/ClaudeCode/managed-settings.json`
172
+
173
+ ## References
174
+ - Official Docs: https://docs.anthropic.com/en/docs/claude-code/hooks
175
+ - Hook Guide: https://docs.anthropic.com/en/docs/claude-code/hooks-guide