Skip to content

fix(claude): brace the project dir in the devtools gate hook - #5739

Merged
Sinity merged 3 commits into
masterfrom
fix/hook-project-dir-brace
Sep 28, 2026
Merged

Sinity merged 3 commits into
masterfrom
fix/hook-project-dir-brace

Conversation

@Sinity

@Sinity Sinity commented Sep 28, 2026

Copy link
Copy Markdown
Owner

Summary

Brace CLAUDE_PROJECT_DIR in the PreToolUse devtools-gate hook so the hook runs under a Claude Code shell prefix.

Problem

Sinnix now launches Claude Code with CLAUDE_CODE_SHELL_PREFIX (sinnix 23fe8fb3), which moves tool processes into their own memory slice. With a prefix set, Claude Code expands variables in hook commands itself, and it reads an unbraced $CLAUDE_PROJECT_DIR/.claude/hooks/require-devtools.sh as a single variable name. That name is invalid, so the command expands to an empty string. The session's debug log shows 764 hook failures in one session: "Invalid environment variable name evaluates to an empty string: CLAUDE_PROJECT_DIR/.claude/hooks/require-devtools.sh" followed by "zsh: string expected after -c". The devtools gate never ran.

Solution

Use ${CLAUDE_PROJECT_DIR}, the form the sinex project already uses.

Verification

In a scratch project, a PreToolUse hook written as ${CLAUDE_PROJECT_DIR}/h.sh ran on a Bash call under the shell prefix (claude -p with Haiku), both with and without CLAUDE_PROJECT_DIR in the launching environment. The unbraced form fails in the live session log quoted above.

🤖 Generated with Claude Code

https://claude.ai/code/session_015pdKaZWyGe6Ngvsz468dzg

Under CLAUDE_CODE_SHELL_PREFIX, Claude Code expands hook command variables
itself and reads an unbraced "$CLAUDE_PROJECT_DIR/.claude/..." as one
invalid variable name, so the hook command becomes empty and the gate never
runs. The braced form expands correctly.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015pdKaZWyGe6Ngvsz468dzg
@Sinity
Sinity enabled auto-merge (squash) September 28, 2026 19:11
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 28, 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-28T23:05:46.583074Z 0c7f1e7 New commits
🔒 Security Review ✅ Completed 2026-09-28T19:14:04.912783Z fcf9af4 PR opened
ℹ️ 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.

Sinity added a commit that referenced this pull request Sep 28, 2026
## Summary

The patterns gate trusts an exemption that any parent of `HEAD` already
carried, so a PR whose tip merges `master` no longer fails for
`master`'s own baseline additions.

## Problem

`_trusted_baseline` read the committed baseline from `HEAD^` only. On a
PR whose head is a merge of `master`, `HEAD^` is the PR's previous tip,
so every exemption `master` added since the PR last merged it counts as
growth. The quick-gate of #5739 (a one-line hook change merged with
`master` at f2562c3) failed with `patterns: committed baseline grew`
over dozens of `master`'s own entries (`diagnosis=gate_input_error`);
#5643, #5696 and #5704 fail the same way.

## Solution

Read the baseline at every parent (`git rev-parse HEAD^@`) and trust
each entry at the largest count any parent carried. A merge resolution
that adds an entry present in neither parent is still growth.

## Verification

`devtools test tests/unit/devtools/test_verify_patterns.py` on a
checkout of origin/master 82e84ec with this change: 9 passed, 1
failed. The new
`test_merging_the_base_branch_does_not_count_its_exemptions_as_growth`
passes; it fails with first-parent-only trust. The failing
`test_displacing_a_baselined_match_does_not_trip_the_gate` fails the
same way on unpatched master (IndentationError in its synthetic file)
and is recorded in polylogue-rb7tx.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_015pdKaZWyGe6Ngvsz468dzg

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
@Sinity
Sinity merged commit f95f0b1 into master Sep 28, 2026
3 of 4 checks passed
@Sinity
Sinity deleted the fix/hook-project-dir-brace branch September 28, 2026 23:09
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.

1 participant