From harn
Generate PostToolUse auto-formatter hook. Triggers: /harn:format, 'auto format', 'formatter hook', 'PostToolUse formatter'
npx claudepluginhub sliday/harnThis skill uses the workspace's default tool permissions.
Generate `scripts/harness/auto_formatter.sh` — a PostToolUse hook that auto-formats files after every Edit or Write tool call.
Provides Ktor server patterns for routing DSL, plugins (auth, CORS, serialization), Koin DI, WebSockets, services, and testApplication testing.
Conducts multi-source web research with firecrawl and exa MCPs: searches, scrapes pages, synthesizes cited reports. For deep dives, competitive analysis, tech evaluations, or due diligence.
Provides demand forecasting, safety stock optimization, replenishment planning, and promotional lift estimation for multi-location retailers managing 300-800 SKUs.
Generate scripts/harness/auto_formatter.sh — a PostToolUse hook that auto-formats files after every Edit or Write tool call.
Scan the project root to determine which formatter to use:
| Check | Formatter command |
|---|---|
.prettierrc, prettier.config.*, or "prettier" in package.json | npx prettier --write |
pyproject.toml containing [tool.black], or .black config file | black |
rustfmt.toml or Cargo.toml | rustfmt |
go.mod | gofmt -w |
| None of the above | Skip formatting (echo to stderr and exit 0) |
Use Glob and Read to check for these files. Pick the first match in the order listed above.
Create scripts/harness/auto_formatter.sh with the following structure. Replace {{FORMATTER_CMD}} with the detected formatter command from step 1.
#!/usr/bin/env bash
# Auto-formatter PostToolUse hook — generated by harn:auto-formatter
# Formats files after Edit/Write tool calls
set -euo pipefail
# Read hook JSON payload from stdin
PAYLOAD="$(cat)"
# Extract tool name
TOOL_NAME="$(echo "$PAYLOAD" | jq -r '.tool_name // empty')"
# Only run for Edit or Write tools
if [[ "$TOOL_NAME" != "Edit" && "$TOOL_NAME" != "Write" ]]; then
exit 0
fi
# Extract file path from parameters
FILE_PATH="$(echo "$PAYLOAD" | jq -r '.parameters.file_path // empty')"
if [[ -z "$FILE_PATH" || ! -f "$FILE_PATH" ]]; then
exit 0
fi
# Run formatter with timeout
timeout 5 {{FORMATTER_CMD}} "$FILE_PATH" 2>/dev/null && \
echo "Harn: Formatted $FILE_PATH" >&2 || true
exit 0
Make the script executable:
chmod +x scripts/harness/auto_formatter.sh
.claude/settings.jsonRead the existing .claude/settings.json (or create it if missing). Add the PostToolUse hook configuration:
{
"hooks": {
"PostToolUse": [
{
"matcher": "Edit|Write",
"hooks": [
{
"type": "command",
"command": "bash scripts/harness/auto_formatter.sh",
"timeout": 5
}
]
}
]
}
}
If settings.json already has other hooks, merge this entry into the existing PostToolUse array without overwriting other hook types.
Run the script with a test payload to confirm it exits cleanly:
echo '{"tool_name":"Edit","parameters":{"file_path":"/dev/null"}}' | bash scripts/harness/auto_formatter.sh
Report which formatter was detected and confirm the hook is wired.