Enhance hooks with session-start script and documentation
- Add hooks/scripts/session-start.sh that: - Checks for unsummarized sessions - Checks for pending decisions - Outputs context to session - Update hooks.json to use the script - Add hooks/README.md documenting hook events and configuration This provides automatic context loading at session start. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
47
hooks/scripts/session-start.sh
Executable file
47
hooks/scripts/session-start.sh
Executable file
@@ -0,0 +1,47 @@
|
||||
#!/bin/bash
|
||||
# Session start hook - provides context to Claude
|
||||
# Output is injected into the session as a system reminder
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
CLAUDE_DIR="${HOME}/.claude"
|
||||
STATE_DIR="${CLAUDE_DIR}/state"
|
||||
PA_DIR="${STATE_DIR}/personal-assistant"
|
||||
|
||||
# Check for unsummarized sessions
|
||||
UNSUMMARIZED=0
|
||||
if [[ -f "${PA_DIR}/history/index.json" ]]; then
|
||||
UNSUMMARIZED=$(python3 -c "
|
||||
import json
|
||||
with open('${PA_DIR}/history/index.json') as f:
|
||||
data = json.load(f)
|
||||
unsummarized = [s for s in data.get('sessions', []) if not s.get('summarized', False)]
|
||||
print(len(unsummarized))
|
||||
" 2>/dev/null || echo "0")
|
||||
fi
|
||||
|
||||
# Check for pending memory items
|
||||
PENDING_DECISIONS=0
|
||||
if [[ -f "${PA_DIR}/memory/decisions.json" ]]; then
|
||||
PENDING_DECISIONS=$(python3 -c "
|
||||
import json
|
||||
with open('${PA_DIR}/memory/decisions.json') as f:
|
||||
data = json.load(f)
|
||||
pending = [d for d in data.get('items', []) if d.get('status') == 'pending']
|
||||
print(len(pending))
|
||||
" 2>/dev/null || echo "0")
|
||||
fi
|
||||
|
||||
# Output context as system reminder format
|
||||
echo "SessionStart:Callback hook success: Success"
|
||||
|
||||
# Add additional context if there's something noteworthy
|
||||
if [[ "${UNSUMMARIZED}" -gt 0 || "${PENDING_DECISIONS}" -gt 0 ]]; then
|
||||
echo "SessionStart hook additional context: "
|
||||
if [[ "${UNSUMMARIZED}" -gt 0 ]]; then
|
||||
echo "- ${UNSUMMARIZED} unsummarized session(s) available for review"
|
||||
fi
|
||||
if [[ "${PENDING_DECISIONS}" -gt 0 ]]; then
|
||||
echo "- ${PENDING_DECISIONS} pending decision(s) to review"
|
||||
fi
|
||||
fi
|
||||
Reference in New Issue
Block a user