AI Command Rules
A skill for writing precise, environment-aware shell commands and scripts that work correctly the first time across Windows, Linux, macOS, sandboxes, virtual environments, and containers.
Core Principle
Always detect the environment before writing a command. Never assume. A command that works on Linux bash will silently fail or behave differently on Windows CMD, PowerShell, or macOS zsh. When in doubt, ask or emit environment-adaptive commands.
Step 1: Detect the Environment
Before writing any command, identify:
| Signal |
How to detect |
| OS |
User mentions, file paths (C:\ vs /), or ask explicitly |
| Shell |
bash / zsh / fish / PowerShell / CMD / sh |
| Runtime context |
Local terminal, Docker container, CI/CD, sandbox, SSH session |
| Python env |
venv, conda, pipenv, poetry, system Python, Docker |
| Privileges |
Root/sudo available? Admin on Windows? |
If uncertain, emit a detection snippet first:
# Universal OS+shell detector (paste in terminal first)
echo "OS: $(uname -s 2>/dev/null || echo Windows)"
echo "Shell: $SHELL"
echo "Python: $(python --version 2>&1 || python3 --version 2>&1)"
Step 2: Environment-Specific Rules
Read the relevant reference file before emitting commands:
- Linux / macOS / bash / zsh →
references/unix.md
- Windows CMD / PowerShell / WSL →
references/windows.md
- Docker / containers / sandboxes →
references/containers.md
- Python / virtual environments →
references/python-env.md
- SSH / remote execution →
references/ssh-remote.md
- Git →
references/git.md
For cross-platform tasks, read all relevant files.
Step 3: Command Writing Checklist
Before emitting any command block, verify:
✅ Shell Compatibility
✅ Error Handling
✅ Permissions & Privileges
✅ Environment Isolation
✅ Cross-Platform Output
Step 4: Output Formats
Single environment — emit one block with a label:
```bash # Linux / macOS
pip3 install -r requirements.txt
```
Cross-platform — emit tabbed alternatives:
**Linux / macOS (bash/zsh)**
```bash
python3 -m venv .venv && source .venv/bin/activate
```
**Windows (PowerShell)**
```powershell
python -m venv .venv; .\.venv\Scripts\Activate.ps1
```
**Windows (CMD)**
```cmd
python -m venv .venv && .venv\Scripts\activate.bat
```
Agentic / AI coding context — always add safety guards:
```bash
set -euo pipefail # Exit on error, undefined vars, pipe failures
# ... rest of script
```
Common Pitfalls to Avoid
| ❌ Wrong |
✅ Right |
Why |
python script.py |
python3 script.py (Unix) |
macOS/Linux default python may be 2.x |
pip install X |
pip install X --break-system-packages (system Python) |
PEP 668 restriction |
rm -rf dist/ |
rm -rf ./dist/ |
Protects against accidental root deletion |
cd /app && run.sh |
cd /app && ./run.sh |
PATH may not include . |
source activate |
conda activate myenv |
conda >= 4.6 deprecated old syntax |
docker run image cmd |
docker run --rm image cmd |
Avoid orphaned containers |
ssh user@host cmd |
ssh -o StrictHostKeyChecking=no user@host 'cmd' |
Non-interactive SSH needs explicit options |
&& in PowerShell |
; or -and |
&& not supported in PS < 7 |
%VAR% in PowerShell |
$env:VAR |
Different variable syntax |
\n in Windows paths |
/ or \\ |
Use forward slashes where possible |
Sandbox / Restricted Environment Rules
When Claude itself is executing commands (Claude Code, agentic pipelines, sandboxed VMs):
- Probe before assuming — run
which, command -v, or Get-Command to verify tool availability
- No interactive prompts — use
-y, --yes, --non-interactive, -f flags
- Absolute paths preferred — don't rely on PATH being correct
- Temp files — write to
/tmp (Linux) or $env:TEMP (Windows), not current directory
- Network — check if egress is allowed before running
curl, pip install, npm install
- No
sudo in containers — usually running as root already; sudo may not exist
Quick Reference: Shell Detection Snippets
# Detect if running inside Docker
[ -f /.dockerenv ] && echo "In Docker" || echo "Not Docker"
# Detect OS in bash
case "$(uname -s)" in
Linux*) OS=Linux ;;
Darwin*) OS=Mac ;;
CYGWIN*|MINGW*|MSYS*) OS=Windows ;;
esac
# Detect active Python venv
[ -n "$VIRTUAL_ENV" ] && echo "venv: $VIRTUAL_ENV" || echo "No venv active"
# Detect conda env
[ -n "$CONDA_DEFAULT_ENV" ] && echo "conda: $CONDA_DEFAULT_ENV"
# PowerShell: detect version
$PSVersionTable.PSVersion
# PowerShell: detect if running as Admin
([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
Source: russodope/ai-cli-kit — distributed by TomeVault.
1---2name: ai-command-rules3description: Use this skill whenever Claude needs to write, suggest, or execute shell commands, scripts, or terminal instructions — especially in AI coding contexts (Claude Code, Cursor, Copilot, agentic pipelines). Triggers include bash/shell scripts, SSH remote commands, Docker/container operations, Git commands, Python/virtual environment commands, PowerShell, Windows CMD, and any cross-platform CLI tasks. Must be consulted whenever the user mentions multiple environments (Windows/Linux/Mac, sandbox, venv, PowerShell, WSL, Docker), asks Claude to run or execute commands or write a script, or when Claude is about to emit a command block. Prevents syntax errors, wrong-shell assumptions, and commands that break silently across platforms.4---56# AI Command Rules78A skill for writing precise, environment-aware shell commands and scripts that work correctly the first time across Windows, Linux, macOS, sandboxes, virtual environments, and containers.910## Core Principle1112**Always detect the environment before writing a command.** Never assume. A command that works on Linux bash will silently fail or behave differently on Windows CMD, PowerShell, or macOS zsh. When in doubt, ask or emit environment-adaptive commands.1314---1516## Step 1: Detect the Environment1718Before writing any command, identify:1920| Signal | How to detect |21|---|---|22| OS | User mentions, file paths (C:\\ vs /), or ask explicitly |23| Shell | bash / zsh / fish / PowerShell / CMD / sh |24| Runtime context | Local terminal, Docker container, CI/CD, sandbox, SSH session |25| Python env | venv, conda, pipenv, poetry, system Python, Docker |26| Privileges | Root/sudo available? Admin on Windows? |2728**If uncertain**, emit a detection snippet first:29```bash30# Universal OS+shell detector (paste in terminal first)31echo "OS: $(uname -s 2>/dev/null || echo Windows)"32echo "Shell: $SHELL"33echo "Python: $(python --version 2>&1 || python3 --version 2>&1)"34```3536---3738## Step 2: Environment-Specific Rules3940Read the relevant reference file before emitting commands:4142- **Linux / macOS / bash / zsh** → `references/unix.md`43- **Windows CMD / PowerShell / WSL** → `references/windows.md`44- **Docker / containers / sandboxes** → `references/containers.md`45- **Python / virtual environments** → `references/python-env.md`46- **SSH / remote execution** → `references/ssh-remote.md`47- **Git** → `references/git.md`4849For cross-platform tasks, read all relevant files.5051---5253## Step 3: Command Writing Checklist5455Before emitting any command block, verify:5657### ✅ Shell Compatibility58- [ ] Correct quoting style for target shell (single vs double vs backtick)59- [ ] Path separator correct (`/` vs `\`)60- [ ] Line continuation correct (`\` bash vs `` ` `` PowerShell)61- [ ] Variable syntax correct (`$VAR` bash vs `$env:VAR` PowerShell vs `%VAR%` CMD)62- [ ] Logical operators correct (`&&` / `||` bash vs `-and` / `-or` PowerShell)6364### ✅ Error Handling65- [ ] Long scripts use `set -euo pipefail` (bash) or `$ErrorActionPreference = 'Stop'` (PS)66- [ ] Destructive commands (`rm`, `del`, `DROP`) have a dry-run or confirmation step67- [ ] Commands that may fail silently have explicit exit code checks6869### ✅ Permissions & Privileges70- [ ] `sudo` / `su` used only when needed; never prefix everything with sudo71- [ ] Windows: flag if Admin PowerShell is required72- [ ] Docker: flag if `--privileged` or volume mounts need host permission7374### ✅ Environment Isolation75- [ ] Python commands use the correct interpreter (`python` vs `python3` vs `./venv/bin/python`)76- [ ] npm/node commands run inside the correct project directory77- [ ] Docker commands target the correct container/image name7879### ✅ Cross-Platform Output80- [ ] If user may run on multiple OSes, provide alternatives (see formats below)8182---8384## Step 4: Output Formats8586### Single environment — emit one block with a label:87````88```bash # Linux / macOS89pip3 install -r requirements.txt90```91````9293### Cross-platform — emit tabbed alternatives:94````95**Linux / macOS (bash/zsh)**96```bash97python3 -m venv .venv && source .venv/bin/activate98```99100**Windows (PowerShell)**101```powershell102python -m venv .venv; .\.venv\Scripts\Activate.ps1103```104105**Windows (CMD)**106```cmd107python -m venv .venv && .venv\Scripts\activate.bat108```109````110111### Agentic / AI coding context — always add safety guards:112````113```bash114set -euo pipefail # Exit on error, undefined vars, pipe failures115# ... rest of script116```117````118119---120121## Common Pitfalls to Avoid122123| ❌ Wrong | ✅ Right | Why |124|---|---|---|125| `python script.py` | `python3 script.py` (Unix) | macOS/Linux default `python` may be 2.x |126| `pip install X` | `pip install X --break-system-packages` (system Python) | PEP 668 restriction |127| `rm -rf dist/` | `rm -rf ./dist/` | Protects against accidental root deletion |128| `cd /app && run.sh` | `cd /app && ./run.sh` | PATH may not include `.` |129| `source activate` | `conda activate myenv` | conda >= 4.6 deprecated old syntax |130| `docker run image cmd` | `docker run --rm image cmd` | Avoid orphaned containers |131| `ssh user@host cmd` | `ssh -o StrictHostKeyChecking=no user@host 'cmd'` | Non-interactive SSH needs explicit options |132| `&&` in PowerShell | `;` or `-and` | `&&` not supported in PS < 7 |133| `%VAR%` in PowerShell | `$env:VAR` | Different variable syntax |134| `\n` in Windows paths | `/` or `\\` | Use forward slashes where possible |135136---137138## Sandbox / Restricted Environment Rules139140When Claude itself is executing commands (Claude Code, agentic pipelines, sandboxed VMs):1411421. **Probe before assuming** — run `which`, `command -v`, or `Get-Command` to verify tool availability1432. **No interactive prompts** — use `-y`, `--yes`, `--non-interactive`, `-f` flags1443. **Absolute paths preferred** — don't rely on PATH being correct1454. **Temp files** — write to `/tmp` (Linux) or `$env:TEMP` (Windows), not current directory1465. **Network** — check if egress is allowed before running `curl`, `pip install`, `npm install`1476. **No `sudo` in containers** — usually running as root already; `sudo` may not exist148149---150151## Quick Reference: Shell Detection Snippets152153```bash154# Detect if running inside Docker155[ -f /.dockerenv ] && echo "In Docker" || echo "Not Docker"156157# Detect OS in bash158case "$(uname -s)" in159 Linux*) OS=Linux ;;160 Darwin*) OS=Mac ;;161 CYGWIN*|MINGW*|MSYS*) OS=Windows ;;162esac163164# Detect active Python venv165[ -n "$VIRTUAL_ENV" ] && echo "venv: $VIRTUAL_ENV" || echo "No venv active"166167# Detect conda env168[ -n "$CONDA_DEFAULT_ENV" ] && echo "conda: $CONDA_DEFAULT_ENV"169```170171```powershell172# PowerShell: detect version173$PSVersionTable.PSVersion174175# PowerShell: detect if running as Admin176([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)177```178179---180> Source: [russodope/ai-cli-kit](https://github.com/russodope/ai-cli-kit) — distributed by [TomeVault](https://tomevault.io).181<!-- tomevault:4.0:skill_md:2026-06-16 -->