Skip to content

feat(hooks): validate-memory-location — flag misplaced auto-memory files #81

@breferrari

Description

@breferrari

Problem

~/.claude/projects/<project>/memory/ should hold only MEMORY.md per CLAUDE.md. Everything else belongs in brain/ topic notes.

Agents drift here — the vocabulary ("this is a memory, goes in the memory dir") fights the convention. Misplaced files aren't versioned, fork the source of truth, and silently desync from the brain/ index.

Fix

PostToolUse hook on Write|Edit. Detects writes to ~/.claude/projects/<x>/memory/<file>.md where basename != MEMORY.md. Emits a warning at write time with migration pointer to the right brain/ note.

PostToolUse can't block; visibility is the lever.

Shape

.claude/scripts/validate-memory-location.ts, ~70 lines, matches the existing validate-write.ts pattern.

  • Reads stdin JSON, checks tool_input.file_path
  • POSIX + Windows path separators
  • Allows MEMORY.md
  • hookSpecificOutput.additionalContext lists target brain/ notes (Patterns / Gotchas / Key Decisions / Memories / new topic)
  • Silent on:
    • Vault paths
    • Paths with 'memory' substring elsewhere (e.g. brain/Memories.md)
    • Other .claude/projects/<x>/ subdirs (transcripts, hook-output)
    • Bad input (null stdin, missing tool_input, non-string file_path)
  • Subprocess integration tests in tests/validate-memory-location.test.ts

Wires into existing PostToolUse Write|Edit block alongside validate-write and qmd-refresh.

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