Comprehensive guide for writing shell scripts with Google zx — a tool for writing better scripts using JavaScript/TypeScript.

MITAuto-check: notesDevelopment

Install Zx

skills CLI
$ npx skills add LeoYeAI/openclaw-master-skills --skill zx -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install LeoYeAI/openclaw-master-skills zx --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/LeoYeAI/openclaw-master-skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/zx .claude/skills/zx && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
zx
GitHub stars
2.2k
Token cost
~2.2k tokens
SKILL.md length
489 words
Files
7 (incl. references)
Skills in repo
1,235
Repo updated
First seen
Licence
MIT

At a glance

Comprehensive guide for writing shell scripts with Google zx — a tool for writing better scripts using JavaScript/TypeScript.

  • Refactoring zx scripts (.mjs
  • SKILL.md covers Overview, Triggers, Quick Start and Core Concepts, plus 5 more sections
  • Calls npm, npx and node; reaches github.com
  • .ts files using zx)

What it does

Zx is an agent skill from LeoYeAI/openclaw-master-skills. Comprehensive guide for writing shell scripts with Google zx — a tool for writing better scripts using JavaScript/TypeScript. Use when writing, debugging, or refactoring zx scripts (.mjs, .js, .ts files using zx), executing shell commands from JavaScript, working with ProcessPromise/ProcessOutput APIs, piping streams, configuring zx options, or using zx CLI. Do NOT use for general Node.js questions unrelated to shell scripting.

Its SKILL.md is about 2.2k tokens, which your agent loads only when the skill is triggered. The skill folder holds 8 other files, including reference files (for example `.clawhub/origin.json`, `_meta.json` and `references/api.md`).

It sits in Development, covering Shell scripting. It works with JavaScript, Bash, TypeScript and Node.js. The repository describes itself as: 🧠 Curated collection of 1209+ best OpenClaw skills — weekly updated by MyClaw.ai. The licence is MIT.

When your agent uses it

  • Refactoring zx scripts (.mjs
  • .ts files using zx)
  • Executing shell commands from JavaScript
  • Working with ProcessPromise/ProcessOutput APIs

Example prompts

  • “/zx”

Requirements

  • Node.js

What it can do on your machine

Read from SKILL.md and the folder at commit e5199b5. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • npm
    • npx
    • node

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    Hosts in commands or code, which the agent is likely to contact:

    • github.com

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Zx loads about 2.2k tokens when it runs, and up to ~8.6k if it reads all its reference files. Until then it costs about 109 tokens; SKILL.md has 489 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~109
When it runs · the whole SKILL.md, loaded when a task matches
~2.2k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~8.6k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check: notes

The automated check noted patterns worth knowing about, such as sudo or a known installer.

  • NoteMentions a .env fileSKILL.md:134
    | Load .env file | `` dotenv.config('.env') `` |
  • NoteMentions a .env fileSKILL.md:250
    | `dotenv` | .env file loading | `dotenv.config('.env')` |

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from LeoYeAI/openclaw-master-skills at commit e5199b5, republished under its MIT licence (© LeoYeAI). 489 words, ~2,222 tokens.

Download SKILL.mdSave it as .claude/skills/zx/SKILL.md (or your agent's skills folder). This skill also uses 6 other files; get the full folder from GitHub.
name
zx
description
Comprehensive guide for writing shell scripts with Google zx — a tool for writing better scripts using JavaScript/TypeScript. Use when writing, debugging, or refactoring zx scripts (.mjs, .js, .ts files using zx), executing shell commands from JavaScript, working with ProcessPromise/ProcessOutput APIs, piping streams, configuring zx options, or using zx CLI. Do NOT use for general Node.js questions unrelated to shell scripting.

Zx — Write Better Shell Scripts with JavaScript

Overview

zx is Google's tool for writing shell scripts in JavaScript/TypeScript. It wraps child_process, auto-escapes arguments, and provides sensible defaults — giving you the power of the JavaScript ecosystem in your scripts.

js
#!/usr/bin/env zx

await $`cat package.json | grep name`

const branch = await $`git branch --show-current`
await $`dep deploy --branch=${branch}`

const name = 'foo & bar'
await $`mkdir /tmp/${name}`  // No quotes needed — auto-escaped

Bash is great for simple tasks, but when scripts grow complex, a full programming language helps. zx adds helpful wrappers around child_process, escapes arguments, and gives sensible defaults. Think: bash + JavaScript in one script.

Triggers

Also triggers when users ask about running shell commands in JavaScript, converting bash scripts to zx, executing remote scripts, Markdown scripts, or TypeScript shell scripts.

Quick Start

bash
npm install zx

Write scripts as .mjs files (supports top-level await). Add #!/usr/bin/env zx shebang or run via CLI:

bash
zx ./script.mjs           # Direct execution
npx zx ./script.mjs       # Via npx
node --import zx/globals  # As Node.js loader

All functions ($, cd, fetch, etc.) are globally available in zx scripts without imports. For explicit imports (better VS Code autocomplete):

js
import 'zx/globals'

Core Concepts

$`command` — Execute Shell Commands

The tagged template literal is the heart of zx. Everything in ${...} is auto-escaped and quoted.

js
// Async (standard) — returns ProcessPromise
const output = await $`ls -la`

// Sync variant — returns ProcessOutput directly
const dir = $.sync`pwd`

// Arrays are flattened
const flags = ['--oneline', '--decorate', '--color']
await $`git log ${flags}`

// Non-zero exit codes throw ProcessOutput
try {
  await $`exit 1`
} catch (p) {
  console.log(`Exit: ${p.exitCode}, Error: ${p.stderr}`)
}
Preset Configuration with $({...})

Create custom $ instances with preset options — chainable and composable:

js
const $$ = $({ verbose: false, env: { NODE_ENV: 'production' } })
const pwd = $$.sync`pwd`

// Presets are chainable
const $1 = $({ nothrow: true })
const $2 = $1({ sync: true })  // Both nothrow + sync applied
ProcessPromise & ProcessOutput
$`cmd`              ProcessPromise (extends Promise)
  ├── .pipe()       Stream piping
  ├── .kill()       Terminate process
  ├── .text()       Output as string
  ├── .json()       Output as parsed JSON
  ├── .lines()      Output split by lines
  ├── .nothrow()    Suppress errors for this command
  ├── .quiet()      Suppress output for this command
  ├── .timeout()    Auto-kill after duration
  ├── .stdio()      Configure I/O
  ├── .exitCode     Promise<exit code>
  ├── .stdout       Readable stream
  ├── .stderr       Readable stream
  ├── .stdin        Writable stream
  ├── .pid / .cmd   Process metadata
  └── await → ProcessOutput
                ├── .stdout    string
                ├── .stderr    string
                ├── .exitCode  number
                ├── .signal    string|null
                ├── .text() / .json() / .lines() / .buffer() / .blob()
                └── .ok        boolean (when nothrow)

Decision Tree

When writing zx scripts, use this decision tree:

GoalApproach
Run a commandawait $`cmd`
Run synchronously$.sync`cmd`
Pipe output.pipe($`next`) / .pipe('file.txt')
Handle errors gracefully$({nothrow: true}) / .nothrow()
Set timeout$({timeout: '30s'}) / .timeout('30s')
Parse JSON output(await $`cmd`).json()
Real-time streamingfor await (const line of $`cmd`)
Retry on failureretry(5, () => $`cmd`)
User promptquestion('Name: ')
Progress indicatorawait spinner('Working...', () => $`cmd`)
Change directorycd('/path') or within(() => { $.cwd = '/tmp' })
Temp files/dirstmpfile() / tmpdir()
Parse CLI argsargv.flag or minimist(process.argv.slice(2))
Load .env filedotenv.config('.env')

Writing Effective zx Scripts

Parallel Execution
js
const results = await Promise.all([
  $`sleep 1; echo 1`,
  $`sleep 2; echo 2`,
  $`sleep 3; echo 3`,
])
Error Handling with nothrow
js
$.nothrow = true

const repos = ['zx', 'webpod']
const clones = repos.map(n => $`git clone https://github.com/google/${n}`)

const results = await Promise.all(clones)
const errors = results.filter(o => !o.ok).map(o => o.stderr.trim())
console.log('Errors:', errors.join('\n'))
Stream Piping
js
// Chain commands like bash pipes
const greeting = await $`printf "hello"`
  .pipe($`awk '{printf $1", world!"}'`)
  .pipe($`tr '[a-z]' '[A-Z]'`)

// Pipe to file
await $`echo "Hello!"`.pipe('/tmp/output.txt')

// Real-time output to terminal
await $`echo 1; sleep 1; echo 2; sleep 1; echo 3`.pipe(process.stdout)
Stream Splitting & Merging
js
// Split one source to multiple consumers
const p = $`some-command`
const [o1, o2] = await Promise.all([
  p.pipe`log`,
  p.pipe`extract`,
])

// Merge multiple sources
const $h = $({ halt: true })
const p1 = $`echo foo`
const p2 = $h`echo a && sleep 0.1 && echo b`
const p3 = $h`echo c && sleep 0.1 && echo d`
const cat = $h`cat`
p1.pipe(cat); p2.pipe(cat); p3.pipe(cat)
await cat.run()
Output Formatters
js
const p = $`echo '{"foo":"bar"}\nline2'`

await p.json()    // { foo: 'bar' }
await p.lines()   // ['{"foo":"bar"}', 'line2']
await p.text()    // '{"foo":"bar"}\nline2\n'
Async Iteration
js
for await (const line of $`git log --oneline --max-count=5`) {
  console.log(line)
}

Shell Configuration

zx defaults to bash. Switch shells as needed:

js
import { useBash, usePowerShell, usePwsh } from 'zx'

usePowerShell()  // PowerShell.exe
usePwsh()        // PowerShell v7+
useBash()        // Back to bash

// Manual override
$.shell = '/bin/zsh'

On Windows, consider using WSL or Git Bash for bash support, or switch to PowerShell via usePowerShell().

Show full SKILL.md (190 more words)Show less

Built-in Helpers Summary

HelperPurposeExample
cd()Change directorycd('/tmp')
fetch()HTTP requests, supports .pipe()fetch('https://api.example.com')
question()Interactive user inputquestion('Name: ')
sleep()Delay executionawait sleep(1000)
echo()Print to stdoutecho`Status: ${p}`
stdin()Read stdinJSON.parse(await stdin())
within()Isolated async config contextwithin(() => { $.cwd = '/tmp' })
retry()Retry with delay/backoffretry(5, () => $curl url)
spinner()CLI progress indicatorawait spinner(() => $long-cmd)
glob()File glob matching (globby)glob('**/*.js')
which()Find executable pathawait which('node')
psCross-platform process listps.lookup({ command: 'node' })
tmpdir()Temp directorytmpdir('sub')
tmpfile()Temp filetmpfile('f.txt', 'content')
argvParsed CLI argumentsargv.verbose
dotenv.env file loadingdotenv.config('.env')

Exposed npm packages: chalk (colors), fs (fs-extra), os, path, YAML (yaml), minimist.

Resources

  • references/api.md — Full API reference: $ options, cd(), fetch(), question(), sleep(), echo(), stdin(), within(), retry(), spinner(), glob(), which(), ps, kill(), tmpdir(), tmpfile(), minimist, argv, chalk, fs, os, path, YAML, dotenv, quote(), useBash(), usePowerShell(), usePwsh()
  • references/configuration.md — All $.options: shell, prefix, postfix, quote, verbose, quiet, env, cwd, timeout, nothrow, detached, preferLocal, spawn, kill, log, input, signal, stdio, halt, delimiter, defaults
  • references/cli.md — CLI usage: flags, env vars, Markdown scripts, remote scripts, stdin execution, REPL mode
  • references/process.md — ProcessPromise/ProcessOutput lifecycle, piping, killing, aborting, output formatters, stream handling

© LeoYeAI, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 6 other files (references) in skills/zx of LeoYeAI/openclaw-master-skills.

  • SKILL.md
  • .clawhub/origin.json
  • _meta.json
  • references/api.md
  • references/cli.md
  • references/configuration.md
  • references/process.md

Open the folder on GitHubat commit e5199b5

Compare with similar skills

Zx next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Zx compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Zx this skillLeoYeAI/openclaw-master-skills2.2k—~2.2kAutomated safety check: NotesMIT
Swpm Code Reviewdeinsoftware/swpm125—~1.1kAutomated safety check: PassMIT
Generate Release Notesteambit/bit18k—~2.2kAutomated safety check: PassCustom licence
ast-grep Codemod Referencewarp-drive-data/warp-drive3.2k—~2.6kAutomated safety check: PassMIT
Coding Standardskurealnum/dotfiles29017 repos~2.9kAutomated safety check: PassNone
Bit CLIteambit/bit18k—~2kAutomated safety check: WarnCustom licence

Similar skills

  • Swpm Code Review

    deinsoftware/swpm

    Automated code review bash script for SWPM. An agent skill from deinsoftware/swpm.

    125 GitHub stars~1.1k tokensUpdated 4 mo ago
    DevelopmentAuto-check passed
  • Generate comprehensive release notes for Bit from git commits and pull requests.

    18k GitHub stars~2.2k tokensUpdated today
    DevelopmentAuto-check passed
  • ast-grep Codemod Reference

    warp-drive-data/warp-drive

    Reference for writing and debugging TypeScript and JavaScript codemods with @ast-grep/napi: parsing, node queries, meta-variables, rule objects and editing.

    3.2k GitHub stars~2.6k tokensUpdated yesterday
    DevelopmentAuto-check passed
  • Coding Standards

    kurealnum/dotfiles

    Universal coding standards, best practices, and patterns for TypeScript, JavaScript, React, and Node.js development.

    290 GitHub starsUsed in 17 repos~2.9k tokens
    DevelopmentAuto-check passed
  • Bit CLI

    teambit/bit

    MUST consult before running ANY bit command. An agent skill from teambit/bit.

    18k GitHub stars~2k tokensUpdated today
    DevelopmentAuto-check: warnings
  • Minimum Viable

    ferrumclaudepilgrim/claude-code-android

    Before building anything, justify the tool choice and complexity level.

    268 GitHub stars~538 tokensUpdated 2 mo ago
    DevelopmentAuto-check: notes

More from LeoYeAI/openclaw-master-skills

All 1,235 skills in this repo
  • DevOps Pipeline Management

    LeoYeAI/openclaw-master-skills

    Manages pipelines on a DevOps quality and efficiency platform through its OpenAPI: list workspaces and templates, create, update, run and cancel pipelines, and read run records.

    2.2k GitHub stars~4.2k tokensUpdated 2 mo ago
    Auto-check: notes
  • Feishu Document Collaboration

    LeoYeAI/openclaw-master-skills

    Patches OpenClaw's Feishu extension so an edited document triggers an isolated agent session that reads the doc and replies inline, turning it into a live chat space.

    2.2k GitHub stars~2k tokensUpdated 2 mo ago
    Auto-check passed
  • Files Memory System

    LeoYeAI/openclaw-master-skills

    Multi-context memory management system for OpenClaw agents with group-isolated storage, global shared memory, workspace organization, and group-specific skills isolation.

    2.2k GitHub stars~3.8k tokensUpdated 2 mo ago
    Auto-check passed
  • GEO-Claw AI Visibility Agent

    LeoYeAI/openclaw-master-skills

    Runs a brand's AI-search visibility work end to end: diagnosing how AI platforms represent it, repositioning it, producing AI-optimized content and monitoring ongoing mentions.

    2.2k GitHub stars~4.7k tokensUpdated 2 mo ago
    Auto-check passed
  • Google Workspace CLI

    LeoYeAI/openclaw-master-skills

    Installs and authenticates the gws CLI, then automates Gmail, Drive, Sheets, Calendar, Docs, Chat and Tasks with ready-made recipes, persona bundles and security audits.

    2.2k GitHub stars~2.6k tokensUpdated 2 mo ago
    Auto-check: notes
  • HealthFit Health Advisors

    LeoYeAI/openclaw-master-skills

    Runs four advisor roles, a fitness coach, nutritionist, data analyst and TCM practitioner, to build a health profile and track workouts, diet and wellness over time.

    2.2k GitHub stars~4.4k tokensUpdated 2 mo ago
    Auto-check passed

Categories

Questions about Zx

What does Zx do?

Comprehensive guide for writing shell scripts with Google zx — a tool for writing better scripts using JavaScript/TypeScript. Zx is an agent skill from LeoYeAI/openclaw-master-skills. Comprehensive guide for writing shell scripts with Google zx — a tool for writing better scripts using JavaScript/TypeScript.

When should I use Zx?

Zx fits situations like: refactoring zx scripts (.mjs; .ts files using zx); executing shell commands from JavaScript; working with ProcessPromise/ProcessOutput APIs.

How do I install Zx in Claude Code?

Run `npx skills add LeoYeAI/openclaw-master-skills --skill zx -a claude-code`. Or copy the skill folder (skills/zx in LeoYeAI/openclaw-master-skills) into .claude/skills/zx in your project. Claude Code loads it when a task matches its description.

How do I install Zx in Codex?

Run `npx skills add LeoYeAI/openclaw-master-skills --skill zx -a codex`. Or copy the skill folder (skills/zx in LeoYeAI/openclaw-master-skills) into .agents/skills/zx in your project. Codex loads it when a task matches its description.

Can I use Zx in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add LeoYeAI/openclaw-master-skills --skill zx -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/zx, .gemini/skills/zx, .github/skills/zx and .opencode/skills/zx in your project.

What does Zx need to run?

Going by SKILL.md and its folder, Zx needs the command-line tools its instructions call (npm, npx and node). Our summary lists: Node.js.

Does Zx access the network?

SKILL.md names 1 domain. In commands or code: github.com; the agent is likely to contact it when it follows the instructions. This is read from the text; nothing was executed.

Is Zx safe to install?

Our automated static check of SKILL.md found notes only (mentions a .env file), nothing it rates as a warning. It is not a guarantee. Review the folder before installing.

What licence does Zx use?

Zx is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Zx use?

About 2.2k tokens (SKILL.md is roughly 8.9k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 6.4k tokens, read only when the agent opens those files.

What are the alternatives to Zx?

Skills that share tags, products or a category with Zx: Swpm Code Review (deinsoftware/swpm, 125 stars), Generate Release Notes (teambit/bit, 18k stars), ast-grep Codemod Reference (warp-drive-data/warp-drive, 3.2k stars) and Coding Standards (kurealnum/dotfiles, 290 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Zx?

LeoYeAI (a GitHub user) maintains it in LeoYeAI/openclaw-master-skills, which has 2,160 GitHub stars. The repository holds 1,235 skills in this directory. The repository was last updated on July 20, 2026.

Source: LeoYeAI/openclaw-master-skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.