Skip to content

Skip auto-memory hooks when project is not initialized #17

@severity1

Description

@severity1

Summary

Auto-memory hooks should not trigger unless the project has been initialized via /auto-memory:init. Running on uninitialized projects wastes resources and may cause confusion.

Problem

Currently, load_config() in post-tool-use.py returns a default config when no config file exists:

def load_config(project_dir: str) -> dict:
    config_file = Path(project_dir) / ".claude" / "auto-memory" / "config.json"
    if config_file.exists():
        # ... load config
    return {"triggerMode": "default"}  # <-- defaults even when not initialized

This causes:

  • Dirty files tracked on projects that have no auto-memory setup
  • Stop hook may block and request memory-updater spawn on uninitialized projects
  • Unnecessary file I/O and processing overhead
  • Potential confusion when hooks fire unexpectedly

Proposed Solution

Treat missing config as "not enabled":

  1. post-tool-use.py: Exit early if config file doesn't exist
  2. stop.py: Exit early if config file doesn't exist
def load_config(project_dir: str) -> dict | None:
    """Load plugin configuration. Returns None if not initialized."""
    config_file = Path(project_dir) / ".claude" / "auto-memory" / "config.json"
    if not config_file.exists():
        return None  # Not initialized
    # ... load and return config

# In main():
config = load_config(project_dir)
if config is None:
    return  # Project not initialized, skip

Affected Files

  • scripts/post-tool-use.py - add config existence check
  • scripts/stop.py - add config existence check (for consistency)

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