Skip to content

Claude Code gofmt hook never runs: $CLAUDE_FILE_PATHS is not set (same in conforma/policy) #3601

Open

Description

@faizjamal0111-svg

The PostToolUse hook in .claude/settings.json reads $CLAUDE_FILE_PATHS, which Claude Code doesn't set: the tool call arrives as JSON on stdin, with the path at tool_input.file_path (hooks reference: https://code.claude.com/docs/en/hooks). So f is always empty and gofmt never runs on a file Claude edits.

Fix (needs jq):

"command": "f=$(jq -r '.tool_input.file_path // empty'); case \"$f\" in *.go) gofmt -w \"$f\" 2>/dev/null;; esac"

Tested with the JSON Claude Code sends for an Edit to cmd/main.go: before, nothing runs; after, gofmt -w runs on that file, and a .md edit still runs nothing.

conforma/policy has the same pattern for .rego files, so make fmt never runs there either. The same change works:

"command": "if jq -r '.tool_input.file_path // empty' | grep -q '\\.rego$'; then make fmt 2>/dev/null; fi"

Found this while testing Claude Code hooks for Paveo; uvx paveo doctor flags both. Happy to open a PR in each repo.

Activity

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

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions