Skip to content

fix(learn): honor CLAUDE_CONFIG_DIR when locating Claude logs and memory - #1642

Merged
JerrettDavis merged 3 commits into
headroomlabs-ai:mainfrom
tenderdeve:fix/1630-learn-claude-config-dir
Jul 2, 2026
Merged

JerrettDavis merged 3 commits into
headroomlabs-ai:mainfrom
tenderdeve:fix/1630-learn-claude-config-dir

Conversation

@tenderdeve

@tenderdeve tenderdeve commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Description

headroom learn ignored CLAUDE_CONFIG_DIR. ClaudeCodePlugin.__init__ resolved the Claude config directory as ~/.claude, and the memory writer wrote the global CLAUDE.md to ~/.claude/CLAUDE.md. A user who relocates their Claude config with that env var had learn scan the wrong directory and detect no projects.

Other parts of the codebase already honor the override (subscription/client.py, subscription/session_tracking.py, mcp_registry/claude.py); the learn path was the outlier.

Closes #1630

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

Changes Made

  • Add claude_config_dir() to headroom/learn/_shared.py — returns $CLAUDE_CONFIG_DIR when set, else ~/.claude (via Path.home(), matching the existing override elsewhere).
  • ClaudeCodePlugin.__init__ now defaults claude_dir to claude_config_dir() instead of a hardcoded ~/.claude (an explicit claude_dir= argument still wins).
  • ClaudeCodeWriter._resolve_context_path writes the home-directory global memory to claude_config_dir() / "CLAUDE.md" instead of ~/.claude/CLAUDE.md.

Testing

  • Unit tests pass (pytest)
  • Linting passes (ruff check .)
  • Type checking passes (mypy headroom)
  • New tests added for new functionality
  • Manual testing performed

Test Output

$ pytest tests/test_learn/test_claude_config_dir.py tests/test_learn/test_writer.py -q
35 passed, 1 warning in 0.18s

$ ruff check headroom/learn/ tests/test_learn/test_claude_config_dir.py
All checks passed!

$ mypy headroom/learn/_shared.py headroom/learn/plugins/claude.py headroom/learn/writer.py
Success: no issues found in 3 source files

Real Behavior Proof

  • Environment: macOS (arm64), Python 3.14 venv, editable install of this branch.
  • Exact command / steps: ran python -c "from headroom.learn.plugins.claude import ClaudeCodePlugin; print(ClaudeCodePlugin().projects_dir)" with and without CLAUDE_CONFIG_DIR=/tmp/altclaude set, then pytest tests/test_learn/ tests/test_cli_learn.py.
  • Observed result: default prints /Users/<me>/.claude/projects; with CLAUDE_CONFIG_DIR=/tmp/altclaude it prints /tmp/altclaude/projects (before this change the second still printed ~/.claude/projects). Test suite: 226 passed, 3 skipped. New regression tests cover the plugin scan dir, explicit-arg precedence, and the writer's home-memory path.
  • Not tested: end-to-end headroom learn against a real relocated log tree with live Claude Code transcripts — verified at the plugin/writer resolution layer plus the existing scanner suite.

Review Readiness

  • I have performed a self-review
  • This PR is ready for human review

Additional Notes

The identical hardcode also exists at headroom/cli/mcp.py:21 (CLAUDE_CONFIG_DIR = Path.home() / ".claude"), but that is a separate command outside this issue's scope, so I left it for a follow-up to keep this PR to one issue.

`headroom learn` resolved the Claude config directory as `~/.claude` in
`ClaudeCodePlugin.__init__` and wrote global memory to `~/.claude/CLAUDE.md`,
ignoring `CLAUDE_CONFIG_DIR`. Users who relocate their Claude config via that
env var had `learn` scan the wrong directory and detect no projects.

Add a `claude_config_dir()` helper in the learn package that honors
`CLAUDE_CONFIG_DIR` (falling back to `~/.claude`), mirroring the override
already respected in `subscription` and `mcp_registry`, and use it in the
scanner plugin and the memory writer.

Closes headroomlabs-ai#1630
@github-actions

github-actions Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

PR governance

This PR follows the template and is marked ready for human review.

@github-actions github-actions Bot added the status: needs author action Pull request body or readiness checklist still needs author updates label Jul 1, 2026
@github-actions github-actions Bot added status: ready for review Pull request body is complete and the author marked it ready for human review and removed status: needs author action Pull request body or readiness checklist still needs author updates labels Jul 1, 2026

@JerrettDavis JerrettDavis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good. The Claude learn scanner and global-memory writer now share one config-dir resolver, explicit constructor paths still win in tests, and the regression coverage catches both scan and write targets under CLAUDE_CONFIG_DIR.

@JerrettDavis
JerrettDavis merged commit c600e31 into headroomlabs-ai:main Jul 2, 2026
27 checks passed
JerrettDavis added a commit to peterlodri-sec/headroom that referenced this pull request Jul 14, 2026
…ory (headroomlabs-ai#1642)

## Description

`headroom learn` ignored `CLAUDE_CONFIG_DIR`.
`ClaudeCodePlugin.__init__` resolved the Claude config directory as
`~/.claude`, and the memory writer wrote the global `CLAUDE.md` to
`~/.claude/CLAUDE.md`. A user who relocates their Claude config with
that env var had `learn` scan the wrong directory and detect no
projects.

Other parts of the codebase already honor the override
(`subscription/client.py`, `subscription/session_tracking.py`,
`mcp_registry/claude.py`); the `learn` path was the outlier.

Closes headroomlabs-ai#1630

## Type of Change

- [x] Bug fix (non-breaking change that fixes an issue)

## Changes Made

- Add `claude_config_dir()` to `headroom/learn/_shared.py` — returns
`$CLAUDE_CONFIG_DIR` when set, else `~/.claude` (via `Path.home()`,
matching the existing override elsewhere).
- `ClaudeCodePlugin.__init__` now defaults `claude_dir` to
`claude_config_dir()` instead of a hardcoded `~/.claude` (an explicit
`claude_dir=` argument still wins).
- `ClaudeCodeWriter._resolve_context_path` writes the home-directory
global memory to `claude_config_dir() / "CLAUDE.md"` instead of
`~/.claude/CLAUDE.md`.

## Testing

- [x] Unit tests pass (`pytest`)
- [x] Linting passes (`ruff check .`)
- [x] Type checking passes (`mypy headroom`)
- [x] New tests added for new functionality
- [x] Manual testing performed

### Test Output

```text
$ pytest tests/test_learn/test_claude_config_dir.py tests/test_learn/test_writer.py -q
35 passed, 1 warning in 0.18s

$ ruff check headroom/learn/ tests/test_learn/test_claude_config_dir.py
All checks passed!

$ mypy headroom/learn/_shared.py headroom/learn/plugins/claude.py headroom/learn/writer.py
Success: no issues found in 3 source files
```

## Real Behavior Proof

- Environment: macOS (arm64), Python 3.14 venv, editable install of this
branch.
- Exact command / steps: ran `python -c "from
headroom.learn.plugins.claude import ClaudeCodePlugin;
print(ClaudeCodePlugin().projects_dir)"` with and without
`CLAUDE_CONFIG_DIR=/tmp/altclaude` set, then `pytest tests/test_learn/
tests/test_cli_learn.py`.
- Observed result: default prints `/Users/<me>/.claude/projects`; with
`CLAUDE_CONFIG_DIR=/tmp/altclaude` it prints `/tmp/altclaude/projects`
(before this change the second still printed `~/.claude/projects`). Test
suite: 226 passed, 3 skipped. New regression tests cover the plugin scan
dir, explicit-arg precedence, and the writer's home-memory path.
- Not tested: end-to-end `headroom learn` against a real relocated log
tree with live Claude Code transcripts — verified at the plugin/writer
resolution layer plus the existing scanner suite.

## Review Readiness

- [x] I have performed a self-review
- [x] This PR is ready for human review

## Additional Notes

The identical hardcode also exists at `headroom/cli/mcp.py:21`
(`CLAUDE_CONFIG_DIR = Path.home() / ".claude"`), but that is a separate
command outside this issue's scope, so I left it for a follow-up to keep
this PR to one issue.

---------

Co-authored-by: JerrettDavis <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: ready for review Pull request body is complete and the author marked it ready for human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] headroom learn does not respect CLAUDE_CONFIG_DIR

2 participants