Skip to content

chore: resolve post-edit hook path via CLAUDE_PROJECT_DIR - #2362

Open
rahmanunver wants to merge 2 commits into
mainfrom
chore/claude-hook-project-dir
Open

rahmanunver wants to merge 2 commits into
mainfrom
chore/claude-hook-project-dir

Conversation

@rahmanunver

Copy link
Copy Markdown
Contributor

The PostToolUse hook command was a repo-root-relative path, so it only resolved when the shell's working directory happened to be the repo root.

Widget work follows docs/widget-scripts.md and runs from inside the package directory, where that path does not exist. The hook fails non-blocking, so the auto-format silently stops running and the loss is easy to miss.

$CLAUDE_PROJECT_DIR is set to the project root, so the path resolves regardless of working directory. Behaviour at the repo root is unchanged.

The hook command was a repo-root-relative path, so it only resolved when
the shell's working directory happened to be the repo root. Widget work
follows docs/widget-scripts.md and runs from inside the package directory,
where the path does not exist and the auto-format hook silently stops
running (it fails non-blocking, so the loss is easy to miss).
@rahmanunver
rahmanunver requested a review from a team as a code owner July 28, 2026 10:12
@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

AI Code Review

⚠️ Approved with suggestions — low-severity items only, safe to merge


What was reviewed

File Change
.claude/settings.json PostToolUse hook command changed from a bare relative path to one resolved via $CLAUDE_PROJECT_DIR

Skipped (out of scope): dist/, pnpm-lock.yaml

All CI checks — not available in this run (checks approval was declined).


Findings

⚠️ Low — Double-quoting may break hook invocation depending on runner behaviour

File: .claude/settings.json line 51
Problem: The new command value is "\"$CLAUDE_PROJECT_DIR/.claude/hooks/post-edit.sh\"" — after JSON parsing, the string Claude Code actually receives is "$CLAUDE_PROJECT_DIR/.claude/hooks/post-edit.sh" (with literal surrounding double-quote characters as part of the string). If the hook runner passes this to sh -c, the shell will strip the quotes and expand the variable correctly. However, if the runner executes it as a raw argv[0] (i.e. execve without a shell), the leading " will be treated as part of the filename and the hook will silently fail — the exact same silent-failure mode the PR is trying to fix.

The safer and more idiomatic form, which works regardless of how the runner invokes commands, is without the embedded quotes:

Fix:

"command": "$CLAUDE_PROJECT_DIR/.claude/hooks/post-edit.sh"

If the variable alone is not expanded by the runner, the next safest form wraps the whole thing in an explicit shell invocation:

"command": "bash -c '$CLAUDE_PROJECT_DIR/.claude/hooks/post-edit.sh'"

Recommend verifying with pnpm start from inside a widget package (e.g. packages/pluggableWidgets/combobox-web) to confirm formatting fires after an edit.


Positives

  • Root cause is correctly identified and explained in the PR description — the relative path only resolves when CWD is the repo root, which breaks all widget-level work.
  • The fix is surgical: one line, no unrelated changes.
  • $CLAUDE_PROJECT_DIR is the right variable to use; it's documented as pointing to the project root regardless of working directory.

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