PlugWiki

bash-defensive-patterns Skill (wshobson) for Claude Code

Makes Claude write Bash scripts that fail safely, for anyone building automation, CI scripts or system tools.

Installs
13.8K
on skills.sh
Stars
42.1K
on GitHub
Files
1
besides SKILL.md
Updated
Oct 2026
last repo commit

The skill gives Claude a checklist of defensive Bash habits: strict mode with set -Eeuo pipefail, quoted variables, [[ ]] tests, error traps, input checks, dry-run mode, mktemp with cleanup and idempotent design. The reference file has ten numbered patterns, from safe script directory detection to dry-run support.

It is writing guidance. The skill bundles no scripts, and the example scripts in the reference file are templates Claude can adapt.

Good for

  • Developers writing deployment or CI scripts in Bash
  • Sysadmins building utilities that must handle bad input
  • Anyone reviewing a shell script for unsafe patterns

Install bash-defensive-patterns

Claude Code

  1. 1

    Copy this prompt.

    Install the bash-defensive-patterns skill in Claude Code. Run this command:
    
    npx skills add wshobson/agents --skill bash-defensive-patterns
    
    Then check that it loaded and tell me how to use it.
  2. 2

    Paste it into Claude Code. It shows the change and asks before running it.

Requires Node.js.

The README says the skills routes install a skill without the plugin's agents, commands or hooks. Pick the plugin only if you want the whole shell-scripting set.

Built from the package data we hold. Not yet tested by us. Source.

What's in the skill

When it loads

Master defensive Bash programming techniques for production-grade scripts. Use when writing robust shell scripts, CI/CD pipelines, or system utilities requiring fault tolerance and safety.

Sections in SKILL.md

  1. When to Use This Skill
  2. Detailed patterns and worked examples
  3. Best Practices Summary

Key facts

Author
wshobson
Repository
wshobson/agents
Installs on skills.sh
13,800 as of 2026-11-02
Last repo commit
2026-10-30

What it includes

  • set -Eeuo pipefail and what each flag does

    SKILL.md puts strict mode first in its best practices list. details.md has a Strict Mode section.

    Strict mode

  • trap handlers that report errors and clean up

    Core principle 2 in details.md shows trapping errors and exit to run cleanup.

    Error trapping and cleanup

  • Quoting, required variables and safe array loops

    Shows wrong and correct quoting, failing with a message when a required variable is unset, and reading command output into an array safely.

    Variable and array safety

  • Find where the script lives

    Fundamental pattern 1.

    Script directory detection

  • Prefixed functions with docs and error handling

    Pattern 2 gives a function layout with a naming prefix and checks.

    Function template

  • mktemp directory plus trap cleanup

    Pattern 3 creates a temporary directory and removes it on exit.

    Files · Safe temp files

  • Defaults, flags and required-argument checks

    Pattern 4.

    Argument parsing

  • Timestamped log levels

    Pattern 5.

    Structured logging

  • Background jobs, signals and wait

    Pattern 6 tracks background process IDs and waits for them.

    Runs code · Process orchestration

  • No-overwrite moves, guarded cleanup and atomic writes

    Pattern 7 includes a safe directory cleanup example.

    Files · Safe file operations

  • Scripts that are safe to rerun, and $() handling

    Patterns 8 and 9.

    Idempotent design and safe substitution

From the official docs

Permissions

Low risk

The skill bundles no scripts. Its reference examples show file cleanup and process handling that Claude may adapt, so read generated scripts before you run them.

What it can do

  • Read your data
  • Create and change things
  • Delete things
  • Read-only mode

Watch out for

  • Examples include file deletion and cleanup

    details.md has a safe directory cleanup example and mktemp cleanup traps. Check the paths in any script Claude writes before you run it. github.com

Security advisories

No published security advisories as of Nov 2, 2026.

Technical details
Turning on read-onlyNo read-only switch is documented. Ask Claude to show a script before running it.
Sign-in and keysNo API key or credential is mentioned in SKILL.md or details.md.
Scopes
  • Claude writes shell scripts in your project when you ask

Questions

What does the bash-defensive-patterns skill do?

It makes Claude follow defensive Bash practices when it writes or reviews a shell script. That means strict mode, quoting, traps, input validation, dry-run mode and safe temp files.

How do I install it?

Use the install box above. The skills CLI route installs only this skill. The plugin routes install the whole shell-scripting plugin, which adds 2 agents and the other skills in it.

Does it run or lint my scripts?

No scripts come with it, so it does not run or lint anything by itself. It shapes how Claude writes code. If you want checks to run, ask Claude to run a tool you already have.

Is it only for Bash?

It is written for Bash. SKILL.md also lists scripts that work across different platforms as a use case, and details.md includes a POSIX-compatible conditional alongside the Bash one. The plugin it belongs to describes itself as covering POSIX compliance too.

Is it safe?

It bundles no scripts. The reference examples include file moves, cleanup with rm and background process handling, which are templates for Claude to adapt in your scripts. Read any script before you run it.

Does it need an API key?

No file in the skill refers to one.

Information

updated Nov 2, 2026

Repository
wshobson/agents
Folder
plugins/shell-scripting/skills/bash-defensive-patterns

wshobson/agentsskills.sh

Sources

Docs, issue trackers and discussions this page is built from.

Show all 4
  1. Using skills in Claude · support.claude.com
  2. wshobson/agents README · github.com
  3. SKILL.md · github.com
  4. details.md · github.com

Updated Nov 2, 2026.