Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Don't install this. Just steal what you like.
| `file-history/` | Change tracking for edited files |
| `session-env/` | Environment snapshots per session |
| `sessions/` | Session state and conversation data |
| `logs/` | Session and commit history logs |
| `logs/` | Per-session hook and git command logs |
| `debug/` | Session debug output |
| `shell-snapshots/` | Shell environment captures |
| `cache/` | Temporary cached data |
Expand Down Expand Up @@ -177,7 +177,7 @@ This configuration includes 11 hooks:

#### Logging Hooks (PreToolUse, PostToolUse, and others)

- **log-git-commands.sh** - Logs all git/gh commands to stderr for tracking
- **log-git-commands.sh** - Logs all git/gh commands to per-session log files
- **log-hook-event.sh** - Companion logger on every lifecycle event for observability

#### Formatting Hooks (PostToolUse)
Expand All @@ -191,20 +191,23 @@ This configuration includes 11 hooks:
- **load-session-context.sh** - Injects git repository context at session start
- **evaluate-session.js** - Analyzes session for learnings and patterns

#### Notification Hooks (Notification)
#### Cleanup Hooks (SessionEnd)

- **notify-idle.sh** - macOS notification when Claude is ready for input
- **session-cleanup.sh** - Removes session log directories older than 7 days and cleans stale debug/snapshot files on session exit

## Common Operations

### Review Recent Activity

```bash
# Check recent session logs
tail -n 50 logs/session-log.txt
# List session log directories
ls logs/

# View commit history
cat logs/commit-log.txt
# Check hook events for a session (last 8 chars of session ID)
tail -n 50 logs/<session-id>/hook-events.log

# View git commands for a session
cat logs/<session-id>/git-commands.log
```

### Inspect Project Metadata
Expand Down
15 changes: 11 additions & 4 deletions hooks/log-git-commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@
#
# Note: Intentionally no 'set -euo pipefail' - hooks must always exit 0

command=$(jq -r '.tool_input.command // empty' 2>/dev/null || echo "")
description=$(jq -r '.tool_input.description // "No description"' 2>/dev/null || echo "No description")
input=$(cat)
command=$(echo "$input" | jq -r '.tool_input.command // empty' 2>/dev/null || echo "")
description=$(echo "$input" | jq -r '.tool_input.description // "No description"' 2>/dev/null || echo "No description")

# Only log git/gh/dot commands
if echo "$command" | grep -qE '^(git|gh|dot)\s'; then
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
mkdir -p ~/.claude/logs
echo "[$timestamp] $command | $description" >>~/.claude/logs/git-commands.log
# Extract session ID from stdin JSON (last 8 chars)
session_id=$(echo "$input" | jq -r '.session_id // empty' 2>/dev/null)
session_id="${session_id: -8}"
session_id="${session_id//[^a-zA-Z0-9]/_}"
session_id="${session_id:-default}"
log_dir=~/.claude/logs/"$session_id"
mkdir -p "$log_dir"
echo "[$timestamp] $command | $description" >>"$log_dir"/git-commands.log
fi

exit 0 # Never block, just log
11 changes: 9 additions & 2 deletions hooks/log-hook-event.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@

event_name="$1"
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
mkdir -p ~/.claude/logs

input=$(cat)
tool=""
tool_input=""

# Extract session ID from stdin JSON (last 8 chars)
session_id=$(echo "$input" | jq -r '.session_id // empty' 2>/dev/null)
session_id="${session_id: -8}"
session_id="${session_id//[^a-zA-Z0-9]/_}"
session_id="${session_id:-default}"
log_dir=~/.claude/logs/"$session_id"
mkdir -p "$log_dir"

if [ -n "$input" ]; then
tool=$(echo "$input" | jq -r '.tool // .tool_name // empty' 2>/dev/null)
tool_input=$(echo "$input" | jq -c '.tool_input // empty' 2>/dev/null)
Expand All @@ -23,6 +30,6 @@ if [ -n "$tool_input" ] && [ "$tool_input" != "null" ]; then
line="$line input=$tool_input"
fi

echo "$line" >>~/.claude/logs/hook-events.log
echo "$line" >>"$log_dir"/hook-events.log

exit 0
19 changes: 19 additions & 0 deletions hooks/session-cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
# SessionEnd cleanup - delete logs and session data older than 7 days
# Note: Intentionally no 'set -euo pipefail' - hooks must always exit 0

log_dir=~/.claude/logs

# Remove session log directories older than 7 days
find "$log_dir" -mindepth 1 -maxdepth 1 -type d -mtime +7 -exec rm -rf -- {} + 2>/dev/null || true

# Remove legacy flat log files from before session-scoped logging
rm -f "$log_dir/hook-events.log" "$log_dir/hook-events.log.1" "$log_dir/git-commands.log" "$log_dir/git-commands.log.1" 2>/dev/null || true

# Remove debug files older than 7 days
find ~/.claude/debug -name "*.txt" -mtime +7 -delete 2>/dev/null || true

# Remove stale shell snapshots older than 7 days
find ~/.claude/shell-snapshots -type f -mtime +7 -delete 2>/dev/null || true

exit 0
9 changes: 9 additions & 0 deletions settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,15 @@
}
],
"SessionEnd": [
{
"hooks": [
{
"type": "command",
"command": "~/.claude/hooks/session-cleanup.sh",
"timeout": 10
}
]
},
{
"hooks": [
{
Expand Down