Skip to content

/careful hook triggers false positives on patterns inside commit messages #1060

@oscarsterling

Description

@oscarsterling

Summary

The /careful hook uses string matching against the full bash command, including the contents of git commit -m arguments. This means commit messages that describe destructive commands (e.g., "this hook catches recursive deletes and database drops") trigger the safety warning even though no destructive command is being run.

Steps to reproduce

  1. Activate /careful
  2. Run a commit whose message mentions a blocked pattern:
git add file.txt && git commit -m "feat: add guard for recursive delete and database drop patterns"
  1. The hook fires on patterns found inside the quoted commit message string, not as an actual command.

Expected behavior

The hook should only match destructive patterns in the executable portions of the command, not inside string arguments to git commit -m, echo, printf, or heredoc bodies.

Suggested fix

Before pattern matching, split the command on shell operators (&&, ||, ;), then skip any segment that starts with git commit, echo, cat, or printf since those are producing text output, not executing destructive operations.

Found this while building a similar hook inspired by gstack's /careful approach. Happy to submit a PR if useful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions