bash-defensive-patterns — Claude Code skill: install
This skill guides safer Bash scripts for automation, CI/CD, and system utilities. It covers error handling, input checks, and edge-case handling.
/plugin marketplace add wshobson/agents
/plugin install shell-scripting@claude-code-workflowsWhat bash-defensive-patterns does
bash-defensive-patterns provides practical patterns for Bash scripts that must handle failures and repeated runs. It covers strict mode with set -Eeuo pipefail, quoted variables, [[ ]] conditionals, input validation, and error handling with traps.
The guidance also covers structured logs with timestamps and levels, dry-run support, temporary files through mktemp, cleanup with trap, and executable checks with command -v. More detailed worked patterns are stored in references/details.md.
The skill treats idempotency as a design requirement for scripts that may be run again. For temporary files, cleanup and failure paths need to be planned together.
What it helps with
- write Bash scripts for CI/CD pipelines
- handle failures with strict mode and traps
- validate inputs, files, and permissions
- make rerunning automation scripts safe
Example prompts for the agent
- Write a CI/CD Bash script with
set -Eeuo pipefail, input validation, and error handling. - Add dry-run support, structured logging, and safe temporary-file cleanup to this system script.
- Review this script for idempotency and replace
whichchecks withcommand -v.
How to install bash-defensive-patterns
1Plugin marketplace
/plugin marketplace add wshobson/agents/plugin install shell-scripting@claude-code-workflowsThis installs the whole shell-scripting plugin with all its skills
2Skills CLI (Vercel)
npx skills add wshobson/agents --skill bash-defensive-patterns -a claude-code3Manually: put the files in place
~/.claude/skills/bash-defensive-patterns/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/bash-defensive-patterns/
1Skills CLI (Vercel)
npx skills add wshobson/agents --skill bash-defensive-patterns -a codex2Manually: put the files in place
.agents/skills/bash-defensive-patterns/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add wshobson/agents --skill bash-defensive-patterns -a cursor2Manually: put the files in place
.cursor/skills/bash-defensive-patterns/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install wshobson/agents bash-defensive-patterns2Manually: put the files in place
.github/skills/bash-defensive-patterns/SKILL.mdPlatform CLI
gemini skills install https://github.com/wshobson/agents --path plugins/shell-scripting/skills/bash-defensive-patternsManually: put the files in place
.devin/skills/bash-defensive-patterns/SKILL.mdThe legacy .windsurf/skills/ path still works
Claude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about bash-defensive-patterns
How do I install bash-defensive-patterns in Claude Code?
The commands are /plugin marketplace add wshobson/agents and /plugin install shell-scripting@claude-code-workflows.
What does bash-defensive-patterns do?
It guides Bash scripts with error handling, input validation, structured logging, safe temporary files, dry-run support, and idempotent behavior.
Which Bash practices does it cover?
It covers set -Eeuo pipefail, quoted variables, [[ ]] conditionals, mktemp, trap, idempotency, and executable checks with command -v.
Source text
SKILL.md · MIT
--- name: bash-defensive-patterns description: 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. --- # Bash Defensive Patterns Comprehensive guidance for writing production-ready Bash scripts using defensive programming techniques, error handling, and safety best practices to prevent common pitfalls and ensure reliability. ## When to Use This Skill - Writing production automation scripts - Building CI/CD pipeline scripts - Creating system administration utilities - Developing error-resilient deployment automation - Writing scripts that must handle edge cases safely - Building maintainable shell script libraries - Implementing comprehensive logging and monitoring - Creating scripts that must work across different platforms ## Detailed patterns and worked examples Detailed pattern documentation lives in `references/details.md`. Read that file when the navigation tier above is insufficient. ## Best Practices Summary 1. **Always use strict mode** - `set -Eeuo pipefail` 2. **Quote all variables** - `"$variable"` prevents word splitting 3. **Use [[]] conditionals** - More robust than [ ] 4. **Implement error trapping** - Catch and handle errors gracefully 5. **Validate all inputs** - Check file existence, permissions, formats 6. **Use functions for reusability** - Prefix with meaningful names 7. **Implement structured logging** - Include timestamps and levels 8. **Support dry-run mode** - Allow users to preview changes 9. **Handle temporary files safely** - Use mktemp, cleanup with trap 10. **Design for idempotency** - Scripts should be safe to rerun 11. **Document requirements** - List dependencies and minimum versions 12. **Test error paths** - Ensure error handling works correctly 13. **Use `command -v`** - Safer than `which` for checking executables 14. **Prefer printf over echo** - More predictable across systems
© Ryan Snodgrass · MIT · wshobson/agents