claude-code-ultimate-guide/examples/hooks/bash/learning-capture.sh
Florian BRUNIAUX 8e63d84b47 docs: factual audit + reference sync — 260 findings corrected
Parallel 6-agent audit against official Anthropic docs (llms-full.txt).
Key corrections applied across permissions, hooks, MCP, security, privacy, reference.yaml.

Highlights:
- Fix MCP config path (~/.claude.json), mcpServers key, variable substitution syntax
- Fix permission modes (5 not 3), :* syntax (×6), Stop event description
- Fix hook JSON field names (hook_event_name, tool_name, tool_input, session_id)
- Fix filesystem restriction docs (permission rules, not settings.json keys)
- Fix data-privacy: 4-tier retention, /bug 5yr warning, ZDR conditions, 5 telemetry opt-out vars
- Add official llms.txt/llms-full.txt references to CLAUDE.md + machine-readable/llms.txt
- Reference.yaml: 375 entries re-synced (92% had wrong line numbers — guide grew 15K→21K lines)
- New script: scripts/resync-reference-yaml.py for automated line number sync
- Quiz: corrected answers for hooks (07), memory settings (03), MCP servers (08)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-26 12:10:14 +01:00

58 lines
1.5 KiB
Bash
Executable file

#!/bin/bash
# Hook: Stop - Capture one learning insight at session end
# Event: Stop (when Claude finishes responding)
# Purpose: Build a learning journal with minimal friction
#
# Exit codes:
# 0 = success (always returns 0 to not block session end)
#
# Output: Appends to ~/claude-learnings.md
#
# Configuration:
# CLAUDE_LEARNING_LOG - Custom log path (default: ~/claude-learnings.md)
# CLAUDE_LEARNING_SKIP - Set to 1 to skip prompt
set -e
# Configuration
LOG_FILE="${CLAUDE_LEARNING_LOG:-$HOME/claude-learnings.md}"
SKIP_PROMPT="${CLAUDE_LEARNING_SKIP:-0}"
# Skip if disabled
if [[ "$SKIP_PROMPT" == "1" ]]; then
exit 0
fi
# Read hook input (not used but consumed to avoid errors)
INPUT=$(cat)
# Get project context
PROJECT_NAME=$(basename "${CLAUDE_PROJECT_DIR:-$(pwd)}")
DATE=$(date +%Y-%m-%d)
TIME=$(date +%H:%M)
# Ensure log file directory exists
mkdir -p "$(dirname "$LOG_FILE")"
# Create log file with header if it doesn't exist
if [[ ! -f "$LOG_FILE" ]]; then
cat > "$LOG_FILE" << 'HEADER'
# Claude Learning Journal
A record of insights captured during coding sessions.
---
HEADER
fi
# Return system message prompting for learning capture
# The user's response will be logged by the next invocation
# (This is a non-blocking prompt approach)
cat << EOF
{
"systemMessage": "Session ending. Quick reflection:\n\nWhat's ONE thing you learned this session?\n\n(Type your answer, or 'skip' to end without logging)\n\nLogging to: $LOG_FILE"
}
EOF
exit 0