How to Use Fabric from the Command Line: The Complete Guide
Fabric is a Go-based CLI that executes AI-augmented prompts (patterns) directly from your terminal by parsing flags defined in internal/cli/flags.go and orchestrating requests through internal/cli/cli.go.
Fabric—an open-source AI pattern framework maintained by Daniel Miessler—turns your terminal into an AI powerhouse. When you use Fabric from the command line, you can summarize articles, extract wisdom from YouTube videos, and run a local REST API server through simple Unix-style pipes and flags. The tool's architecture centers on a lightweight Go binary that bridges your shell environment with multiple AI vendors.
Installation and Initial Configuration
Before running patterns, you must install the binary and initialize the environment.
Installing the Fabric Binary
The project provides a one-line installer script that downloads and installs the latest release:
curl -fsSL https://raw.githubusercontent.com/danielmiessler/fabric/main/scripts/installer/install.sh | bash
First-Time Setup with --setup
Fabric stores API keys and default model settings in a configuration directory. Run the setup command once to create ~/.config/fabric/ and a default .env file. According to internal/cli/cli.go (lines 28-32), the ensureEnvFile function handles this directory creation when you pass the --setup flag:
fabric --setup
This step is mandatory before executing any patterns, as it establishes the environment where custom patterns and vendor credentials reside.
Understanding the CLI Architecture
Fabric's command-line interface follows a clean three-layer architecture defined in the internal/cli package.
Entry Point and Version Handling
The binary compiled from cmd/fabric/main.go serves as the minimal entry point. It initializes the CLI by passing the version string to internal/cli.Cli, immediately delegating control to the orchestration layer:
// Located in cmd/fabric/main.go (lines 12-14)
cli.Cli(v)
Flag Parsing via internal/cli/flags.go
All command-line options are centralized in the Flags struct within internal/cli/flags.go (lines 28-80). The implementation uses the go-flags library to automatically map struct tags to both long (--pattern) and short (-p) command-line flags. This declarative approach ensures that every configuration option—from model selection to output formatting—is accessible via predictable CLI arguments.
Core Orchestration in internal/cli/cli.go
After flag parsing, the Cli function in internal/cli/cli.go coordinates execution. It constructs a ChatRequest from your supplied options and hands it to the core.PluginRegistry, which resolves the AI vendor, loads the pattern from ~/.config/fabric/patterns/ (or built-in defaults), and manages the request lifecycle.
Essential Command-Line Operations
Once configured, you can use Fabric from the command line to process text, URLs, and files through AI patterns.
Basic Pattern Execution
Pipe text directly into Fabric and specify a pattern using the --pattern or -p flag:
# Summarize clipboard content
pbpaste | fabric --pattern summarize
View all available flags and options by running:
fabric -h
Processing YouTube Videos
Use the -y flag to extract transcripts and process them with any pattern. Combine with --stream to see incremental results:
fabric -y "https://youtube.com/watch?v=uXs-zPc63kM" --stream --pattern extract_wisdom
Output Management
Control where results go using the --output, --copy, and --stream flags. Results print to stdout by default, but you can write to files or copy to the clipboard:
# Save analysis to markdown
fabric -p write_latex "AI security primer" > report.md
# Copy results directly to clipboard
fabric --pattern summarize --copy < article.txt
Listing Available Resources
Discover available patterns, contexts, models, and vendors without leaving the terminal:
fabric --listpatterns
fabric --listcontexts
fabric --listmodels
fabric --listvendors
Advanced CLI Workflows
Beyond simple text processing, Fabric supports complex automation and server modes.
Running Custom Patterns
Store your own prompts in ~/.config/fabric/patterns/my-analyzer/ and invoke them by name:
fabric --pattern my-analyzer "analyze this text"
Applying Reasoning Strategies
Enhance patterns with chain-of-thought or other strategies using the --strategy flag:
echo "Explain quantum entanglement" | fabric --strategy cot -p explain_concept
Starting the REST API Server
Fabric can expose its functionality as a local HTTP server. Use the --serve flag to start the built-in REST API (defaults to port 8080):
fabric --serve
Summary
- Fabric is a Go-based CLI tool for running AI patterns from the terminal, sourced from the
danielmiessler/fabricrepository. - The entry point at
cmd/fabric/main.godelegates tointernal/cli/cli.go, whileinternal/cli/flags.godefines all available command-line options using thego-flagslibrary. - Initial setup requires running
fabric --setupto create the~/.config/fabric/directory and.envconfiguration files via theensureEnvFilefunction. - Patterns execute by constructing a
ChatRequestthat thecore.PluginRegistryroutes to the appropriate AI vendor. - You can process piped input, YouTube URLs, local files, and custom patterns, with options to stream output, save to files, or copy to clipboard.
- Advanced features include custom pattern development in
~/.config/fabric/patterns/, reasoning strategies, and a local REST API server via--serve.
Frequently Asked Questions
How do I install Fabric on my system?
You can install Fabric using the official one-line installer script: curl -fsSL https://raw.githubusercontent.com/danielmiessler/fabric/main/scripts/installer/install.sh | bash. This downloads the compiled Go binary and places it in your system PATH. After installation, you must run fabric --setup to initialize the configuration directory at ~/.config/fabric/ and create the required .env file for API keys.
Where does Fabric store its patterns and configuration?
Fabric stores configuration files, API keys, and custom patterns in ~/.config/fabric/. The ensureEnvFile function in internal/cli/cli.go creates this directory during setup. Built-in patterns ship with the binary, while custom patterns reside in ~/.config/fabric/patterns/. You can list all available patterns anytime using the fabric --listpatterns command.
Can I use Fabric to process YouTube videos from the command line?
Yes. Use the -y flag followed by a YouTube URL to extract the transcript and pipe it through any pattern. For example: fabric -y "https://youtube.com/watch?v=..." --pattern extract_wisdom. Add the --stream flag to see results incrementally as the AI processes the content.
How do I run Fabric as a local API server?
Start the built-in REST API server by running fabric --serve, which defaults to port 8080. This exposes Fabric's pattern execution capabilities over HTTP, allowing other applications to send requests to your local instance instead of using the command-line interface directly.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →