Skip to content

guard-git.sh's clean-command guard blocks --dry-run too (and matches on raw command substrings) #2099

Description

@carlos-alm

Bug

.claude/hooks/guard-git.sh (line ~78) blocks every git clean invocation unconditionally:

if echo "$NCOMMAND" | grep -qE '(^|[[:space:]]|&&[[:space:]]*)git[[:space:]]+clean'; then
  deny "BLOCKED: 'git clean' deletes untracked files that may belong to other sessions."
fi

This also blocks the dry-run form, which is a pure listing operation that never deletes anything. The /housekeep skill's Phase 2 explicitly recommends the dry-run form of git clean -fdX as the discovery mechanism for gitignored dirt files, so the hook currently makes that step of the skill impossible to run as documented.

Worse: the grep matches on the raw command text, not just actual invocations. Any Bash command whose argument text merely contains the substring "git clean" gets blocked too — e.g. gh issue create --body "...git clean -fdX --dry-run..." was blocked while filing this very issue, because the deny message and quoted body text contained that substring.

Fix

The check should:

  1. Special-case --dry-run/-n flags and allow those through, only blocking invocations that would actually delete (lack -n/--dry-run and include -f/--force).
  2. Scope the grep to the actual command being executed (e.g. first word of a pipeline segment / structured parse), not a blind substring match over the entire raw command string — so quoted text in unrelated commands (like gh issue create --body "...") doesn't trigger it.

Found via

/housekeep run on 2026-07-12, discovered while running Phase 2 (dirt file discovery), then again while trying to file this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions