OpenClawCheatsheet

OpenClaw Skills Development Cheatsheet📋

Everything you need to build, test, and publish OpenClaw skills in one place. Skills are reusable agent capabilities packaged as a SKILL.md (instructions), skill.json (manifest), and optional tools.json (custom tool definitions). This cheatsheet covers the full lifecycle: project scaffolding, parameter schemas, input validation, skill composition, local testing, debugging, and ClawHub publishing. Keep this open while you build.

Quick Reference

NameSyntaxDescription
Skill anatomySKILL.md + skill.json + tools.jsonEvery skill is a directory with SKILL.md (agent instructions), skill.json (manifest with name, version, requiredTools), and optional tools.json (custom tool definitions).
Create a skillopenclaw skills create <name>Scaffold a new skill directory with template SKILL.md, skill.json, tools.json, and README.md.
Skill parametersparameters: { type: "object", properties: {...} }Define tool input schemas using JSON Schema in tools.json. OpenClaw validates parameters before execution.
Input validation"required": ["field1", "field2"]Mark required fields in the JSON Schema. OpenClaw rejects calls with missing required parameters and returns clear error messages.
Skill compositionskills: ["@org/skill-a", "@org/skill-b"]Install multiple focused skills on a single agent. Each skill's SKILL.md is injected into the system prompt independently.
Test skills locallyopenclaw skills test ./<skill-dir> --agent <id>Run the skill against a real agent in a sandboxed session with test prompts.
Publish to ClawHubopenclaw skills publish ./<skill-dir>Upload skill to ClawHub after authentication. Requires valid manifest and passing validation.
Skill versioning"version": "1.2.0" (semver)Follow semver in skill.json. Patch for fixes, minor for new instructions, major for breaking tool changes.
Error handling"onError": { "retry": false, "fallback": "message" }Define error behavior in tool definitions. Control retry logic and fallback messages for failed tool executions.
Skill hooks"hooks": { "onInstall": "...", "onActivate": "..." }Lifecycle hooks in skill.json that run on install, activation, and deactivation. Use for setup validation and cleanup.

Skill Basics

Create a skill project

openclaw skills create <name>

The CLI scaffolds a complete skill directory with template files. Start by editing skill.json with your metadata, then write the SKILL.md instructions.

bash

Tips

  • Use descriptive, kebab-case names: 'api-health-check' not 'healthcheck'
  • The template SKILL.md includes all recommended sections pre-filled with placeholders

skill.json manifest

{ name, version, description, author, requiredTools, tags, config, hooks }

The manifest declares metadata, required tools, tags for ClawHub discovery, optional config defaults, and lifecycle hooks. OpenClaw reads this when installing.

json

Tips

  • List ALL built-in tools your SKILL.md references in requiredTools
  • Tags improve discoverability on ClawHub — use 3-5 relevant keywords
  • Config values are accessible in tool command templates via {{config.key}}

SKILL.md handler structure

Description → When to Use → Instructions → Safety Rules → Common Patterns

SKILL.md is the heart of the skill. The agent reads and follows these instructions literally. Every section serves a specific purpose for the agent's decision-making.

markdown

Tips

  • Keep SKILL.md under 1,000 tokens to preserve context window space
  • The 'When to Use' section is critical — without it, the agent cannot decide when to activate the skill
  • Number your instructions for clear step-by-step execution

Parameter schemas in tools.json

{ tools: [{ name, description, executor, command, parameters }] }

Each tool definition includes a name, description (the model reads this), executor type, command template with {{placeholders}}, and a JSON Schema for parameters.

json

Tips

  • Use the 'pattern' keyword for string validation (e.g., URL format)
  • Set 'default' values so the agent does not have to provide every parameter
  • The 'description' field on each property helps the model generate correct values

Input & Output

Parameter validation with JSON Schema

properties.{field}.{type, enum, pattern, minimum, maximum}

Use JSON Schema features for strict parameter validation: enums for fixed choices, min/max for ranges, arrays for lists, and nested objects for structured config.

json

Tips

  • Use 'enum' to restrict values to a known set — the agent will only pick from the list
  • Nested objects let you group related config without cluttering the top level
  • OpenClaw validates before execution — invalid parameters never reach the command

Typed parameters with executor functions

executor: "function", handler: "./handlers/deploy.ts"

Function executors let you write TypeScript handlers with full type safety. The handler receives validated parameters and a context object with skill config and agent metadata.

typescript

Tips

  • Use the @openclaw/sdk package for type definitions
  • The context object includes config values from skill.json, agent ID, and session info
  • Return structured objects — the agent formats them for the user

Response formatting

return { success, message, data }

Return a structured response with success flag, human-readable message, and optional data object. The agent uses 'message' for its reply and 'data' for follow-up reasoning.

typescript

Tips

  • Always include a 'message' field — the agent uses it directly in conversation
  • Put machine-readable details in 'data' for the agent to reference
  • Set 'success: false' to signal errors — the agent will follow SKILL.md error handling rules

Streaming responses

return { stream: true, generator: async function* () {...} }

For long-running operations like log tailing, return a streaming response. The agent receives chunks incrementally and can relay them to the user in real time.

typescript

Tips

  • Use streaming for operations that take more than a few seconds
  • Always yield a final { done: true } chunk to signal completion
  • The agent can interrupt a stream if the user sends a new message

Advanced Skills

Skill composition — multiple skills on one agent

skills: ["@org/skill-a", "@org/skill-b"]

Install multiple focused skills on a single agent. Each skill's SKILL.md is injected independently. The agent decides which skill to activate based on the 'When to Use' section.

json

Tips

  • Keep total skill tokens under 2,000 to leave room for conversation context
  • Avoid overlapping 'When to Use' triggers between skills
  • Use `openclaw agent prompt --stats` to monitor token budgets

Calling other skills from within a skill

context.invokeSkill(skillName, params)

Skills can invoke tools from other installed skills via context.invokeSkill(). This enables orchestration patterns where a higher-level skill coordinates multiple capabilities.

typescript

Tips

  • The invoked skill must be installed on the same agent
  • invokeSkill returns the same { success, message, data } structure
  • Use this for orchestration — keep individual skills focused

Context access — agent info, session, and config

context.{agent, session, config, workspace}

The context object provides access to agent metadata, session info, skill config values, and the workspace path. Use it to make skills context-aware.

typescript

Tips

  • Use context.session.channel to adapt behavior per platform (Discord vs Telegram)
  • context.workspace is the agent's isolated directory — read/write files there
  • Config values come from the 'config' field in skill.json

State management across invocations

context.state.get(key) / context.state.set(key, value)

Use context.state to persist data across tool invocations within a session. State is scoped to the agent and session, and survives across multiple messages.

typescript

Tips

  • State is session-scoped — it resets when the session ends
  • Use state for rate limiting, caching, and tracking multi-step workflows
  • State values are serialized as JSON — store plain objects and primitives

External API integration

fetch() in function executor handlers

Function executor handlers can call external APIs using fetch(). Read API tokens from environment variables — never hardcode secrets.

typescript

Tips

  • Always check for missing environment variables and return clear error messages
  • Use proper error handling for API failures (status codes, timeouts, network errors)
  • Return structured data so the agent can reason about the API response

Testing & Debugging

Unit testing skill handlers

import { handler } from './handlers/my-tool'

Unit test skill handlers by importing them directly and providing a mock context. Mock fetch() for external API calls and context.state for state management.

typescript

Tips

  • Mock context.invokeSkill to test skill composition without running real skills
  • Test both success and failure paths — the agent relies on correct error signals
  • Use vitest or jest — the handler is just a regular async function

Local testing with the CLI

openclaw skills test ./<dir> --agent <id> [--prompts ...]

The CLI provides sandboxed testing, validation, and prompt preview. Always validate and test locally before publishing to ClawHub.

bash

Tips

  • Include at least 3-5 prompts covering happy path, edge cases, and error scenarios
  • Use --with-skill to verify the skill fits within the agent's token budget
  • Validation catches common issues: missing requiredTools, invalid schemas, missing SKILL.md sections

Debug logging in handlers

context.log.debug() / context.log.info() / context.log.error()

Use context.log for structured logging in skill handlers. Debug logs require OPENCLAW_LOG_LEVEL=debug. Error logs are always visible in `openclaw logs`.

typescript

Tips

  • Include relevant context (params, IDs) in log messages for easier debugging
  • Use context.log.debug for verbose tracing, context.log.info for key events, context.log.error for failures
  • View logs with: openclaw logs --filter skill --last 1h

Mock contexts for integration testing

createMockContext() from @openclaw/sdk/testing

The @openclaw/sdk/testing module provides createMockContext() for integration tests. It includes working state management, log capture, and configurable skill config.

typescript

Tips

  • Use createMockContext for integration tests that span multiple handlers
  • Access context.logs to verify logging behavior
  • Pre-seed state with initialState to test flows that depend on previous invocations

Publishing

ClawHub publishing workflow

openclaw auth login → validate → publish

The full publishing workflow: authenticate, validate, publish, verify. ClawHub reviews new skills for quality and security before they appear in search.

bash

Tips

  • Always validate before publishing — failed validation blocks the publish
  • First-time skills may take a few minutes to appear in search after review
  • Your ClawHub username becomes the skill namespace: @yourname/skill-name

Versioning strategy

"version": "MAJOR.MINOR.PATCH" in skill.json

Follow semver strictly. Existing installations are NOT auto-updated — users must explicitly update. Pin versions in production.

typescript

Tips

  • Bump version in skill.json BEFORE running publish
  • Document breaking changes in README.md so users know what to expect
  • Use @yourname/skill@^1.0.0 for compatible range installs

Documentation for ClawHub

README.md in skill directory

A good README helps users understand what your skill does, how to install it, what tools it requires, and how to use it. This is what appears on your ClawHub skill page.

markdown

Tips

  • Include real usage examples as conversation prompts the user would type
  • List required tools so users know prerequisites before installing
  • Maintain a changelog so users can evaluate if an update is worth pulling

Skill discovery and metadata

tags, description, and README in skill.json

Good metadata makes your skill discoverable on ClawHub. Use specific names, clear descriptions, and relevant tags.

typescript

Tips

  • Search ClawHub for similar skills before publishing to avoid name conflicts
  • Tags are the primary search mechanism — choose terms users would actually search for
  • A clear description in skill.json appears in search results and helps users decide to install

Common Patterns

Basic skill with parameter validation

typescript

A complete skill with validated parameters. The JSON Schema enforces URL format with a regex pattern, restricts custom aliases to alphanumeric characters, and marks 'url' as required. OpenClaw validates all parameters before the handler runs.

Skill that calls an external API

typescript

A skill handler that calls an external API with proper error handling. Checks for the API key upfront, handles specific HTTP errors (404 for city not found), catches network errors, uses structured logging, and returns both a human-readable message and structured data.

Composed skill (skill calling other skills)

typescript

A pipeline skill that orchestrates other skills via context.invokeSkill(). It deploys using the docker-deploy skill, verifies health using the health-check skill, and automatically rolls back if the health check fails. Dependencies are declared in skill.json so OpenClaw ensures all required skills are installed.

Watch Out For

Missing 'When to Use' section in SKILL.md causes the agent to activate the skill at inappropriate times or ignore it entirely

Always include a 'When to Use' section with explicit trigger conditions. List specific phrases or scenarios: 'Use this skill when the user asks to deploy, check deployment status, or rollback.' Without it, the agent cannot decide when to activate your skill.

Forgetting to list required tools in skill.json leads to silent failures when the skill is installed on an agent without those tools

Audit every tool reference in your SKILL.md instructions and tools.json. Add them all to the 'requiredTools' array in skill.json. The install command warns about missing tools — but only if you declare them.

SKILL.md exceeding 1,000 tokens consumes too much context window, leaving less room for conversation and causing degraded agent performance

Check token usage with `openclaw skills validate`. If over 1,000 tokens, split into multiple focused skills. Remove redundant instructions and keep Common Patterns concise. Monitor with `openclaw agent prompt --stats`.

Publishing a skill without bumping the version in skill.json causes the publish to fail or silently overwrite the existing version

Always update the 'version' field in skill.json before running `openclaw skills publish`. Follow semver: patch for fixes, minor for new features, major for breaking changes. ClawHub rejects duplicate version numbers.

Hardcoding API keys or secrets in handler files or SKILL.md instead of reading from environment variables exposes credentials on ClawHub

Always read secrets from process.env in handler code. Document required environment variables in your README.md. Never include real tokens in SKILL.md, tools.json, or handler files. ClawHub scans for leaked secrets and blocks the publish.

Dive Deeper