Skip to content

fix(hooks): crate_guard.py rejects Cargo.toml writes inside .claude/worktrees/ (blocks /clud-pr workflow) #794

Closed

Description

@zackees

Sub-issue of #789, prerequisite for Phase 1 (#790).

Symptom

/clud-pr (and any worktree-based workflow under .claude/worktrees/)
cannot edit Cargo.toml files. crate_guard.py denies the write with:

Refusing to create/modify Cargo.toml at
'.claude/worktrees/<branch>/crates/fbuild-build': fbuild is kept close
to a monocrate ...

even though crates/fbuild-build IS in the allowlist.

Root cause

ci/hooks/crate_guard.py:relative_dir resolves the edit path relative
to os.getcwd(), which the harness pins to \$CLAUDE_PROJECT_DIR (the
main checkout, not the worktree). So an absolute path like
<repo>/.claude/worktrees/feat-xyz/crates/fbuild-build/Cargo.toml
yields rel_dir = ".claude/worktrees/feat-xyz/crates/fbuild-build",
which is not in APPROVED_CRATE_DIRS and gets denied.

Fix

After computing rel_dir, strip a leading .claude/worktrees/<single path component>/ prefix if present, then re-check against
APPROVED_CRATE_DIRS. A worktree under that path is by definition a
fbuild checkout, so the same allowlist applies.

Equivalent regex:

_WORKTREE_PREFIX_RE = re.compile(r"^\.claude/worktrees/[^/]+/?")
posix = _WORKTREE_PREFIX_RE.sub("", posix, count=1)

Acceptance

  • crate_guard.py accepts edits of allowlisted Cargo.toml paths
    inside .claude/worktrees/<any-branch>/crates/<allowed>/.
  • Still rejects new top-level crates (e.g.
    crates/fbuild-new-thing/Cargo.toml from either main or
    worktree).
  • New unit test in ci/hooks/ (or wherever the hook tests live)
    exercises both the worktree-allowed and worktree-blocked cases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions