A reliable solution to automatically log Claude Code interactions to project-specific markdown files.
Claude Code only stores your inputs (messages, files) in .claude.json, not AI responses. This solution creates persistent logs of when interactions occurred, organized by project directory with automatic archival.
- Automatic Logging: Creates
CLAUDE_SESSION_LOG.mdin each project directory - Per-Project Logs: Each directory gets its own interaction history
- Archive System: Monthly archives when logs get large (preserves all data)
- Reliable: Built with failure-safe design - won't break Claude if logging fails
- Chronological: Complete timeline of when you used Claude in each project
# Download and install the script
curl -o ~/.local/bin/claude_response_logger.sh https://gist.githubusercontent.com/[GIST_URL]/claude_response_logger.sh
chmod +x ~/.local/bin/claude_response_logger.shAdd this to your ~/.claude/settings.json:
{
"model": "sonnet",
"hooks": {
"stop": {
"command": "/Users/[USERNAME]/.local/bin/claude_response_logger.sh",
"timeout": 5000,
"continueOnFailure": true
}
}
}Replace [USERNAME] with your actual username.
your-project/
├── CLAUDE_SESSION_LOG.md # Recent interactions (500 entries max)
├── CLAUDE_SESSION_LOG_ARCHIVE_2025-08.md # August 2025 archive
├── CLAUDE_SESSION_LOG_ARCHIVE_2025-09.md # September 2025 archive
└── (your project files...)
# Claude Session Log
This file contains summaries of Claude Code interactions for this project.
---
## Session: 2025-08-25 15:30:42
- **Project:** my-awesome-app
- **Directory:** /Users/john/projects/my-awesome-app
- **User:** john
- **Action:** Claude interaction completed
---
## Session: 2025-08-25 16:15:23
- **Project:** my-awesome-app
- **Directory:** /Users/john/projects/my-awesome-app
- **User:** john
- **Action:** Claude interaction completed
---- Failure-safe: Uses
continueOnFailure: true- won't break Claude - Timeout protection: 5-second limit prevents hanging
- Error handling: Built with
set -efor proper error handling
- No data loss: Archives old entries instead of deleting them
- Monthly archives: Organized by year-month for easy browsing
- Chronological order: Maintains timeline across archives
- Per-directory logs: Each project gets its own history
- Automatic creation: Creates log files as needed
- Path-based: Works from any directory you run Claude from
Edit the script and modify:
if [[ $(wc -l < "$LOG_FILE") -gt 1000 ]]; then # Change 1000 to your preferenceEdit the script and modify:
head -500 "$LOG_FILE" >> "$ARCHIVE_FILE" # Change 500 to your preference
tail -500 "$LOG_FILE" > "${LOG_FILE}.tmp" # Change 500 to your preferenceModify the section that writes to $LOG_FILE to include different information.
- Check your
~/.claude/settings.jsonsyntax withcat ~/.claude/settings.json - Verify script path:
ls -la ~/.local/bin/claude_response_logger.sh - Test script manually:
~/.local/bin/claude_response_logger.sh
# Make sure script is executable
chmod +x ~/.local/bin/claude_response_logger.sh
# Make sure ~/.local/bin directory exists
mkdir -p ~/.local/bin- Linux/Mac: Use
/home/[username]/.local/bin/claude_response_logger.sh - Mac alternative: Use
/Users/[username]/.local/bin/claude_response_logger.sh - Custom path: Put script anywhere and update the path in settings.json
- Save settings and restart Claude Code
- Have a conversation in any directory
- Check for
CLAUDE_SESSION_LOG.mdfile creation - Verify timestamps match your interaction time
You can modify the script to create different log formats or additional files:
- Add JSON logs for programmatic analysis
- Include git commit information
- Add project type detection
- Include tool usage summaries
- Use with git hooks to commit logs
- Parse logs for productivity analysis
- Generate daily/weekly summaries
- Export to other formats (JSON, CSV)
This solution uses Claude Code's built-in hooks system rather than trying to modify Claude itself. Benefits:
- Official API: Uses documented Claude Code functionality
- Reliable: Doesn't depend on undocumented behavior
- Safe: Won't break when Claude Code updates
- Flexible: Easy to customize for your needs
Feel free to fork and modify this script for your needs. Common improvements:
- Better log formatting
- Integration with version control
- Summary generation
- Tool usage tracking
Created for the Claude Code community. Share and modify freely!