# format-javascript-files

> Automatically format JavaScript/TypeScript files after any Edit operation using prettier. This hook runs 'npx prettier --write' on any .js, .ts, .jsx, or .

- Source: https://doutorai.pt/en/components/hooks__format-javascript-files
- Type: Automations
- Category: Post Tool
- Downloads: 388
- Site: Doutor AI (https://doutorai.pt/en) - AI tools for small businesses

An open-source community component, curated and adapted by Doutor AI.

## What it does and how to use it

A **hook** that automates post tool actions at key moments (before/after a tool runs, on save, etc.), without you having to think about it.

1. Install the hook (command above).
2. It runs automatically on the defined events.
3. Adjust the rules in the settings file if you want to fine-tune it.

## Install (Claude Code)

```bash
mkdir -p .claude/hooks && curl -fsSL https://doutorai.pt/data/lib/hooks__format-javascript-files.md -o .claude/hooks/format-javascript-files.json
```

Paste this command into the terminal, in your project folder, and the component installs automatically.

## Content

```
{
  "description": "Automatically format JavaScript/TypeScript files after any Edit operation using prettier. This hook runs 'npx prettier --write' on any .js, .ts, .jsx, or .tsx file that Claude modifies, ensuring consistent code formatting. Uses npx so prettier doesn't need to be globally installed. Includes error suppression so it won't fail if prettier is not available.",
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit",
        "hooks": [
          {
            "type": "command",
            "command": "if [[ \"$CLAUDE_TOOL_FILE_PATH\" =~ \\.(js|ts|jsx|tsx)$ ]]; then n

- 🔒 Full content on the Pro plan (€7.99/month) -
```

## Related components

- [agents-md-loader](https://doutorai.pt/en/components/hooks__agents-md-loader): Automatically loads AGENTS.md configuration file content at session start to ensure Claude Code follows project-specific agent behavior. Onl
- [ai-bash-guard](https://doutorai.pt/en/components/hooks__ai-bash-guard): AI-powered bash command security guard. Before any Bash command runs, a lightweight Claude subagent evaluates it for destructive or irrevers
- [auto-git-add](https://doutorai.pt/en/components/hooks__auto-git-add): Automatically stage modified files with git add after editing. Helps maintain a clean git workflow by staging changes as they're made.
- [backup-before-edit](https://doutorai.pt/en/components/hooks__backup-before-edit): Create automatic backup of files before any Edit operation for safety. This hook creates a timestamped backup copy (filename.backup.timestam
- [build-on-change](https://doutorai.pt/en/components/hooks__build-on-change): Automatically trigger build processes when source files change. Detects common build tools and runs appropriate build commands.
- [change-logger](https://doutorai.pt/en/components/hooks__change-logger-2): Log every file mutation to CSV for demo prep. Records timestamp, tool, file path, action, and details for Edit, MultiEdit, Write, and Bash o

## Save hours every week with AI, no hassle

**Doutor AI** gives you 1,859 ready-to-copy AI prompts, by industry and in plain English - plus a complete technical library for those who want to go further. [See plans →](https://doutorai.pt/en/pricing)

---
Content by Doutor AI (https://doutorai.pt/en). When quoting, please cite the source: https://doutorai.pt/en/components/hooks__format-javascript-files
