llamafile
Expert guidance for llamafile, the tool that packages LLMs into single executable files that run on any OS (Linux, macOS, Windows, FreeBSD) without installation. Helps developers create portable AI applications, run models offline, and distribute LLMs as self-contained binaries with built-in web UI and OpenAI-compatible API.
What this skill does
# llamafile — Single-File LLM Executables
## Overview
Llamafile, the tool that packages LLMs into single executable files that run on any OS (Linux, macOS, Windows, FreeBSD) without installation. Helps developers create portable AI applications, run models offline, and distribute LLMs as self-contained binaries with built-in web UI and OpenAI-compatible API.
## Instructions
### Running a llamafile
```bash
# Download a pre-built llamafile (model + runtime in one file)
wget https://huggingface.co/Mozilla/Meta-Llama-3.1-8B-Instruct-llamafile/resolve/main/Meta-Llama-3.1-8B-Instruct.Q5_K_M.llamafile
# Make it executable and run
chmod +x Meta-Llama-3.1-8B-Instruct.Q5_K_M.llamafile
./Meta-Llama-3.1-8B-Instruct.Q5_K_M.llamafile
# Opens web UI at http://localhost:8080
# Also serves OpenAI-compatible API at http://localhost:8080/v1
# Run with specific settings
./Meta-Llama-3.1-8B-Instruct.Q5_K_M.llamafile \
--host 0.0.0.0 \
--port 8080 \
--ctx-size 8192 \
--threads 8 \
--gpu auto # Use GPU if available (CUDA, Metal, ROCm)
```
### Creating Custom llamafiles
```bash
# Build a llamafile from any GGUF model
# 1. Download the llamafile runtime
wget https://github.com/Mozilla-Ocho/llamafile/releases/latest/download/llamafile
chmod +x llamafile
# 2. Download a GGUF model from HuggingFace
wget https://huggingface.co/TheBloke/Mistral-7B-Instruct-v0.2-GGUF/resolve/main/mistral-7b-instruct-v0.2.Q5_K_M.gguf
# 3. Create the llamafile (packages model + runtime)
./llamafile \
--model mistral-7b-instruct-v0.2.Q5_K_M.gguf \
--create my-assistant.llamafile
# 4. The resulting file runs anywhere — no dependencies
./my-assistant.llamafile --port 8080
# With a custom system prompt baked in
./llamafile \
--model mistral-7b-instruct-v0.2.Q5_K_M.gguf \
--system-prompt "You are a customer support assistant for Acme Inc. Be helpful and concise." \
--create acme-support-bot.llamafile
```
### OpenAI-Compatible API
```typescript
// src/local-llm.ts — Use llamafile with any OpenAI-compatible SDK
import OpenAI from "openai";
// Point to the local llamafile server
const llm = new OpenAI({
apiKey: "not-needed", // llamafile doesn't require auth
baseURL: "http://localhost:8080/v1",
});
async function chat(prompt: string) {
const response = await llm.chat.completions.create({
model: "local", // Model name doesn't matter for llamafile
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: prompt },
],
temperature: 0.7,
max_tokens: 512,
});
return response.choices[0].message.content;
}
// Streaming works too
async function streamChat(prompt: string) {
const stream = await llm.chat.completions.create({
model: "local",
messages: [{ role: "user", content: prompt }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}
}
// Embeddings
async function embed(text: string) {
const response = await llm.embeddings.create({
model: "local",
input: text,
});
return response.data[0].embedding;
}
```
### CLI Usage (No Server)
```bash
# One-shot completion (no server, just stdin → stdout)
echo "Explain Docker in one sentence:" | ./llamafile --cli
# With a system prompt
./llamafile --cli \
--system "You are a Linux expert. Answer in one line." \
--prompt "How do I find files larger than 100MB?"
# Process a file
cat error_log.txt | ./llamafile --cli \
--system "Analyze this error log. Identify the root cause."
# Batch processing with a script
for file in reports/*.txt; do
echo "=== $file ==="
cat "$file" | ./llamafile --cli \
--system "Summarize this report in 3 bullet points." \
--temp 0
done
```
### Embedding in Applications
```python
# Run llamafile as a subprocess from your application
import subprocess
import requests
class LlamafileServer:
"""Manage a llamafile server as a subprocess."""
def __init__(self, model_path: str, port: int = 8080):
self.model_path = model_path
self.port = port
self.process = None
self.base_url = f"http://localhost:{port}"
def start(self):
self.process = subprocess.Popen(
[self.model_path, "--port", str(self.port), "--host", "127.0.0.1"],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
# Wait for server to be ready
import time
for _ in range(30):
try:
requests.get(f"{self.base_url}/health", timeout=1)
return
except requests.ConnectionError:
time.sleep(1)
raise RuntimeError("llamafile failed to start")
def chat(self, prompt: str, system: str = "") -> str:
response = requests.post(
f"{self.base_url}/v1/chat/completions",
json={
"messages": [
{"role": "system", "content": system},
{"role": "user", "content": prompt},
],
"temperature": 0.7,
},
)
return response.json()["choices"][0]["message"]["content"]
def stop(self):
if self.process:
self.process.terminate()
self.process.wait()
# Usage
server = LlamafileServer("./my-model.llamafile", port=8081)
server.start()
answer = server.chat("What is the capital of France?")
server.stop()
```
## Installation
```bash
# No installation needed — llamafile IS the installation
# Download and run. That's it.
# For creating llamafiles:
wget https://github.com/Mozilla-Ocho/llamafile/releases/latest/download/llamafile
chmod +x llamafile
```
## Examples
### Example 1: Integrating Llamafile into an existing application
**User request:**
```
Add Llamafile to my Next.js app for the AI chat feature. I want streaming responses.
```
The agent installs the SDK, creates an API route that initializes the Llamafile client, configures streaming, selects an appropriate model, and wires up the frontend to consume the stream. It handles error cases and sets up proper environment variable management for the API key.
### Example 2: Optimizing creating custom llamafiles performance
**User request:**
```
My Llamafile calls are slow and expensive. Help me optimize the setup.
```
The agent reviews the current implementation, identifies issues (wrong model selection, missing caching, inefficient prompting, no batching), and applies optimizations specific to Llamafile's capabilities — adjusting model parameters, adding response caching, and implementing retry logic with exponential backoff.
## Guidelines
1. **Single file = single deployment** — Distribute your AI as one file; users double-click to run, no Python/Docker/CUDA setup
2. **GPU auto-detection** — llamafile automatically uses GPU when available (CUDA, Metal, ROCm); falls back to CPU
3. **Quantized models for speed** — Use Q5_K_M or Q4_K_M quantizations; they're 3-5x smaller with minimal quality loss
4. **OpenAI API compatibility** — Use the same code for local llamafile and cloud APIs; swap by changing the base URL
5. **CLI mode for scripts** — Use `--cli` for batch processing; pipe text in, get completions out, no server needed
6. **Air-gapped environments** — llamafile runs completely offline; ideal for sensitive data or environments without internet
7. **Context size matters** — Set `--ctx-size` based on your use case; larger contexts need more RAM
8. **One model per llamafile** — Each llamafile contains one model; run multiple on different ports for model routing
Related in Design
contribute
IncludedLocal-only OSS contribution command center. Auto-refreshes the user's in-flight PR and issue state on invoke so conversations start with full context — no need to brief Claude on what's in flight. Helps the user find issues to contribute to on GitHub, builds per-repo dossiers of what each upstream expects (CLA, DCO, branch convention, AI policy, draft-first, review bots, issue templates), runs deterministic gates before any external action so AI-assisted contributions don't reach maintainers as slop. State is markdown-only: candidate files at ~/.contribute-system/candidates/, repo dossiers at ~/.contribute-system/research/, append-only event log at ~/.contribute-system/log.jsonl. No database, no cloud calls. Use when the user asks about their PRs / issues / contributions, wants to find new work to take on, claim an issue, build/refresh a repo's dossier, or draft a Design Issue or PR. Trigger with "/contribute", "what's my PR status", "find a contribution", "claim issue X", "draft a Design Issue for Y", "refresh dossier for Z".
architectural-analysis
IncludedUser-triggered deep architectural analysis of a codebase or scoped subtree across eight modes — information architecture, data flow, integration points, UI surfaces, interaction patterns, data model, control flow, and failure modes. This skill should be used when the user asks to "diagram this codebase," "map the architecture," "show the data flow," "give me an ERD," "trace control flow," "find the integration points," "verify the layout pattern," "audit the UX architecture," or any similar request whose primary deliverable is mermaid diagrams plus cited reports under docs/architecture/. Dispatches haiku/sonnet sub-agents in parallel for per-mode exploration, then verifies every citation mechanically before any node lands in a diagram. Not for one-off prose explanations of code (use code-explanation) or for high-level system design from scratch (use system-design).
mcp
IncludedModel Context Protocol (MCP) server development and tool management. Languages: Python, TypeScript. Capabilities: build MCP servers, integrate external APIs, discover/execute MCP tools, manage multi-server configs, design agent-centric tools. Actions: create, build, integrate, discover, execute, configure MCP servers/tools. Keywords: MCP, Model Context Protocol, MCP server, MCP tool, stdio transport, SSE transport, tool discovery, resource provider, prompt template, external API integration, Gemini CLI MCP, Claude MCP, agent tools, tool execution, server config. Use when: building MCP servers, integrating external APIs as MCP tools, discovering available MCP tools, executing MCP capabilities, configuring multi-server setups, designing tools for AI agents.
react-native-skia
IncludedDesign, build, debug, and optimise high-polish animated graphics in React Native or Expo using @shopify/react-native-skia, Reanimated, and Gesture Handler. Use when the user wants canvas-driven UI, shaders, paths, rich text, image filters, sprite fields, Skottie, video frames, snapshots, web CanvasKit setup, or performance tuning for custom motion-heavy elements such as loaders, hero art, cards, charts, progress indicators, particle systems, or gesture-driven surfaces. Also use when the user asks for fluid, glow, glass, blob, parallax, 60fps/120fps, or GPU-friendly animated effects in React Native, even if they do not explicitly say "Skia". Do not use for ordinary form/layout work with standard views.
plaid
IncludedProduct Led AI Development — guides founders from idea to launched product. Six capabilities: Idea (discover a product idea), Validate (pressure-test the idea against fatal flaws, problem reality, competition, and 2-week MVP feasibility), Plan (vision intake + document generation), Design (translate image references into a design.md spec), Launch (go-to-market strategy), and Build (roadmap execution). Use when someone says "PLAID", "plaid idea", "help me find an idea", "product idea", "idea from my business", "idea from my expertise", "plaid validate", "validate my idea", "pressure-test", "is this idea good", "find fatal flaws", "validate the problem", "plan a product", "define my vision", "generate a PRD", "product strategy", "plaid design", "design from image", "translate image to design", "create design.md", "extract design tokens", "plaid launch", "go-to-market", "launch plan", "GTM strategy", "launch playbook", "plaid build", "build the app", "start building", or "execute the roadmap".
nextjs-framer-motion-animations
IncludedAdds production-safe Motion for React or Framer Motion animations to Next.js apps, including reveal, hover and tap micro-interactions, whileInView, stagger, AnimatePresence, layout and layoutId transitions, reorder, scroll-linked UI, and lightweight route-content transitions. Use when the user asks to add, refactor, or debug Motion or Framer Motion in App Router or Pages Router codebases, especially around server/client boundaries, reduced motion, LazyMotion, bundle size, hydration, or route transitions. Avoid for GSAP-style timelines, WebGL or 3D scenes, heavy scroll storytelling, or CSS-only effects unless Motion is explicitly requested.