Summary
Add a SessionEnd hook that logs basic session metadata to a text file, establishing the pattern for session tracking and analytics.
Follows the precedent established by #1414 (Notification hook) as the second hook implementation in the project.
Motivation
Track Claude Code sessions for future analysis and debugging. Start with the simplest possible implementation (tracer bullet) that can be enhanced later.
Implementation
Add SessionEnd hook to .claude/settings.json that:
- Logs session_id, transcript_path, timestamp, and exit reason
- Writes to
~/.claude/sessions/log.txt
- Uses simple text format (human-readable)
Configuration to add:
```json
"SessionEnd": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "mkdir -p ~/.claude/sessions && echo "$(date -Iseconds) | Session: $(jq -r .session_id) | Transcript: $(jq -r .transcript_path) | Reason: $(jq -r .reason)" >> ~/.claude/sessions/log.txt"
}
]
}
]
```
Test Plan
Example Output
```
2025-10-28T14:23:45-05:00 | Session: abc123 | Transcript: ~/.claude/projects/.../session.jsonl | Reason: clear
```
Future Enhancements
- Upgrade to JSONL format for structured queries
- Add transcript archiving to prevent data loss from cleanupPeriodDays
- Build summary generation tool that reads session logs
Related
Principles
- tracer-bullets: Start with simplest working implementation
- versioning-mindset: Build foundation for future iteration
Summary
Add a SessionEnd hook that logs basic session metadata to a text file, establishing the pattern for session tracking and analytics.
Follows the precedent established by #1414 (Notification hook) as the second hook implementation in the project.
Motivation
Track Claude Code sessions for future analysis and debugging. Start with the simplest possible implementation (tracer bullet) that can be enhanced later.
Implementation
Add SessionEnd hook to
.claude/settings.jsonthat:~/.claude/sessions/log.txtConfiguration to add:$(jq -r .session_id) | Transcript: $ (jq -r .transcript_path) | Reason: $(jq -r .reason)" >> ~/.claude/sessions/log.txt"
```json
"SessionEnd": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "mkdir -p ~/.claude/sessions && echo "$(date -Iseconds) | Session:
}
]
}
]
```
Test Plan
.claude/settings.jsonExample Output
```
2025-10-28T14:23:45-05:00 | Session: abc123 | Transcript: ~/.claude/projects/.../session.jsonl | Reason: clear
```
Future Enhancements
Related
Principles