[BUG] BASIC_MEMORY_HOME env var is not respected
Bug Description
Configuring the BASIC_MEMORY_HOME env var does not set the root dir for basic memory
Example:
"basic-memory": {
"command": "uvx",
"args": ["basic-memory", "mcp"],
"env": {
"BASIC_MEMORY_HOME": "~/project/.basic-memory"
}
}
files are still created in ~/basic-memory
@claude why isn't the env var working in the config.py?
Claude finished @phernandez's task —— View job • claude/issue-219-20250710_012005 • Create PR ➔
Fixed BASIC_MEMORY_HOME Environment Variable Issue ✅
Todo List:
- [x] Read config.py to understand environment variable handling
- [x] Check how home directory is determined
- [x] Identify the bug causing BASIC_MEMORY_HOME to be ignored
- [x] Implement fix for the issue
- [x] Add comprehensive tests for the fix
- [x] Commit and push changes
Root Cause Identified
The issue was in the ConfigManager.load_config() method (src/basic_memory/config.py:177-192). When a config file existed, BasicMemoryConfig(**data) was called with data from the JSON file, which bypassed Pydantic's environment variable parsing. The BASIC_MEMORY_HOME env var only worked when there was no existing config file.
The Fix
Modified ConfigManager.load_config() to explicitly check for BASIC_MEMORY_HOME environment variable after loading from file and override the main project path if set:
# Allow BASIC_MEMORY_HOME environment variable to override the main project path
env_home = os.getenv("BASIC_MEMORY_HOME")
if env_home:
config.projects["main"] = str(Path(env_home))
This ensures that BASIC_MEMORY_HOME takes precedence over the file-based configuration for the main project path, allowing users to override their configuration temporarily using environment variables.
Tests Added
Added comprehensive tests in TestConfigManager class:
test_load_config_respects_basic_memory_home_with_existing_file- verifiesBASIC_MEMORY_HOMEoverrides file-based configtest_load_config_without_basic_memory_home_uses_file_config- verifies fallback to file-based config when env var is not set
Changes Made
- Modified:
src/basic_memory/config.py- Added environment variable override logic - Added: New test class
TestConfigManagerintests/test_config.py
Oh Claude, at least you tried...
@phernandez @groksrc
The root issue here is that the FileService object that actually writes the files to disk, uses the value of the path field in the project table in the database to decide where to write the file. The value in the Config is not used. We can't just change the value of the path in the database, because then any existing files would not longer be able to be found.
So, one possible way forward is to:
- Remove the BASIC_MEMORY_HOME env var and the config
- Create a cli command for changing the root path of a BM project which will update the path for the project in the database, ~~and move all the notes for all the projects to the new project dir.~~
- On paul's suggestion, just prompt the user to move the files from the old location to their new location (BM cli just updates the database)
- Since project paths are no longer in the config file, it might be helpful if we had a tool or cli command to show the projects and their file system locations, since that would no longer be available in the config file.
Nice. the project info is available via
➜ ~ bm project list
Basic Memory Projects
┏━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━┓
┃ Name ┃ Path ┃ Default ┃ Active ┃
┡━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━┩
│ main │ ~/basic-memory │ ✓ │ ✓ │
│ personal │ ~/Library/Mobile Documents/iCloud~md~obsidian/Documents/personal │ │ │
│ chat-test │ ~/chat-test │ │ │
│ basic-memory-llc │ ~/dev/basicmachines/basic-memory-llc │ │ │
└──────────────────┴──────────────────────────────────────────────────────────────────┴─────────┴────────┘
➜ ~