ワンクリックで
auto-formatter
Generate PostToolUse auto-formatter hook. Triggers: /harn:format, 'auto format', 'formatter hook', 'PostToolUse formatter'
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Generate PostToolUse auto-formatter hook. Triggers: /harn:format, 'auto format', 'formatter hook', 'PostToolUse formatter'
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
Scaffold a complete harness for the current project — AGENTS.md, hooks, guardrails. Use when starting a new project or hardening an existing one. Triggers: /harn:init, 'set up harness', 'scaffold guardrails', 'create AGENTS.md'
Build or rebuild AGENTS.md with progressive disclosure. Use when: /harn:agents-md, 'create AGENTS.md', 'update agent instructions', 'too many instructions'
Audit project harness against the CAR framework. Use when: /harn:analyze, 'audit harness', 'check CAR', 'harness health', 'how good is my harness'
Scaffold resume artifacts (LEARNED.md, CHECKPOINT.json) for long-running sessions. Triggers: /harn:checkpoint, 'resume artifacts', 'checkpoint', 'session recovery', 'LEARNED.md'
Generate context monitoring and backpressure hooks. Triggers: /harn:context, 'context monitoring', 'backpressure', 'context budget', 'attention budget', 'context rot'
Generate or update the quality gate Stop hook. Use when: /harn:quality-gate, 'set up type checking', 'add quality gate', 'stop hook'
| name | auto-formatter |
| description | Generate PostToolUse auto-formatter hook. Triggers: /harn:format, 'auto format', 'formatter hook', 'PostToolUse formatter' |
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.