Skip to content

Add session-aware dirty-files tracking #16

@severity1

Description

@severity1

Summary

Support session-isolated dirty-file tracking to prevent interference between concurrent Claude sessions editing the same project.

Problem

Currently, dirty files are tracked in a single shared file: .claude/auto-memory/dirty-files

When multiple Claude sessions run concurrently on the same project:

  1. Session A edits file1.py -> appends to dirty-files
  2. Session B edits file2.py -> appends to dirty-files
  3. Session A's stop hook triggers memory update for both files (including B's changes)
  4. Session B may see empty dirty-files (if A cleared it) or trigger duplicate processing

This causes:

  • Sessions processing files they didn't edit
  • Race conditions on file reads/writes
  • Duplicate or missed memory updates
  • Unpredictable behavior in multi-session workflows

Proposed Solution

Use session-specific dirty-file tracking:

.claude/auto-memory/
  dirty-files-{session_id_1}
  dirty-files-{session_id_2}
  ...

Implementation steps:

  1. Check if Claude provides a session identifier via environment variable (e.g., CLAUDE_SESSION_ID)
  2. Modify post-tool-use.py to write to session-specific file
  3. Modify stop.py to read only the current session's dirty file
  4. Add cleanup for stale session files (sessions that terminated without cleanup)

Considerations

  • Session ID availability: Need to verify Claude exposes a session identifier
  • Stale file cleanup: Sessions may crash without clearing their dirty files
  • Backwards compatibility: Handle upgrade path from single-file to session-aware format

Affected Files

  • scripts/post-tool-use.py - dirty file writes
  • scripts/stop.py - dirty file reads
  • agents/memory-updater.md - may need session context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions