🎁 Get the FREE AI Skills Starter Guide β€” Subscribe β†’
BytesAgainBytesAgain
πŸ¦€ ClawHub

Batch Files

by @jhauga

Expert-level Windows batch file (.bat/.cmd) skill for writing, debugging, and maintaining CMD scripts. Use when asked to "create a batch file", "write a .bat...

Versionv1.0.0
βš™οΈ Configuration

  • Windows NT-based OS (Windows 7 or later)
  • cmd.exe (built-in)
  • Optional: a bin/ directory on PATH for distributing scripts as commands
  • Optional: PATHEXT configured to include .BAT;.CMD (default on Windows)
  • πŸ“‹ Tips & Best Practices

    1. Always start with @echo off and setlocal β€” Prevents noisy output and variable leakage to the caller. 2. Validate inputs before processing β€” Check required arguments and file existence early. Use if not defined and if not exist. 3. Quote paths and variables β€” Use "%~1" and "%_MY_PATH%" to handle spaces and special characters safely. 4. Use exit /b instead of exit β€” Avoids closing the parent console window. 5. Return meaningful exit codes β€” exit /b 0 for success, non-zero for specific failures. 6. Use %~dp0 for script-relative paths β€” Ensures the script works regardless of the caller's working directory. 7. Prefer ROBOCOPY over XCOPY β€” More reliable, supports retry, mirroring, and logging. 8. Use EnableDelayedExpansion when modifying variables inside loops or parenthesized blocks. 9. Write errors to stderr β€” echo ERROR: message 1>&2 keeps stdout clean for piping. 10. Use REM for comments β€” :: can cause issues inside FOR loop bodies.

    Security Considerations

  • Never store credentials in batch files β€” Use environment variables, credential stores, or prompts.
  • Validate user input β€” Unquoted variables containing &, |, or > can inject commands. Always quote: "%_USER_INPUT%".
  • Use SETLOCAL β€” Prevents variable values from leaking to parent processes.
  • Sanitize file paths β€” Validate paths before passing to DEL, RD, or ROBOCOPY to prevent unintended deletion.
  • Avoid SET /P for sensitive input β€” Input is visible and stored in console history. Use a dedicated credential tool when possible.
  • View on ClawHub
    TERMINAL
    clawhub install batch-files

    πŸ§ͺ Use this skill with your agent

    Most visitors already have an agent. Pick your environment, install or copy the workflow, then run the smoke-test prompt above.

    πŸ” Can't find the right skill?

    Search 60,000+ AI agent skills β€” free, no login needed.

    Search Skills β†’