llamafile
llamafileに関する専門的な知識を持ち、LLMを単一の実行ファイルにパッケージ化して様々なOSで動作させる方法をアドバイスし、オフライン環境でのAIアプリ開発や自己完結型バイナリ配布を支援するSkill。
📜 元の英語説明(参考)
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.
🇯🇵 日本人クリエイター向け解説
llamafileに関する専門的な知識を持ち、LLMを単一の実行ファイルにパッケージ化して様々なOSで動作させる方法をアドバイスし、オフライン環境でのAIアプリ開発や自己完結型バイナリ配布を支援するSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o llamafile.zip https://jpskill.com/download/15078.zip && unzip -o llamafile.zip && rm llamafile.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/15078.zip -OutFile "$d\llamafile.zip"; Expand-Archive "$d\llamafile.zip" -DestinationPath $d -Force; ri "$d\llamafile.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
llamafile.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
llamafileフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
llamafile — シングルファイル LLM 実行可能ファイル
概要
Llamafile は、インストールなしで任意の OS (Linux, macOS, Windows, FreeBSD) 上で実行できる単一の実行可能ファイルに LLM をパッケージ化するツールです。開発者がポータブルな AI アプリケーションを作成したり、モデルをオフラインで実行したり、組み込みの Web UI および OpenAI 互換 API を備えた自己完結型のバイナリとして LLM を配布したりするのに役立ちます。
手順
llamafile の実行
# 事前構築済みの llamafile (モデル + ランタイムが 1 つのファイルに) をダウンロード
wget https://huggingface.co/Mozilla/Meta-Llama-3.1-8B-Instruct-llamafile/resolve/main/Meta-Llama-3.1-8B-Instruct.Q5_K_M.llamafile
# 実行可能にして実行
chmod +x Meta-Llama-3.1-8B-Instruct.Q5_K_M.llamafile
./Meta-Llama-3.1-8B-Instruct.Q5_K_M.llamafile
# Web UI が http://localhost:8080 で開きます
# OpenAI 互換 API も http://localhost:8080/v1 で提供されます
# 特定の設定で実行
./Meta-Llama-3.1-8B-Instruct.Q5_K_M.llamafile \
--host 0.0.0.0 \
--port 8080 \
--ctx-size 8192 \
--threads 8 \
--gpu auto # 利用可能な場合は GPU を使用 (CUDA, Metal, ROCm)
カスタム llamafile の作成
# 任意の GGUF モデルから llamafile を構築
# 1. llamafile ランタイムをダウンロード
wget https://github.com/Mozilla-Ocho/llamafile/releases/latest/download/llamafile
chmod +x llamafile
# 2. HuggingFace から GGUF モデルをダウンロード
wget https://huggingface.co/TheBloke/Mistral-7B-Instruct-v0.2-GGUF/resolve/main/mistral-7b-instruct-v0.2.Q5_K_M.gguf
# 3. llamafile を作成 (モデル + ランタイムをパッケージ化)
./llamafile \
--model mistral-7b-instruct-v0.2.Q5_K_M.gguf \
--create my-assistant.llamafile
# 4. 結果のファイルはどこでも実行可能 — 依存関係なし
./my-assistant.llamafile --port 8080
# カスタムシステムプロンプトを組み込む場合
./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 互換 API
// src/local-llm.ts — 任意の OpenAI 互換 SDK で llamafile を使用
import OpenAI from "openai";
// ローカルの llamafile サーバーを指す
const llm = new OpenAI({
apiKey: "not-needed", // llamafile は認証を必要としません
baseURL: "http://localhost:8080/v1",
});
async function chat(prompt: string) {
const response = await llm.chat.completions.create({
model: "local", // 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;
}
// ストリーミングも動作します
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 ?? "");
}
}
// 埋め込み
async function embed(text: string) {
const response = await llm.embeddings.create({
model: "local",
input: text,
});
return response.data[0].embedding;
}
CLI の使用 (サーバーなし)
# ワンショット補完 (サーバーなし、stdin → stdout のみ)
echo "Explain Docker in one sentence:" | ./llamafile --cli
# システムプロンプトを使用する場合
./llamafile --cli \
--system "You are a Linux expert. Answer in one line." \
--prompt "How do I find files larger than 100MB?"
# ファイルの処理
cat error_log.txt | ./llamafile --cli \
--system "Analyze this error log. Identify the root cause."
# スクリプトを使用したバッチ処理
for file in reports/*.txt; do
echo "=== $file ==="
cat "$file" | ./llamafile --cli \
--system "Summarize this report in 3 bullet points." \
--temp 0
done
アプリケーションへの埋め込み
# アプリケーションからサブプロセスとして llamafile を実行
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,
)
# サーバーの準備ができるまで待機
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()
# 使用例
server = LlamafileServer("./my-model.llamafile", port=8081)
server.start()
answer = server.chat("What is the capital of France?")
server.stop()
インストール
# インストールは不要 — llamafile がインストールそのものです
# ダウンロードして実行するだけです。
# llamafile を作成する場合:
wget https://github.com/Mozilla-Ocho/llamafile/releases/latest/download/llamafile
chmod +x llamafile
例
例 1: 既存のアプリケーションへの Llamafile の統合
ユーザーのリクエスト:
AI チャット機能のために、Llamafile を Next.js アプリに追加してください。ストリーミング応答が必要です。
エージェントは SDK をインストールし、API ルートを作成します。
(原文はここで切り詰められています)
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
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
# 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
# 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
// 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)
# 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
# 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
# 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
- Single file = single deployment — Distribute your AI as one file; users double-click to run, no Python/Docker/CUDA setup
- GPU auto-detection — llamafile automatically uses GPU when available (CUDA, Metal, ROCm); falls back to CPU
- Quantized models for speed — Use Q5_K_M or Q4_K_M quantizations; they're 3-5x smaller with minimal quality loss
- OpenAI API compatibility — Use the same code for local llamafile and cloud APIs; swap by changing the base URL
- CLI mode for scripts — Use
--clifor batch processing; pipe text in, get completions out, no server needed - Air-gapped environments — llamafile runs completely offline; ideal for sensitive data or environments without internet
- Context size matters — Set
--ctx-sizebased on your use case; larger contexts need more RAM - One model per llamafile — Each llamafile contains one model; run multiple on different ports for model routing