Skip to content

fix(cli): honor Claude profile configuration - #1473

Merged
phernandez merged 5 commits into
mainfrom
codex/integrate-1420-claude-config-dir
Sep 4, 2026
Merged

fix(cli): honor Claude profile configuration#1473
phernandez merged 5 commits into
mainfrom
codex/integrate-1420-claude-config-dir

Conversation

@phernandez

@phernandez phernandez commented Sep 4, 2026

Copy link
Copy Markdown
Member

Summary

  • honor CLAUDE_CONFIG_DIR when resolving Claude Code hook settings
  • install and remove hooks in the active Claude profile instead of always using ~/.claude
  • preserve Claude Code's literal path semantics for empty, whitespace, relative, and tilde-prefixed values
  • preserve project-local settings.local.json precedence when the profile directory overlaps the project

Why

Claude Code supports profile-specific configuration through CLAUDE_CONFIG_DIR. The hook command ignored that setting, which could read or modify a different account's configuration and route captures to the wrong Basic Memory project.

Claude Code also treats the variable as a literal path whenever it is present. Normalizing, expanding, or treating an empty value as unset would make Basic Memory target a different settings file than Claude Code.

Implementation

  • preserve both signed contributor commits from fix(cli): honour CLAUDE_CONFIG_DIR when resolving Claude hook settings #1420
  • centralize active Claude profile directory resolution
  • preserve the environment value exactly and fall back to ~/.claude only when it is unset
  • deduplicate settings sources by resolved file path so profile settings are not read twice while local overrides still apply
  • isolate the test environment from a developer's real CLAUDE_CONFIG_DIR
  • keep all profile-aware bundled Claude skills on the same resolution semantics
  • enforce the skill contract in the Claude plugin package validator

Testing

  • explicit CLI integration coverage for empty, whitespace, and literal tilde paths
  • uv run pytest tests/cli/test_hook_command.py -q (118 passed)
  • just fast-check
  • just package-check-claude-code
  • local /review before each maintainer push (no findings after fixes)

Attribution

Supersedes #1420 while preserving @fzipi's original commits, authorship, sign-offs, and cherry-pick provenance.

fzipi and others added 2 commits September 4, 2026 12:11
The Claude hook resolved user-level settings as a hardcoded ~/.claude and
never read CLAUDE_CONFIG_DIR, which Claude Code treats as a full replacement
for that directory. Users running per-account profiles hit two problems: a
basicMemory block in the active profile was never read, so hook status
reported "settings: not found" and capture fell back to the default project;
and `hook install` wrote hook entries into ~/.claude/settings.json regardless
of the active profile, editing another account's configuration.

Add _claude_user_dir(), honouring CLAUDE_CONFIG_DIR and falling back to
~/.claude so single-profile setups are unchanged, and use it for both the
settings base and the install/remove target.

The ancestor walk in _claude_project_dir can reach $HOME and find
~/.claude/settings.json. That was previously suppressed by comparing the
resolved project root to $HOME; keep that guard alongside the new profile-dir
comparison, otherwise the default profile's settings re-enter as a
higher-precedence project source and override the active profile.

Clear CLAUDE_CONFIG_DIR in the CLI test isolation fixture so a contributor
running the suite under a profile wrapper does not read their real config.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Felipe Zipitria <fzipi@fing.edu.uy>
(cherry picked from commit c189352)
CLAUDE_CONFIG_DIR can legitimately point at a repository's own .claude
directory. Skipping the project sources whenever that directory matched the
profile dir dropped settings.local.json entirely, so its higher-precedence
primaryProject was ignored and hooks routed notes to the profile-wide project.

Deduplicate by resolved file path rather than by directory: settings.json is
read once as the user-level source, and settings.local.json still layers on
top of it.

Reported by the Codex review bot on #1420.

Signed-off-by: Felipe Zipitria <fzipi@fing.edu.uy>
(cherry picked from commit 54df21f)
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 4, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-04T18:37:18.838030Z 67d5ebc New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Signed-off-by: phernandez <paul@basicmachines.co>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 33e46ff4ac

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/basic_memory/cli/commands/hook.py
Signed-off-by: phernandez <paul@basicmachines.co>
Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez
phernandez merged commit 328f898 into main Sep 4, 2026
30 checks passed
@phernandez
phernandez deleted the codex/integrate-1420-claude-config-dir branch September 4, 2026 19:11
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.

2 participants