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

  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

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-patterns

Codex

npx degit wshobson/agents/plugins/shell-scripting/skills/bash-defensive-patterns#main ~/.codex/skills/bash-defensive-patterns

Claude.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.

Related devops & cloud skills

  1. Supabase

    Official

    Use when doing ANY task involving Supabase. Triggers: Supabase products (Database, Auth, Edge Functions, Realtime, Storage, Vectors, Cron,…

    supabase/agent-skills★ 3.1k
  2. Senior Architect

    System architecture decisions with a written rationale: monolith vs microservices, database choice, scaling limits, ADRs, Mermaid diagrams.

    alirezarezvani/claude-skills★ 30k
  3. Vercel Deploy

    Official

    Deploy applications and websites to Vercel. Use when the user requests deployment actions like "deploy my app", "deploy and give me the…

    openai/skills★ 29k
  4. Cost Optimization

    Optimize cloud costs across AWS, Azure, GCP, and OCI through resource rightsizing, tagging strategies, reserved instances, and spending…

    wshobson/agents★ 43k
  5. Database Migration

    Execute database migrations across ORMs and platforms with zero-downtime strategies, data transformation, and rollback procedures.

    wshobson/agents★ 43k
  6. Deployment Pipeline Design

    Design multi-stage CI/CD pipelines with approval gates, security checks, and deployment orchestration.

    wshobson/agents★ 43k
  7. Distributed Tracing

    Implement distributed tracing with Jaeger and Tempo to track requests across microservices and identify performance bottlenecks.

    wshobson/agents★ 43k
  8. Github Actions Templates

    Create production-ready GitHub Actions workflows for automated testing, building, and deploying applications.

    wshobson/agents★ 43k
  9. Gitlab Ci Patterns

    Build GitLab CI/CD pipelines with multi-stage workflows, caching, and distributed runners for scalable automation.

    wshobson/agents★ 43k

See all devops & cloud skills →

More skills from wshobson

  1. Bats Testing Patterns

    Master Bash Automated Testing System (Bats) for comprehensive shell script testing.

    wshobson/agents★ 43k
  2. Bazel Build Optimization

    Optimize Bazel builds for large-scale monorepos. Use when configuring Bazel, implementing remote execution, or optimizing build performance…

    wshobson/agents★ 43k
  3. Before You Build

    Pre-build product and feature risk review for founders, product managers, and AI-assisted builders.

    wshobson/agents★ 43k

All skills by wshobson →

Give your whole team an AI agent with skills

Cody runs managed AI agents your team can message in Slack, Teams, WhatsApp and the web, with 50+ business integrations, scheduled tasks and memory. No terminal required.