Skip to content

Conversation

@cjpeterein
Copy link

Summary

This PR fixes configuration priority handling throughout the codebase, ensuring environment variables properly override file-based settings and defaults. It also includes fixes for test pollution and build-time version injection.

Key changes:

  • Environment variables (CLAUDE_MEM_WORKER_PORT, CLAUDE_MEM_DATA_DIR, CLAUDE_MEM_WORKER_HOST) now consistently take priority over settings file values
  • Consolidated 20+ hardcoded path constructions to use centralized paths.ts
  • Replaced hardcoded 127.0.0.1 references with getWorkerHost() across all hooks and services
  • Fixed test pollution from mock.module() affecting logger tests
  • Fixed MCP server version to use build-time injection instead of hardcoded value

Configuration priority (now working consistently):

  1. process.env.CLAUDE_MEM_* (highest)
  2. ~/.claude-mem/settings.json
  3. Default values (lowest)

Fixes #185

Test plan

  • Verify CLAUDE_MEM_WORKER_PORT=9999 claude-mem start uses port 9999
  • Verify CLAUDE_MEM_DATA_DIR=/tmp/test claude-mem start uses custom data directory
  • Verify CLAUDE_MEM_WORKER_HOST=0.0.0.0 claude-mem start binds to all interfaces
  • Run full test suite: npm test
  • Verify MCP server reports correct version

🤖 Generated with Claude Code

Craig Peterein and others added 4 commits January 9, 2026 00:50
MCP server had hardcoded version '1.0.0' instead of using the
build-time injected __DEFAULT_PACKAGE_VERSION__. This caused
version-consistency.test.ts to fail.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Tests using mock.module() to mock the logger singleton were polluting
subsequent tests. The logger-format-tool.test.ts tests failed because
they received the mocked logger instead of the real one.

Changes:
- Export Logger class to allow creating fresh instances
- Use fresh Logger instance in formatTool tests
- Add formatTool to logger mocks for complete interface

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
… > defaults)

Environment variable CLAUDE_MEM_WORKER_PORT was ignored when loading
settings. Port remained at 37777 regardless of configuration.

Root Cause:
SettingsDefaultsManager.loadFromFile() only read from settings file,
completely bypassing environment variables.

Changes:
- Added applyEnvOverrides() helper method to SettingsDefaultsManager
- Applied env var overrides in all code paths (normal, file-not-exist, error)
- Fixed hardcoded port 37777 in utility scripts to use settings

Configuration Priority (Now Working):
  1. process.env.CLAUDE_MEM_WORKER_PORT  ← highest
  2. ~/.claude-mem/settings.json
  3. 37777 (default)                      ← lowest

Scripts Fixed:
- scripts/check-pending-queue.ts
- scripts/clear-failed-queue.ts
- scripts/sync-marketplace.cjs
- ragtime/ragtime.ts

Fixes thedotmack#185

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
…nt variables

Extends the configuration priority fix from a4800359 to cover all settings.
Previously, DATA_DIR and WORKER_HOST were hardcoded in many locations,
ignoring user configuration via environment variables or settings file.

Changes:
- paths.ts: DATA_DIR now checks process.env first (settings file cannot
  override due to circular dependency - settings file is IN the data dir)
- All hooks and services now use getWorkerHost() instead of hardcoded 127.0.0.1
- Consolidated 20+ hardcoded path constructions to use centralized paths.ts
- Settings path resolution now respects DATA_DIR configuration

Configuration Priority (Now Working for All Settings):
  1. process.env.CLAUDE_MEM_*  (highest)
  2. ~/.claude-mem/settings.json
  3. Default values           (lowest)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@cjpeterein cjpeterein closed this Jan 12, 2026
@cjpeterein
Copy link
Author

Will rebase and open a new pr

@cjpeterein cjpeterein deleted the fix/worker-port-configuration branch January 12, 2026 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Port change is not working

1 participant