Command-line tool (CLI)
Note for AI agents: This page is baseline guidance, not an exact prescription. Read it, tell your owner what applies to their project, and get their approval before you change anything. Your project's own rules take precedence. If something important for this project is missing here, suggest it to your owner.
For agents
- A CLI runs with the caller’s rights and is often used in scripts. Typical class: S or M.
- Rule 1:
--help,--version, correct exit codes, results on stdout and errors on stderr. - Rule 2: never take secrets as arguments and never build shell strings from arguments.
- Rule 3: destructive commands confirm or support
--dry-run; releases ship with checksums.
Which class?
- S: a personal or one-off script.
- M: shared with others, handles credentials or personal data.
- L: widely distributed, runs in pipelines with production access.
- XL: a very large user base.
Audit checklist
Every project
- Facts are verified from current official documentation
- What: Commands, libraries, APIs and platform policies in the project come from current official documents, not from memory.
- How to check: Open the dependency list and the platform configuration; for each non-trivial choice find the official page it relies on (link in a comment or a decision note).
- Evidence: Decision note or code comment with the official URL and the date it was checked.
- Packages come from official sources, stable versions only
- What: Packages and versions are chosen from official sources; the current stable release is used, not alpha or beta.
- How to check: Read the dependency file for pre-release tags (alpha, beta, rc, next); check each package on its official registry page.
- Evidence: Dependency file without pre-release versions.
- No secrets in code, chat, commits or logs
- What: Passwords, keys and tokens live in environment variables or a secret manager;
.envis ignored by git; the repository has only.env.example. - How to check: Check
.gitignorefor.env; run a secret scanner (for example gitleaks) over the full history; search for key-like strings. - Evidence:
.gitignoreline, scanner report with zero findings,.env.examplepath.
- What: Passwords, keys and tokens live in environment variables or a secret manager;
- Reports separate “written”, “tested” and “works end to end”
- What: Status reports say clearly whether something is written, passed its tests, or was run end to end; skipped or failed steps are stated.
- How to check: Read the last HANDOFF or release notes; look for features reported as done that have no test or run record.
- Evidence: HANDOFF lines or a test log for each feature marked done.
- Project memory files exist and are current
- What: The repository has CLAUDE.md or AGENTS.md (permanent rules) and HANDOFF.md (where we stopped), updated at the end of every work round.
- How to check: Look in the repository root for both files; compare the HANDOFF date with the latest commit date.
- Evidence: File paths and the date of the last HANDOFF update.
- The tool has help and version output
- What:
--helpexplains commands and options;--versionprints the version; wrong input prints a short usage hint. - How to check: Run
tool --help,tool --version, and with a wrong option. - Evidence: Command output.
- What:
- Exit codes and output streams are correct
- What: Success returns 0, errors return non-zero; results go to standard output and messages or errors to standard error.
- How to check: Run success and failure cases and read
$?and the streams separately. - Evidence: Test names for exit codes.
- Secrets are not passed as command-line arguments
- What: Secrets come from environment variables, files or prompts, since arguments appear in process lists and shell history.
- How to check: Search the argument definitions for password or token options.
- Evidence: Search result; documentation of the safe method.
- Destructive commands confirm or support dry run
- What: Commands that delete or overwrite ask for confirmation (with a
--yesoption for scripts) and offer--dry-run. - How to check: Run the destructive commands.
- Evidence: Command output.
- What: Commands that delete or overwrite ask for confirmation (with a
- Arguments are never built into shell strings
- What: The tool passes arguments to other programs as a list, not by building a shell command line.
- How to check: Search for shell execution with concatenation or string formatting.
- Evidence: Search result.
+ If it has users, personal data or API keys (M)
- One package manager, lockfile committed
- What: Exactly one package manager is used and enforced; the lockfile is committed; installs are done from the lockfile (for example
--frozen-lockfile). - How to check: Look for a lockfile in the repository and a rule that forbids other managers; check the CI and Docker install commands.
- Evidence: Lockfile path; install command lines.
- What: Exactly one package manager is used and enforced; the lockfile is committed; installs are done from the lockfile (for example
- Configuration has a clear order
- What: Command-line options override environment variables, which override config files, which override defaults; this is documented.
- How to check: Read the configuration loader and docs.
- Evidence: Documented order; test.
- Releases are verifiable
- What: Release files come with checksums or signatures and install instructions that verify them.
- How to check: Read the release pipeline and download page.
- Evidence: Checksum file; verification instructions.
- All input is validated on the server with a schema
- What: Every request body, query and parameter is checked on the server against a schema; the client check is only a convenience.
- How to check: For each endpoint find the schema or validator; send invalid, oversized and unexpected fields and see the response.
- Evidence: Validator files per endpoint; test cases for invalid input.
- Logs contain no personal data or secrets
- What: Logs do not record passwords, tokens, keys or personal data; if needed they are masked.
- How to check: Read the logging setup; trigger a login and a form and inspect the log lines; search for e-mail and token patterns.
- Evidence: Sample log lines after a test run showing masking.
- External API keys stay on the server
- What: Third-party API keys (including LLM keys) are kept on the server and never shipped to the browser or app.
- How to check: Search the client bundle and app package for key-like strings; check that client calls go to your own server.
- Evidence: Search result with zero keys in the client build.
- Critical flows have automated tests and a local check
- What: Login, saving data, payment (if any) and permission checks have automated tests; one local command runs the checks before pushing.
- How to check: List the test files; run the check command; look for a git hook that runs it.
- Evidence: Test names and a passing run log.
- Secret scanning runs before push and in CI
- What: A scanner (for example gitleaks or secretlint) runs before code is pushed and in CI.
- How to check: Find the hook or CI step that runs the scanner.
- Evidence: Hook file or CI step; latest clean run.
- Open source licenses are shown
- What: A published app or site shows the name and license of each library (for example Settings → Open source licenses), generated from the lockfile; forbidden licenses fail a check.
- How to check: Find the licenses screen or file and how it is generated; look for a license check in CI.
- Evidence: Generated license list; CI step.
- Every external call has a time limit
- What: Database queries, storage, e-mail, notifications, AI calls and external processes all have an upper time limit.
- How to check: Search for HTTP client and process calls without a timeout setting.
- Evidence: Configuration or code lines with timeouts.
+ If it has an admin panel, file uploads, many users or a store app (L)
Items for class L: see Command-line tool: classes L–XL checklist.
+ If it targets millions of users (XL)
Items for class XL: see Command-line tool: classes L–XL checklist.
Common mistakes
- Always exiting with code 0, so scripts cannot detect failure.
- Mixing results and error messages on one stream.
- A password option on the command line, visible in process lists.
- Deleting files without confirmation or a dry run.
- Passing user text to
sh -c. - Output that cannot be parsed by scripts and has no machine-readable option.
- No version or help output.
- Releases without checksums, so users cannot verify the download.
Example projects
- Script that renames photos: CLI, S.
- Deployment helper for a team: CLI, M.
- Database migration runner: CLI, M, destructive confirmations.
- Open source formatter tool: CLI, M.
- Backup command with cloud credentials: CLI, M.
- Code generator for developers: CLI, S.
- CI release tool with production access: CLI, L.
- Log analyzer: CLI, S.
- Package manager helper: CLI, M.
- Kubernetes helper plugin: CLI, L.
- Data export tool for customer data: CLI, M, personal data.
- Convenience wrapper around an API: CLI, S.
Sources
- POSIX: Utility Conventions — The Open Group
- OS Command Injection Defense Cheat Sheet — OWASP Cheat Sheet Series
- Secrets Management Cheat Sheet — OWASP Cheat Sheet Series
- Input Validation Cheat Sheet — OWASP Cheat Sheet Series
- Concise Guide for Developing More Secure Software — OpenSSF
- SLSA: Supply-chain Levels for Software Artifacts — OpenSSF
- SPDX — Linux Foundation
- Pro Build Guide v1.2: compiled team practices — Pro Build Guide