Skip to content

Add SessionEnd hook for basic session logging #1416

Description

@atxtechbro

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

  • Add hook configuration to .claude/settings.json
  • Validate JSON syntax with `jq empty .claude/settings.json`
  • Start a Claude Code session
  • Exit the session (type `exit` or Ctrl+D)
  • Verify log entry exists: `cat ~/.claude/sessions/log.txt`
  • Confirm it contains: timestamp, session_id, transcript_path, reason

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions