Deterministic Command Choices
Prefer commands whose output does not depend on locale, globbing or shell state
Use when: an agent constructs commands that a shell will interpret before the tool sees them
Avoid when: the command is a fixed literal with no interpolation
Procedure
- Identify every part of the command that the shell expands
- Replace globs with explicit file lists where the set matters
- Quote every path and value that could contain a space
- Avoid locale-sensitive sorting by specifying the collation or sorting explicitly
- Pin time formats to a fixed zone and format
- Re-run the command and confirm identical output
Signals
- two runs produce byte-identical output
- no path in the command is unquoted
- the file set passed to the tool is explicit
- timestamps carry a zone and a fixed format
Patterns
1. Explicit list
cmd a.txt b.txt instead of cmd *.txt
2. Quoted path
"results/my file.json"
3. Fixed time
--date 2026-10-29T00:00:00Z
Pitfalls
- Relying on glob expansion order which differs by filesystem and locale
- Leaving a date unformatted so the output changes every run
- Passing an unquoted path that breaks silently on a space
Done when
- the command produces identical output on a rerun
- no shell expansion affects which files or values are used