Skip to content

Commit 3626681

Browse files
phernandezclaude
andcommitted
feat: add BASIC_MEMORY_CONFIG_DIR environment variable support
Add support for overriding config directory location via BASIC_MEMORY_CONFIG_DIR environment variable. This enables cloud deployments to store config.json in persistent storage (e.g., Tigris) while keeping memory.db on local ephemeral disk. Changes: - ConfigManager now checks BASIC_MEMORY_CONFIG_DIR before using default - Add tests verifying custom config directory works correctly - All existing tests pass Implements Phase 1 of SPEC-15. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: phernandez <paul@basicmachines.co>
1 parent af69399 commit 3626681

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/basic_memory/config.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,12 @@ def __init__(self) -> None:
251251
if isinstance(home, str):
252252
home = Path(home)
253253

254-
self.config_dir = home / DATA_DIR_NAME
254+
# Allow override via environment variable
255+
if config_dir := os.getenv("BASIC_MEMORY_CONFIG_DIR"):
256+
self.config_dir = Path(config_dir)
257+
else:
258+
self.config_dir = home / DATA_DIR_NAME
259+
255260
self.config_file = self.config_dir / CONFIG_FILE_NAME
256261

257262
# Ensure config directory exists

tests/test_config.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,28 @@ def test_disable_permalinks_flag_can_be_enabled(self):
179179
"""Test that disable_permalinks flag can be set to True."""
180180
config = BasicMemoryConfig(disable_permalinks=True)
181181
assert config.disable_permalinks is True
182+
183+
def test_config_manager_respects_custom_config_dir(self, monkeypatch):
184+
"""Test that ConfigManager respects BASIC_MEMORY_CONFIG_DIR environment variable."""
185+
with tempfile.TemporaryDirectory() as temp_dir:
186+
custom_config_dir = Path(temp_dir) / "custom" / "config"
187+
monkeypatch.setenv("BASIC_MEMORY_CONFIG_DIR", str(custom_config_dir))
188+
189+
config_manager = ConfigManager()
190+
191+
# Verify config_dir is set to the custom path
192+
assert config_manager.config_dir == custom_config_dir
193+
# Verify config_file is in the custom directory
194+
assert config_manager.config_file == custom_config_dir / "config.json"
195+
# Verify the directory was created
196+
assert config_manager.config_dir.exists()
197+
198+
def test_config_manager_default_without_custom_config_dir(self, config_home, monkeypatch):
199+
"""Test that ConfigManager uses default location when BASIC_MEMORY_CONFIG_DIR is not set."""
200+
monkeypatch.delenv("BASIC_MEMORY_CONFIG_DIR", raising=False)
201+
202+
config_manager = ConfigManager()
203+
204+
# Should use default location
205+
assert config_manager.config_dir == config_home / ".basic-memory"
206+
assert config_manager.config_file == config_home / ".basic-memory" / "config.json"

0 commit comments

Comments
 (0)