Skip to content

Claude Code gofmt and go vet hooks never run: $CLAUDE_FILE_PATHS is not set #34

Open

Description

@faizjamal0111-svg

Both PostToolUse hooks in .claude/settings.json check $CLAUDE_FILE_PATHS for a .go path. Claude Code doesn't set that variable; it sends the tool call as JSON on stdin, with the path at tool_input.file_path (hooks reference: https://code.claude.com/docs/en/hooks). So the grep never matches, and neither gofmt nor go vet runs after an edit. The second hook also does cd d:/projects/sap-devs-cli, which exists on one machine only.

One hook covers both (needs jq):

"command": "f=$(jq -r '.tool_input.file_path // empty'); case \"$f\" in *.go) gofmt -w \"$f\" && cd \"$CLAUDE_PROJECT_DIR\" && go vet ./... 2>&1 | head -20 ;; esac"

Tested with the JSON Claude Code sends for an Edit to a .go file: before, nothing runs; after, gofmt runs on that file and go vet runs from the project root, and a .md edit runs nothing. One note: on exit 0 the vet output goes to the debug log only, so if you want Claude to act on vet findings, send them to stderr and exit 2.

Found this while testing Claude Code hooks for Paveo; uvx paveo doctor flags both hooks in one command. Happy to open a PR with the fix.

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