Skip to content

Engine writes data/ to caller's cwd — pollutes user repos when started from project root #303

@swiftugandan

Description

@swiftugandan

Summary

npx @agentmemory/agentmemory starts iii-engine with the current working directory as the state-store location. When the server is launched from inside a project (which is the default for the Claude Code plugin auto-start path, since Claude Code's cwd is the user's repo), the engine writes a data/ directory directly into the user's git working tree:

data/state_store.db/mem%3Aaccess.bin
data/state_store.db/mem%3Ahealth.bin
data/state_store.db/mem%3Amemories.bin
data/state_store.db/mem%3Aobs%3A<session-id>.bin
data/state_store.db/mem%3Aindex%3Abm25.bin
data/stream_store/stream%3Amem-live%3A<session-id>.bin
data/stream_store/stream%3Amem-live%3Aviewer.bin

These show up immediately in git status and are easy to accidentally commit. They also leak session ids and memory contents into whatever repo the user happened to be in when the server first started.

Repro

cd ~/some-project    # any git repo
npx -y @agentmemory/agentmemory   # let it become healthy
# in another shell:
cd ~/some-project && git status
# => Untracked: data/

Environment

  • macOS 14 (darwin 23.6.0), x86_64
  • agentmemory 0.9.9
  • iii-engine 0.11.2 (the version agentmemory pins)
  • Node from npx, no Docker fallback

Workaround

Start the server from a dedicated directory:

mkdir -p ~/.agentmemory
cd ~/.agentmemory && npx -y @agentmemory/agentmemory

This works, but it's fragile because:

  1. The Claude Code plugin install instructions ("run npx @agentmemory/agentmemory in a separate terminal") don't mention cwd, so a typical user who pastes the install block into their project terminal will hit this.
  2. There's no CLI flag or env var to override the data location (--help lists --port, --no-engine, --tools, --verbose, but nothing for state).
  3. If/when any hook or skill auto-spawns the engine, it will inherit Claude Code's cwd (the repo) and recreate the problem.

Proposed fix

Make the state-store location explicit and default it outside any repo. A couple of equivalent shapes:

  1. CLI flag + env var, defaulting to ~/.agentmemory/data (or platform-appropriate: $XDG_DATA_HOME/agentmemory on Linux, ~/Library/Application Support/agentmemory on macOS):
    agentmemory --data-dir ~/.agentmemory/data
    AGENTMEMORY_DATA_DIR=~/.agentmemory/data npx @agentmemory/agentmemory
  2. Auto-relocate when started inside a git repo: detect .git in cwd or any ancestor, and if found, use ~/.agentmemory/data instead of ./data. Log a one-line warning so users aren't surprised.

(2) alone would catch every accidental case without needing users to set anything; (1) is still worth having for users who want to pin the location.

Happy to send a PR if you'd like — let me know which shape you prefer.

Why this matters

Plugin auto-installation is the headline path in the README ("/plugin marketplace add rohitg00/agentmemory and /plugin install agentmemory"). Anyone following that path from inside their repo gets engine state written into their working tree on the first run. The current default basically guarantees a footgun for the recommended install flow.

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