# How to Create and Use Custom Patterns in Fabric: A Complete Guide

> Learn to create and use custom patterns in Fabric for reusable prompt packages. Discover how custom patterns override built-in ones for enhanced flexibility. Get this complete guide now.

- Repository: [Daniel Miessler 🛡️/fabric](https://github.com/danielmiessler/fabric)
- Tags: how-to-guide
- Published: 2026-02-28

---

**Fabric enables you to create reusable prompt packages in a dedicated directory that persists across updates, with custom patterns automatically taking precedence over built-in ones when names collide.**

The `danielmiessler/fabric` CLI tool treats a **pattern** as a reusable prompt package containing system instructions, user templates, and optional configuration files. While Fabric ships with built-in patterns stored in `data/patterns`, creating **custom patterns** allows you to extend functionality without risking overwrite during upgrades. This guide explains the complete workflow from initial setup to execution, based on the actual source code implementation.

## Understanding the Custom Patterns Architecture

The custom patterns system relies on three core components working together to load and prioritize your private prompts.

### The CustomPatterns Plugin

Located in [`internal/tools/custom_patterns/custom_patterns.go`](https://github.com/danielmiessler/fabric/blob/main/internal/tools/custom_patterns/custom_patterns.go), the **CustomPatterns** plugin handles the initial configuration. It registers an interactive **setup question** that prompts you for a directory path, expands the `~` home directory shortcut, resolves the absolute path, and creates the folder if it does not exist. The plugin exposes an `IsConfigured()` method that verifies whether a custom directory has been set before the application attempts to load patterns.

### The PatternsLoader Merge Logic

In [`internal/tools/patterns_loader.go`](https://github.com/danielmiessler/fabric/blob/main/internal/tools/patterns_loader.go), the **PatternsLoader** orchestrates pattern discovery. During initialization, it scans both the built-in directory (`o.Patterns.Dir`) and your custom path stored in `CustomPatterns.CustomPatternsDir`. It merges these into a single map, with **custom patterns taking precedence** because they are added to the map after the built-in ones. This means if both directories contain a pattern named `summarize`, Fabric automatically uses your custom version.

### PluginRegistry Integration

The [`internal/core/plugin_registry.go`](https://github.com/danielmiessler/fabric/blob/main/internal/core/plugin_registry.go) file wires the **CustomPatterns** plugin into Fabric's global registry. This integration ensures your custom directory participates in the interactive `fabric --setup` flow and that the path is written to the generated `.env` file as `CUSTOM_PATTERNS_DIRECTORY`. Because the configuration persists in `.env`, your custom patterns remain available across application restarts and upgrades.

## Setting Up Your Custom Patterns Directory

You can configure the custom patterns directory through the interactive setup or manual environment configuration.

### Interactive Setup Method

Run the setup command and specify your preferred storage location:

```bash
fabric --setup

```

When prompted for **Custom Patterns**, enter an absolute or relative path such as `~/my-custom-patterns`. Fabric automatically expands the path, creates the directory structure if missing, and writes the configuration to your `.env` file.

### Manual Environment Configuration

Alternatively, set the directory directly in your `.env` file using the `CUSTOM_PATTERNS_DIRECTORY` variable:

```env
CUSTOM_PATTERNS_DIRECTORY=/home/user/personal-patterns

```

When the environment loads, `CustomPatterns.IsConfigured()` returns true and the **PatternsLoader** automatically includes this path in its scan.

## Creating a Custom Pattern

Each subfolder in your custom directory represents a distinct pattern, following the same structure as built-in patterns.

### Required File Structure

Create a new folder inside your custom patterns directory. The folder name becomes the pattern identifier used with the `--pattern` flag. At minimum, you must include:

- **system.md**: Contains the system prompt instructions that define the AI's behavior
- **user.md**: (Optional) Template for user-specific inputs
- **config.json**: (Optional) Additional configuration parameters

For example, to create a pattern called `security-analyzer`:

```bash
mkdir -p ~/my-custom-patterns/security-analyzer
cat > ~/my-custom-patterns/security-analyzer/system.md <<'EOF'
You are a cybersecurity expert. Analyze the input for vulnerabilities and provide remediation steps. Be concise and technical.
EOF

```

## Using Custom Patterns in Commands

Once configured, custom patterns integrate seamlessly with standard Fabric workflows.

### Listing Available Patterns

Run the following command to see both built-in and custom patterns:

```bash
fabric --listpatterns

```

Custom patterns appear alongside built-in options, allowing you to verify that Fabric detected your new templates.

### Executing Custom Patterns

Invoke your pattern using the standard `--pattern` flag:

```bash
fabric --pattern security-analyzer "Review this firewall configuration"

```

Fabric resolves the directory, loads your custom [`system.md`](https://github.com/danielmiessler/fabric/blob/main/system.md), and applies it to the request. If a built-in pattern shares the same name as your custom one, Fabric automatically selects your custom version due to the merge precedence logic in [`internal/tools/patterns_loader.go`](https://github.com/danielmiessler/fabric/blob/main/internal/tools/patterns_loader.go).

## Summary

- The **CustomPatterns** plugin in [`internal/tools/custom_patterns/custom_patterns.go`](https://github.com/danielmiessler/fabric/blob/main/internal/tools/custom_patterns/custom_patterns.go) manages directory configuration through interactive setup or the `CUSTOM_PATTERNS_DIRECTORY` environment variable.
- **PatternsLoader** automatically merges built-in and custom directories, with custom patterns taking precedence when names collide.
- Each custom pattern requires a folder containing at least a [`system.md`](https://github.com/danielmiessler/fabric/blob/main/system.md) file, with optional [`user.md`](https://github.com/danielmiessler/fabric/blob/main/user.md) and [`config.json`](https://github.com/danielmiessler/fabric/blob/main/config.json) files for advanced configurations.
- Custom patterns persist across Fabric updates because they reside outside the core `data/patterns` directory and store their path in the `.env` file.

## Frequently Asked Questions

### Where does Fabric store the custom patterns configuration?

Fabric stores the custom patterns path in the `.env` file under the variable `CUSTOM_PATTERNS_DIRECTORY`. This value is written during the interactive `fabric --setup` process or can be set manually. The **CustomPatterns** plugin reads this variable at runtime to determine where to scan for user-defined patterns.

### What files are required to create a valid custom pattern?

You must include a [`system.md`](https://github.com/danielmiessler/fabric/blob/main/system.md) file inside a folder named after your pattern. This file contains the system instructions that define the AI's role and behavior. While [`user.md`](https://github.com/danielmiessler/fabric/blob/main/user.md) and [`config.json`](https://github.com/danielmiessler/fabric/blob/main/config.json) are optional, following the standard pattern structure ensures compatibility with Fabric's loading mechanisms.

### Do custom patterns override built-in patterns with the same name?

Yes. When **PatternsLoader** builds the pattern map in [`internal/tools/patterns_loader.go`](https://github.com/danielmiessler/fabric/blob/main/internal/tools/patterns_loader.go), it loads custom patterns after built-in ones. This sequence ensures that custom entries overwrite built-in entries in the map, giving your private prompts automatic precedence without requiring special flags or configuration changes.

### Can I use environment variables instead of interactive setup for custom patterns?

Yes. You can manually set `CUSTOM_PATTERNS_DIRECTORY` in your `.env` file or export it as an environment variable before running Fabric. The **CustomPatterns** plugin checks `IsConfigured()` by verifying this variable exists, allowing the **PatternsLoader** to include your custom directory without ever running the interactive setup wizard.