Skip to content
UsecaseBoard
← All use cases
hashnodeCoding

Format Claude Code edits automatically with a hook

At a glance

A developer configures a PostToolUse hook to run Prettier after Claude writes or edits a file. This workflow is listed under Coding.

Agents / tools
Claude

SourceBuilding a tool for these workflows? See weekly rates.

What they did

1) Have jq and Prettier available and add a hooks configuration to Claude Code settings. Under PostToolUse, match Edit|Write and define a command hook that extracts .tool_input.file_path from the tool input with jq and passes it to npx prettier --write. 2) Ask Claude Code to edit or write a file: the matching hook runs after that tool call. 3) Review the formatted file; the hook is scoped to Edit and Write, so Bash or Read calls do not trigger it.

How it went

The author reports that the hook removed the need to run Prettier manually after each edit.

Worth knowing

The article's example passes the extracted path through xargs; adapt and test the command for your own paths and project before relying on it.

Save ideas in this browser. Upvotes count across the board.

Prompt excerpt

No prompt excerpt was provided by the source.

Sponsored

CodeBuddy

Tencent Cloud AI coding assistant for IDE and CLI.

Try CodeBuddy ↗
Explore all →