Skip to content

feat: Add session-file-validator plugin for stale image detection on resume#20662

Open
CameronImmesoete wants to merge 1 commit intoanthropics:mainfrom
CameronImmesoete:fix/issue-15285-resume-image-caching
Open

feat: Add session-file-validator plugin for stale image detection on resume#20662
CameronImmesoete wants to merge 1 commit intoanthropics:mainfrom
CameronImmesoete:fix/issue-15285-resume-image-caching

Conversation

@CameronImmesoete
Copy link

Summary

This PR adds a new plugin that validates file content when resuming sessions. When images were read in a previous session, the plugin warns Claude about potentially stale cached data and instructs it to re-read files when asked.

Problem: When using --resume to continue a session, Claude may describe cached image content from the original session instead of reading new files. This is because image data is stored as base64 in the transcript and replayed on resume without re-reading the actual files.

Solution: A SessionStart hook that:

  1. Parses the transcript to find image file reads
  2. Checks if those files still exist on disk
  3. Injects context warning Claude about cached content
  4. Instructs Claude to use the Read tool for fresh content when asked

Changes

  • plugins/session-file-validator/.claude-plugin/plugin.json - Plugin metadata
  • plugins/session-file-validator/hooks/hooks.json - Hook configuration (SessionStart with resume matcher)
  • plugins/session-file-validator/hooks/session-resume-validator.py - Main validation logic
  • plugins/session-file-validator/README.md - Documentation
  • plugins/README.md - Added plugin to the directory table

Security

  • Path traversal protection using Path.resolve() and pattern checks
  • Null byte injection prevention
  • Symlink validation
  • No information disclosure in error handling
  • Safe failure mode (errors return empty JSON, don't block session)

Test Plan

  • Plugin activates only on resume (not startup/clear/compact)
  • Detects missing files and warns appropriately
  • Detects existing files and warns about potential staleness
  • Rejects paths with traversal patterns
  • Rejects paths with null bytes
  • Handles invalid JSON input gracefully
  • Python syntax validated
  • JSON files validated

Related

🤖 Generated with Claude Code

…resume

Adds a new plugin that validates file content when resuming sessions.
When images were read in a previous session, the plugin warns Claude
about potentially stale cached data and instructs it to re-read files
when asked about them.

Key features:
- SessionStart hook with resume matcher
- Parses transcript to find image file reads
- Checks if files still exist on disk
- Injects context warning about cached content
- Security: path traversal protection, symlink validation

Co-Authored-By: Claude <[email protected]>
@mrmrcode
Copy link

@claude PTAL

🤖 Generated with Claude Code

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants