---
title: Hooks
description: Run Ultracite after AI-assisted file edits with editor hooks so formatting and safe fixes happen automatically before review.
---

Ultracite can automatically format and fix code after AI coding assistants make edits through hooks. This ensures all AI-generated code adheres to your project's standards without manual intervention.

The hooks work alongside your linter's formatting. After an AI coding assistant edits a file, the hook automatically runs `npx ultracite fix` to format and fix auto-fixable linting issues. This dual approach ensures both intelligent code generation (through AI rules) and automated code quality (through hooks).

> **Note:** Hooks are separate from AI coding rules. The `--agents` flag configures AI coding rules, while the `--hooks` flag sets up automatic formatting after file edits.

## Setup

Some tools like Cursor, Windsurf, CodeBuddy, and Claude Code support hooks that run after AI agents edit files. Ultracite can configure these hooks automatically.

### Automatic Setup

When you run `npx ultracite init`, you'll be prompted to select which editor hooks you want to enable:

```bash
? Which agent hooks do you want to enable (optional)?
  ◯ Cursor
  ◯ Windsurf
  ◯ CodeBuddy
  ◯ Claude Code
```

This will create the relevant hook configuration file in your project directory.

Ultracite writes the following files:

- Cursor: `.cursor/hooks.json`
- Windsurf: `.windsurf/hooks.json`
- CodeBuddy: `.codebuddy/settings.json`
- Claude Code: `.claude/settings.json`

### Manual Setup

If you want to manually set things up or add hooks after initialization, run:

```bash
npx ultracite init --hooks cursor windsurf codebuddy claude
```

Alternatively, you can manually create or edit the hook configuration files in your project directory and add the appropriate hook command.

## How It Works

1. **Automatic Execution**: After the AI agent edits a file, the hook automatically runs `npx ultracite fix`
2. **Code Formatting**: Ultracite formats the edited code according to your linter configuration
3. **Linting Fixes**: Auto-fixable linting issues are resolved automatically
4. **Seamless Integration**: The process happens transparently without interrupting your workflow

## Benefits

Using Ultracite editor hooks provides several advantages:

- **Consistency**: All AI-generated code is automatically formatted to match your style
- **Quality**: Linting issues are fixed immediately after code generation
- **Efficiency**: No need to manually run formatters or linters after AI edits
- **Standards**: Ensures AI-generated code always adheres to project standards
- **Clean Commits**: Code is properly formatted before you even review it

## Customization

Ultracite intelligently merges with existing hook configurations:

- **Preserves existing hooks**: All existing hooks and their commands remain intact
- **Avoids duplicates**: If Ultracite is already configured, it won't be added again
- **Non-destructive**: Your existing hook configuration structure is maintained

You can also customize the hook behavior by modifying the hook configuration files directly if you need different formatting commands or additional post-edit actions.
