Skip to content

fix(doctor): stop false FAIL on marketplace installs missing CLAUDE_PROJECT_DIR - #213

Merged
fdaviddpt merged 1 commit into
mainfrom
fix/207-doctor-project-dir
Jul 28, 2026
Merged

fdaviddpt merged 1 commit into
mainfrom
fix/207-doctor-project-dir

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Summary

Closes #207.

doctor.sh runs through the Bash tool via commands/doctor.md, not as a hook. Claude Code exports CLAUDE_PROJECT_DIR to the three hooks; it is unset in the Bash tool's environment. resolve-paths.sh then hits its "cannot guess" branch and fatals — correct for the hooks (a wrong guess there writes memory into the wrong project) but wrong for a read-only diagnostic, which reported FAIL Path resolution failed and VERDICT: problem — capture cannot run on installs where capture was working fine. commands/doctor.md tells the model to relay the report verbatim and never contradict a FAIL line, so the false signal reached the user with no way to question it — the exact failure class the doctor exists to end (#144, #200), now coming from the doctor itself.

The judgment call

The obvious fix — default CLAUDE_PROJECT_DIR in resolve-paths.sh — was rejected. That file refuses to guess on purpose: for its real callers (the three hooks), a wrong guess silently writes memory into the wrong project, which is worse than the doctor's false FAIL. Weakening it there to fix a diagnostic-only bug would trade a loud false-positive for a quiet false-negative elsewhere.

The default is instead scoped to doctor.sh alone, applied before resolve-paths.sh is sourced. resolve-paths.sh itself is untouched — pinned by a new tests/test_resolve_paths.py, which asserts the strict refusal (loud exit 1 by default, return 1 under REMEMBER_PATHS_SOFT_FAIL=1) still holds for every other caller.

A silent default would just be a quieter version of the same bug: a doctor confidently reporting on a directory nobody told it about, which may not be the project the operator meant. So the assumption is never presented as fact:

  • The Paths section now prints WARN CLAUDE_PROJECT_DIR was not set — assumed the current directory: <dir> instead of an OK line.
  • Every VERDICT line — not just the Paths section — carries the same disclosure inline, since that's the one line commands/doctor.md tells the operator to trust without re-deriving anything above it.
  • Capture health is still evaluated against real evidence in the assumed directory, so a genuinely healthy install reports VERDICT: capture is working — … (CLAUDE_PROJECT_DIR was not set; this describes <dir>, assumed from the current directory) — a WARN-with-named-assumption, not a FAIL and not a silent confident OK.

The doc-comment's default: . was correct as an intent, just never implemented; it's now true, and the ENVIRONMENT header in doctor.sh has been updated to describe the visible-assumption behavior rather than a bare default.

Untrusted input handling

Reported by @PedroHenriqueNS (outside the maintainer allowlist). Their reproduction and root-cause analysis were correct and verified independently against the current main. Their suggested one-line patch (defaulting inside resolve-paths.sh itself) was not applied as-is — see judgment call above for why that would have been the wrong scope.

Test plan (TDD)

Red first, then green — see commit for the sequence:

  • tests/test_doctor.py::test_missing_claude_project_dir_does_not_false_fail_on_healthy_install — reproduces the real condition: CLAUDE_PROJECT_DIR unset and CLAUDE_PLUGIN_ROOT pointing at the repo checkout itself (not a .claude/remember/ layout), which is what actually forces the fatal branch. Failed on main with the exact reported FAIL/VERDICT text; passes after the fix, and asserts the assumption is visible (OK CLAUDE_PROJECT_DIR must NOT appear; assum must appear).
  • tests/test_doctor.py::test_claude_project_dir_set_behaves_unchanged — regression guard: when CLAUDE_PROJECT_DIR is provided, output is unchanged from before this fix.
  • tests/test_resolve_paths.py (new) — pins resolve-paths.sh's own strict refusal for non-doctor callers, both under REMEMBER_PATHS_SOFT_FAIL=1 and the loud default.

Full suite: 924 passed, 41 skipped locally (python3 -m pytest, ~6m26s), coverage 93.98% (gate 80%).

  • Tests written first, confirmed red against unmodified doctor.sh
  • Fix implemented, confirmed green
  • resolve-paths.sh strict-refusal invariant pinned and unchanged
  • Full suite green locally
  • CHANGELOG updated under [Unreleased], crediting @PedroHenriqueNS

…ROJECT_DIR

doctor.sh runs through the Bash tool, not as a hook, so it never receives
CLAUDE_PROJECT_DIR (Claude Code exports that to hooks only). resolve-paths.sh
correctly refuses to guess and fatals — right for the hooks, wrong for a
read-only diagnostic, which reported a healthy install as broken while
commands/doctor.md forbids questioning the FAIL it produces.

Scoped the default to doctor.sh only: default CLAUDE_PROJECT_DIR to $PWD
before sourcing resolve-paths.sh, never in resolve-paths.sh itself, so the
hooks keep the strict no-guess refusal (pinned in new test_resolve_paths.py).
The assumption is never silent: the Paths section prints a WARN naming the
assumed directory instead of an OK, and every VERDICT line carries the same
disclosure inline.

Reported by @PedroHenriqueNS (#207).

Co-Authored-By: Max <noreply>
@fdaviddpt
fdaviddpt merged commit bc02625 into main Jul 28, 2026
12 checks passed
@fdaviddpt
fdaviddpt deleted the fix/207-doctor-project-dir branch September 26, 2026 20:46
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.

doctor.sh reports a false FAIL on a healthy install: CLAUDE_PROJECT_DIR is unset in the Bash tool

2 participants