> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ooneex.com/llms.txt
> Use this file to discover all available pages before exploring further.

# ai:middleware:create

> Generate a new AI middleware class.

Scaffold a new AI middleware class and its matching test file under a module's `ai/middlewares` directory. The `@ooneex/ai` dependency is installed if it is not already present.

## Usage

```bash theme={null}
ooneex ai:middleware:create [options]
```

## Examples

```bash theme={null}
# Interactive: prompts for the middleware name
ooneex ai:middleware:create

# Provide the name as a flag
ooneex ai:middleware:create --name=Audit

# Target a specific module
ooneex ai:middleware:create --name=Audit --module=help
```

## Options

| Option       | Description                                                           | Default             |
| ------------ | --------------------------------------------------------------------- | ------------------- |
| `--name`     | Middleware name. Normalized to PascalCase with a `Middleware` suffix. | Prompted if omitted |
| `--module`   | Target module the middleware is created in.                           | `shared`            |
| `--override` | Overwrite the files if they already exist.                            | `false`             |

## AI Skill

This command ships a matching `ai:middleware:create` skill. It generates the middleware class and test file, then guides your AI agent through implementing a chat middleware that implements `IMiddleware` from `@ooneex/ai` to observe or transform the chat lifecycle. This is chat middleware, not HTTP or socket middleware.

<Tabs>
  <Tab title="Claude">
    ```bash theme={null}
    ooneex claude:init
    ```
  </Tab>

  <Tab title="Codex">
    ```bash theme={null}
    ooneex codex:init
    ```
  </Tab>
</Tabs>
