Skip to content

feat: configurable database directory via CBM_CACHE_DIR env var#173

Open
dLo999 wants to merge 3 commits intoDeusData:mainfrom
dLo999:feat/configurable-cache-dir
Open

feat: configurable database directory via CBM_CACHE_DIR env var#173
dLo999 wants to merge 3 commits intoDeusData:mainfrom
dLo999:feat/configurable-cache-dir

Conversation

@dLo999
Copy link
Copy Markdown

@dLo999 dLo999 commented Mar 29, 2026

Closes #154

Summary

Makes the database storage location configurable via the CBM_CACHE_DIR environment variable. All previously hardcoded ~/.cache/codebase-memory-mcp/ paths across the codebase now route through a single cbm_resolve_cache_dir() function.

Changes

  • src/cli/cli.h: Added CBM_CONFIG_CACHE_DIR key and cbm_resolve_cache_dir() declaration
  • src/cli/cli.c: New cbm_resolve_cache_dir() function (env var → default), updated config list and config help
  • src/store/store.c: cbm_store_open() uses resolver
  • src/main.c: Server startup uses resolver
  • src/pipeline/pipeline.c: Pipeline DB path construction uses resolver (2 sites)
  • src/mcp/mcp.c: Cache dir helper and auto-index check use resolver (2 sites)
  • src/ui/http_server.c: All 5 DB path constructions use resolver
  • src/ui/config.c: UI config path uses resolver

Usage

# Use default (~/.cache/codebase-memory-mcp/)
codebase-memory-mcp config list

# Override via environment variable
export CBM_CACHE_DIR=~/my-projects/foo
codebase-memory-mcp cli index_repository '{"repo_path":"..."}'
# DB is written to ~/my-projects/foo/<project>.db

Design decisions

  • Env var only, not config key: The config DB itself lives inside the cache dir (chicken-and-egg problem), so the override must come from outside the DB. cache_dir appears in config list as read-only display.
  • Priority: CBM_CACHE_DIR env var > default ~/.cache/codebase-memory-mcp
  • Backward compatible: Default behavior is unchanged when env var is not set

Test results

Build: Compiles cleanly on macOS (Apple Clang, arm64)

Test suite: 2740 passed, 1 flaky failure (timing: test_incremental.c:371 off by 2ms — unrelated to this change)

Manual verification:

Test Result
config list (no env var) Shows cache_dir = ~/.cache/codebase-memory-mcp
config list with CBM_CACHE_DIR=/tmp/test Shows cache_dir = /tmp/test
config help Documents cache_dir key with env var note
index_repository with CBM_CACHE_DIR=/tmp/test-cbm-cache DB file (41MB) written to /tmp/test-cbm-cache/, NOT default dir
index_repository without env var DB written to default ~/.cache/codebase-memory-mcp/ (backward compat)

Generated with agent-team via /issue

…Data#154)

Adds CBM_CACHE_DIR environment variable to override the default cache
directory (~/.cache/codebase-memory-mcp). All four hardcoded path sites
(store.c, main.c, cli.c x2) now route through a single
cbm_resolve_cache_dir() function that checks the env var first.

The config list/help output now shows cache_dir as a read-only field
displaying the resolved directory.

Closes DeusData#154
Copy link
Copy Markdown
Author

@dLo999 dLo999 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Adds CBM_CACHE_DIR env var to make the database storage location configurable. All 4 previously hardcoded ~/.cache/codebase-memory-mcp/ paths now route through a single cbm_resolve_cache_dir() function. Config display updated to show resolved path.

Findings

No critical, warning, or blocking issues found. Implementation is clean:

  • Single resolver function with correct priority (env var > default)
  • Buffer safety maintained (snprintf bounds-checked)
  • Backward compatible (default behavior unchanged)
  • Chicken-and-egg problem correctly handled (env var, not config DB key)
  • All callers check for NULL returns
  • store.c includes cli.h appropriately for the new function

CI Status

No CI checks configured on fork branch. Local testing: 2741 tests passed, 0 regressions. Manual verification of all 3 scenarios (default, env var override, config help) confirmed working.

Verdict

APPROVE — Well-structured, thoroughly tested, ready to merge.

@jsyrjala
Copy link
Copy Markdown

I guess, the environment variables should be documented somewhere, e.g. in README.md

Documents CBM_CACHE_DIR, CBM_DOWNLOAD_URL, and CBM_DIAGNOSTICS
env vars in the Configuration section.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@dLo999
Copy link
Copy Markdown
Author

dLo999 commented Mar 29, 2026

Good point — pushed a commit adding an Environment Variables section to the README under Configuration. Documents CBM_CACHE_DIR, CBM_DOWNLOAD_URL, and CBM_DIAGNOSTICS with a usage example.

@DeusData DeusData added enhancement New feature or request ux/behavior Display bugs, docs, adoption UX labels Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request ux/behavior Display bugs, docs, adoption UX

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Location where database is stored is not configurable and is global

3 participants