Skip to content
Back to skills

Write Zsh Scripts

ASecurity

Apply zsh style conventions when creating, editing, or reviewing zsh scripts, .zshrc and other startup files, plugins, and completions, and check them with syntax, compilation, lint and formatting tools. Use for "check zsh" or "lint zsh".

  • 3 stars
  • 0 votes
  • 0 copies
  • 7 views
  • Added October 2, 2026
developmentshellbashexpressapi

Works with

  • api

Security analysis

A100/100

Pro scans all 4 files and shows the line behind each finding

Scanned November 10, 2026

npx -y skills add cboone/agent-harness-plugins --skill write-zsh-scripts --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Write Zsh Scripts?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Write Zsh Scripts
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/cboone-write-zsh-scripts/badge)](https://www.skillsdirectory.com/skills/cboone-write-zsh-scripts)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: write-zsh-scripts
description: >-
  Apply zsh style conventions when creating, editing, or reviewing zsh scripts,
  .zshrc and other startup files, plugins, and completions, and check them with
  syntax, compilation, lint and formatting tools. Use for "check zsh" or "lint zsh".
---

# Zsh Style Guide

Apply the zsh conventions from `./references/ZSH.md` when creating or editing zsh scripts, configurations, and plugins.

## Key Conventions

Read `./references/ZSH.md` for the complete guide. Summary:

### Script Structure

- Shebang: `#!/usr/bin/env zsh`
- Strict mode: `setopt ERR_EXIT NO_UNSET PIPE_FAIL`
- Main function called at end: `main "${@}"`

### Naming

- Functions: `snake_case`
- Local variables: `lower_case`
- Constants: `ALL_CAPS` with `readonly`
- Private/internal: `_underscore_prefix`

### Syntax

- Variable expansion: `${var}` not `$var`
- Command substitution: `$(...)` not backticks
- Tests: `[[ ]]` not `[ ]`
- Function syntax: `function name() { }` with both keyword and parentheses
- Arithmetic: `(( ))` for statements, `$(( ))` for expressions

### Quoting

- Always quote variable expansions: `"${var}"`
- Always quote command substitutions: `"$(cmd)"`
- Use arrays for lists, not word splitting
- Use `"${(@)array}"` to preserve elements in quoted context

### Variables and Scope

- Use `typeset` over `declare`
- Use `local` for all function variables
- Arrays are 1-based (not 0-based like Bash)
- Use `typeset -A` for associative arrays
- Separate `local` declaration from command substitution

### Zsh-Specific Features

- Expansion flags: `${(L)var}`, `${(s:/:)path}`, `${(u)array}`
- Glob qualifiers: `*(.)` for files, `*(/)` for dirs, `*(N)` for null glob
- Extended glob: `setopt EXTENDED_GLOB` for `^`, `~`, `#` patterns
- `always` blocks: `{ ... } always { ... }` for try/finally
- Named traps: `TRAPINT()`, `TRAPZERR()`, `TRAPEXIT()`
- Process substitution: `=(...)` creates a temp file (zsh-only)

## Completions

For zsh completion function conventions, read `./references/completions.md`. Key points:

- Use `_description` for all group descriptions; never pass text directly to `compadd`
- Every `compadd` call must include `"${expl[@]}"`
- Make `curcontext` local in functions using `_arguments -C`
- Register tags before offering matches
- Return zero if matches were added, non-zero otherwise

## Pull Request Review

When reviewing a pull request, apply `./references/review-checklist.md`: the rules of this guide that a reviewer can check in a diff, ranked as Important, Nits and Do not flag. The same checklist is installed into repositories for automated reviewers, so update it whenever a rule here changes.

## Validation

For lint or validation, follow `./references/lint/workflow.md` for file selection, tool checks, scoping and reporting, including startup files such as `.zshrc`.

Whenever possible, validate the script before finishing. Prefer using a project-specific validation script, if available. Common locations include declarations in `package.json`, `Makefile` targets, and scripts stored in `bin/`.

If those aren't present:

- `zsh -n path/to/script` for syntax checking
- `shellcheck --shell=bash` for general linting (limited zsh support, may produce false positives on zsh-specific syntax)

Files in this skill

  • SKILL.md3 KB
  • references/ZSH.md30.6 KB
  • references/completions.md10.8 KB
  • references/review-checklist.md4.2 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.