Skip to content
This repository was archived by the owner on Jan 2, 2026. It is now read-only.

Commit 6c55abb

Browse files
committed
refactor(hooks): restructure hooks.json for Claude Code format
- Convert to Claude Code plugin hook structure - Enable all 3 hooks: SessionStart, UserPromptSubmit, Stop - Add proper timeouts and command paths
1 parent 6d528e9 commit 6c55abb

3 files changed

Lines changed: 60 additions & 38 deletions

File tree

hooks/hooks.json

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,38 @@
11
{
2-
"hooks": [
3-
{
4-
"event": "SessionStart",
5-
"script": "session_start.py",
6-
"description": "Injects relevant memory context at session startup",
7-
"enabled": true
8-
},
9-
{
10-
"event": "UserPromptSubmit",
11-
"script": "user_prompt.py",
12-
"description": "Detects memorable content (decisions, learnings, blockers) and suggests capture",
13-
"enabled": false
14-
},
15-
{
16-
"event": "Stop",
17-
"script": "stop.py",
18-
"description": "Syncs memory index on session end",
19-
"enabled": true
20-
}
21-
]
2+
"description": "Memory Capture Plugin Hooks",
3+
"hooks": {
4+
"SessionStart": [
5+
{
6+
"hooks": [
7+
{
8+
"type": "command",
9+
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/sessionstart.py",
10+
"timeout": 10
11+
}
12+
]
13+
}
14+
],
15+
"UserPromptSubmit": [
16+
{
17+
"hooks": [
18+
{
19+
"type": "command",
20+
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/userpromptsubmit.py",
21+
"timeout": 10
22+
}
23+
]
24+
}
25+
],
26+
"Stop": [
27+
{
28+
"hooks": [
29+
{
30+
"type": "command",
31+
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/stop.py",
32+
"timeout": 30
33+
}
34+
]
35+
}
36+
]
37+
}
2238
}

hooks/stop.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from __future__ import annotations
2121

22+
import json
2223
import sys
2324

2425

@@ -34,14 +35,10 @@ def main() -> None:
3435
handler_main()
3536
except ImportError:
3637
# Library not installed, exit silently (non-blocking)
37-
import json
38-
3938
print(json.dumps({"continue": True}))
4039
sys.exit(0)
4140
except Exception:
4241
# Any unexpected error, exit silently (non-blocking)
43-
import json
44-
4542
print(json.dumps({"continue": True}))
4643
sys.exit(0)
4744

hooks/userpromptsubmit.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from __future__ import annotations
1616

1717
import json
18-
import os
1918
import re
2019
import sys
2120

@@ -33,7 +32,7 @@ def should_capture(prompt: str) -> tuple[bool, str]:
3332
match = re.match(pattern, prompt, re.IGNORECASE)
3433
if match:
3534
# Remove marker and return clean content
36-
clean = prompt[match.end():].strip()
35+
clean = prompt[match.end() :].strip()
3736
return True, clean
3837

3938
return False, prompt
@@ -49,27 +48,37 @@ def capture_memory(content: str) -> dict:
4948
from git_notes_memory import get_capture_service
5049

5150
capture = get_capture_service()
52-
memory = capture.capture_context(
51+
52+
# Use the main capture() method with learnings namespace
53+
# Extract a summary from the first line or first 100 chars
54+
lines = content.strip().split("\n")
55+
summary = lines[0][:100] if lines else content[:100]
56+
57+
result = capture.capture(
58+
namespace="learnings",
59+
summary=summary,
5360
content=content,
54-
source="prompt-hook",
5561
)
5662

57-
return {
58-
"success": True,
59-
"memory_id": memory.id,
60-
"message": f"Captured as memory: {memory.id[:8]}..."
61-
}
63+
if result.success:
64+
return {
65+
"success": True,
66+
"memory_id": result.memory.id,
67+
"message": f"Captured as memory: {result.memory.id[:16]}...",
68+
}
69+
else:
70+
return {
71+
"success": False,
72+
"error": result.warning or "Capture failed",
73+
}
6274

6375
except ImportError:
6476
return {
6577
"success": False,
66-
"error": "git-notes-memory library not installed"
78+
"error": "git-notes-memory library not installed",
6779
}
6880
except Exception as e:
69-
return {
70-
"success": False,
71-
"error": str(e)
72-
}
81+
return {"success": False, "error": str(e)}
7382

7483

7584
def main() -> None:

0 commit comments

Comments
 (0)