How to Build Custom OpenClaw Skills (Step-by-Step)
Skills are reusable instruction sets that turn your agent into a specialist. Build a skill once, use it across every session. Here's the complete guide to writing SKILL.md files that actually work.
What Are Skills and When to Build Them
A skill is a directory containing a SKILL.md file (plus optional scripts and references) that teaches your agent how to do a specific type of task. When you ask your agent to perform that task, it reads the skill file and follows the specialized instructions.
Built-in skills cover common tools like GitHub CLI, email (Himalaya), Things 3, weather, and many more. But your setup is unique โ and that's where custom skills shine.
Build a custom skill when:
- โYou have a workflow you repeat more than 3โ4 times
- โThe task involves specific tools, APIs, or formats unique to your setup
- โYou want the same capability available to both your main agent and sub-agents
- โYou want a procedure that's consistently followed without variation
Skill Directory Structure
All custom skills live in ~/.openclaw/workspace/skills/. Each skill gets its own directory:
~/.openclaw/workspace/skills/
โโโ my-skill/
โโโ SKILL.md # Required: instructions for the agent
โโโ references/ # Optional: docs, schemas, examples
โ โโโ api-docs.md
โโโ scripts/ # Optional: helper scripts
โโโ fetch-data.sh
โโโ process.pyYour custom skills directory is separate from built-in skills. This means they survive OpenClaw updates, can be backed up independently, and shared with teammates.
Writing the SKILL.md File
Every SKILL.md needs these sections:
# Skill Name ## Description One paragraph describing what this skill does and WHEN to use it. Use exact phrases users would say when asking for this. ## Prerequisites - Required tools or CLI utilities - Required environment variables or API keys ## Instructions ### Step 1: [First action] [Detailed instructions for step 1] ### Step 2: [Second action] [Detailed instructions for step 2] ## Output Format Describe the expected output format. ## Error Handling What to do when things go wrong.
Writing a Good Description
Bad description
"Web content management"
Too vague โ might trigger on unrelated tasks
Good description
"Publish posts to WordPress, update existing posts, manage drafts via WP-CLI. Use when: creating new posts, scheduling content, or updating existing WordPress pages."
References and Scripts Directories
references/ โ Supporting Docs
Use references/ for supporting documentation your agent might need to read during the task. Reference files are not loaded automatically โ your SKILL.md should explicitly tell the agent to read them when needed:
## Instructions Before starting, read references/api-docs.md for endpoint details. The authentication flow is documented in references/auth.md.
scripts/ โ Executable Helpers
Use scripts/ for executable helper scripts that your skill calls via the exec tool:
### Step 2: Fetch Data Run the fetch script: exec: bash scripts/fetch-data.sh --date today Parse the JSON output and extract the "results" array.
Bash vs Python: When to Use Each
๐ Use Bash for:
- โCalling CLI tools (gh, vercel, heroku, etc.)
- โSimple file operations (copy, move, grep, sed)
- โChaining commands together
- โEnvironment variables and process management
#!/usr/bin/env bash set -e cd "$PROJECT_DIR" git pull origin main npm run build && npm run deploy
๐ Use Python for:
- โComplex data parsing or transformation
- โAPI calls with authentication
- โWorking with JSON/CSV/YAML data
- โTasks requiring logic, conditionals, loops over data
#!/usr/bin/env python3 import sys, json, requests data = json.load(sys.stdin) results = [r for r in data if r['active']] print(json.dumps(results))
Full Example: Stock Price Checker Skill
# Stock Price Checker
## Description
Fetch current stock prices, percentage changes, and basic metrics
for any US-listed stock ticker. Use when asked about stock prices,
market data, portfolio values, or ticker lookups.
## Prerequisites
- ALPHA_VANTAGE_API_KEY environment variable set
- Python 3.8+ installed
- requests library: pip install requests
## Instructions
### Step 1: Identify Tickers
Extract all stock ticker symbols from the user's request.
Normalize to uppercase (e.g., "apple" โ "AAPL").
### Step 2: Fetch Data
For each ticker, run:
exec: python3 scripts/fetch-stock.py --ticker {TICKER}
### Step 3: Format Output
Present results as a clean table:
| Ticker | Price | Change | Change % | Volume |
## Error Handling
If a ticker is not found: note it as "not found" and continue.
If API rate limit hit: wait 15 seconds and retry once.
## Output Format
Markdown table with all requested tickers.
Include timestamp of data fetch.Using the skill-creator Skill
OpenClaw ships with a skill-creator skill that helps you build other skills. Just describe what you want:
"Create a skill for posting to my Ghost blog. It should: authenticate with Ghost Admin API, create draft posts, publish posts, and update existing ones. The API key is stored in ~/.openclaw/.env as GHOST_ADMIN_KEY."
The agent will create the full skill directory, SKILL.md, and any required scripts.
Testing Your Skill
- 1
Describe a simple use case
Ask your agent to use the skill with a basic request. Watch if it correctly identifies and loads your skill.
- 2
Check the skill is being loaded
If the agent isn't using your skill, check the description section โ it needs to match the phrases you're using.
- 3
Test edge cases
Try requests that should trigger error handling. Make sure the agent follows your error instructions, not generic behavior.
- 4
Iterate and refine
Skills improve with use. After each session where the skill ran, review what went well and what was ambiguous. Update SKILL.md accordingly.
Start With the Setup Guide
New to OpenClaw? Get your agent running first, then come back to build custom skills.
Complete Setup Guide