[FEATURE] Include Modified Files in Hook Input
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
Problem Statement
When using SessionEnd and Stop hooks to perform actions on modified files (like running linters, formatters, or tests), I can't easily determine which specific files Claude modified during the session. Current workarounds require either parsing the entire transcript JSON file to extract tool calls, or using git diff which includes changes made outside the Claude session. This makes it difficult to create efficient hooks that only process files Claude actually touched.
Proposed Solution
Add a modified_files array to the JSON input for SessionEnd and Stop hooks that lists all files modified during the session:
{
"session_id": "abc123",
"transcript_path": "~/.claude/projects/.../session.jsonl",
"hook_event_name": "SessionEnd",
"modified_files": [
"/path/to/file1.ts",
"/path/to/file2.js"
]
}
This would allow hooks to directly access the list of modified files via jq -r '.modified_files[]' and pipe them to tools like lint-staged, prettier, or test runners.
Alternative Solutions
Currently I work around this by using git diff --name-only HEAD to detect all modified files, but this includes changes from outside the Claude session. I've also considered tracking modifications using PostToolUse hooks that append to a temporary file, but this requires complex state management and cleanup. Parsing the transcript file is possible but requires reading potentially large JSON files and extracting file paths from various tool calls.
Priority
Medium - Would be very helpful
Feature Category
Configuration and settings
Use Case Example
Example scenario:
- I start a Claude Code session to refactor several TypeScript files in my project
- Claude modifies 5 files using Edit and Write tools during the session
- When I exit, my SessionEnd hook automatically runs lint-staged on just those 5 files
- The hook uses
jq -r '.modified_files[]' | xargs npx lint-stagedto process only Claude's changes - This saves time by not checking unchanged files and ensures only Claude's modifications are validated
Additional Context
This would benefit common use cases like:
- Running formatters/linters on changed files
- Executing related tests for modified modules
- Staging specific files for git commits
- Running security scanners on modified code
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗