Bash Defensive Patterns skill for Claude
Master defensive Bash programming techniques for production-grade scripts.
When Claude uses it
Use when writing robust shell scripts, CI/CD pipelines, or system utilities requiring fault tolerance and safety.
Bash Defensive Patterns SKILL.md
The full skill file from wshobson/agents (MIT).
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
- Always use strict mode -
set -Eeuo pipefail - Quote all variables -
"$variable"prevents word splitting - Use [[]] conditionals - More robust than [ ]
- Implement error trapping - Catch and handle errors gracefully
- Validate all inputs - Check file existence, permissions, formats
- Use functions for reusability - Prefix with meaningful names
- Implement structured logging - Include timestamps and levels
- Support dry-run mode - Allow users to preview changes
- Handle temporary files safely - Use mktemp, cleanup with trap
- Design for idempotency - Scripts should be safe to rerun
- Document requirements - List dependencies and minimum versions
- Test error paths - Ensure error handling works correctly
- Use
command -v- Safer thanwhichfor checking executables - Prefer printf over echo - More predictable across systems
How to install Bash Defensive Patterns
Claude Code
Copy the skill into your personal skills folder (or into .claude/skills/ inside a project):
npx degit wshobson/agents/plugins/shell-scripting/skills/bash-defensive-patterns#main ~/.claude/skills/bash-defensive-patternsCodex
npx degit wshobson/agents/plugins/shell-scripting/skills/bash-defensive-patterns#main ~/.codex/skills/bash-defensive-patternsClaude.ai and Claude Desktop
Download the skill folder from GitHub, zip it, and upload it under Settings → Capabilities → Skills.
Frequently asked questions
+What does the Bash Defensive Patterns skill do?
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.
+How do I install Bash Defensive Patterns in Claude Code?
Copy the skill folder into ~/.claude/skills/bash-defensive-patterns, for example with "npx degit wshobson/agents/plugins/shell-scripting/skills/bash-defensive-patterns#main ~/.claude/skills/bash-defensive-patterns". Claude Code loads it automatically and uses it when a task matches.
+Does Bash Defensive Patterns work with ChatGPT or Codex?
Yes. Bash Defensive Patterns uses the open SKILL.md format. In Codex, put the folder in ~/.codex/skills/bash-defensive-patterns. In Claude.ai, zip the folder and upload it under Settings → Capabilities → Skills.
+Is Bash Defensive Patterns free?
Bash Defensive Patterns is published on GitHub by wshobson under the MIT license, which allows free use.