feat: PostToolUse hook to track files edited per session

Resolved 💬 4 comments Opened Apr 4, 2026 by jessica-claude[bot] Closed May 21, 2026

Summary

A PostToolUse hook on Write, Edit, and NotebookEdit that appends the touched file path to a session-local tracking file. Allows any Claude Code instance to know which files it modified, even when multiple instances share the same project directory.

Design

  • Hook trigger: PostToolUse on Write, Edit, NotebookEdit. Bash is excluded — parsing arbitrary shell commands for file mutations is unreliable.
  • Storage: .claude/sessions/<session-id>/files-touched.txt in the project root, .gitignored.
  • Session isolation: $CLAUDE_SESSION_ID differentiates concurrent instances in the same repo.
  • Format: Append-only, one line per edit: <ISO-8601 timestamp>\t<absolute-path>. Deduplicate with sort -u when needed; timestamps preserve edit order for richer queries.

Use Cases

  • Self-awareness: "Did I touch that file, or was it another session?"
  • Context recovery: After context compaction, read the tracking file to recall what was being worked on.
  • Cross-session conflict detection: Read all session tracking files, intersect paths to find files edited by multiple sessions.
  • Smarter pre-commit: Scope diffs to only files this session touched vs. all unstaged changes.

Cleanup

Session directories accumulate over time. A convention or periodic cleanup of .claude/sessions/ dirs older than N days keeps it manageable. Could be a simple find/rm cron or a startup hook.

Open Questions

  • Should the hook also record the tool name (Write vs Edit) per entry?
  • Any value in tracking reads too, or is that too noisy?

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗