OpenWriterControle/plugins/claude-code/scripts/context/openagents-repo/examples/hooks/formatting-hook.md
Darren Hinde a8fc9c7715
feat(plugin): enhance context management and skill invocation (#239)
* fix(shellcheck): declare and assign separately in router.sh (SC2155)

* feat(plugin): enhance context management and skill invocation

- Update .context-manifest.json to include profile and detailed source information.
- Revise context-scout.md to clarify context root discovery and navigation.
- Modify commands to replace deprecated skills with updated ones (brainstorming → approach, systematic-debugging → debugger).
- Streamline install-context.md for clarity and remove interactive profile selection.
- Improve oac-status.md to provide a more comprehensive status report.
- Add OAC system paths to session-start.sh for better context management.
- Remove obsolete skills and improve documentation for existing commands.
2026-02-23 12:12:29 +00:00

1.2 KiB

Code Formatting Hook

Purpose: Auto-format files after Claude edits them


TypeScript/Prettier Hook

{
  "hooks": {
    "PostToolUse": [{
      "matcher": "Edit|Write",
      "hooks": [{
        "type": "command",
        "command": "jq -r '.tool_input.file_path' | { read file_path; if echo \"$file_path\" | grep -q '\\.ts$'; then npx prettier --write \"$file_path\"; fi; }"
      }]
    }]
  }
}

How It Works

  1. Triggers after Edit or Write tool completes
  2. Extracts file path from JSON input via jq
  3. Checks if file is .ts extension
  4. Runs prettier on matching files

Variations

Go files:

if echo "$file_path" | grep -q '\\.go$'; then gofmt -w "$file_path"; fi

Python files:

if echo "$file_path" | grep -q '\\.py$'; then black "$file_path"; fi

Multiple extensions:

if echo "$file_path" | grep -qE '\\.(ts|tsx|js|jsx)$'; then npx prettier --write "$file_path"; fi

  • ../../lookup/hook-events.md - Hook events reference
  • ./protection-hook.md - File protection example

Reference: https://docs.anthropic.com/en/docs/claude-code/hooks