Headless Mode

Run Command Code non-interactively in scripts, CI/CD pipelines, and automation workflows. Headless mode executes a single query, outputs the response to stdout, and exits.


Use the -p (or --print) flag to run in headless mode:

cmd -p "explain this file"
Info

Always wrap your query in quotes. Unquoted multi-word queries cause argument parsing errors.


Direct Argument

Pass your query directly after the -p flag:

cmd -p "refactor the auth module"

Piped Stdin

Pipe input from another command or file:

echo "explain this error" | cmd -p
cat prompt.txt | cmd -p

Command Code auto-detects piped input when no query argument is provided. If stdin is a TTY and no query is given, it exits with an error.


By default, headless mode blocks tools that modify your system — file writes, file edits, and shell commands are denied. This keeps automated runs safe.

To enable all tools, pass --dangerously-skip-permissions:

cmd -p "fix the lint errors" --dangerously-skip-permissions
ToolDefault (no flag)With --dangerously-skip-permissions
File reads, grep, globAllowedAllowed
File edits and writesBlockedAllowed
Shell commandsBlockedAllowed
Warning

Only use --dangerously-skip-permissions in trusted environments. It allows Command Code to modify files and run shell commands without confirmation.


Headless mode supports multi-turn tool execution. Command Code can read files, search code, and (with permissions) edit files and run commands, just like interactive mode.

The conversation loop runs for up to 10 turns. If the limit is reached, a warning is printed to stderr and the partial response is returned.


Use exit codes to handle results in scripts and CI/CD:

CodeMeaningConstant
0SuccessEXIT_SUCCESS
1General errorEXIT_ERROR
3Not authenticatedEXIT_AUTH_ERROR
4Permission deniedEXIT_PERMISSION_DENIED
5Rate limit exceededEXIT_RATE_LIMITED
6Network failureEXIT_CONNECTION_ERROR
7API server error (5xx)EXIT_SERVER_ERROR
130Interrupted (SIGINT/SIGTERM)EXIT_INTERRUPTED

Example usage in a script:

cmd -p "check for security issues" --dangerously-skip-permissions if [ $? -ne 0 ]; then echo "Command Code failed" exit 1 fi

GitHub Actions

- name: Code review with Command Code run: | cmd -p "review the changes in this PR" --skip-onboarding env: COMMANDCODE_API_KEY: ${{ secrets.COMMANDCODE_API_KEY }}

Shell Script

#!/bin/bash set -e # Generate docs for changed files CHANGED=$(git diff --name-only HEAD~1) echo "Document these changed files: $CHANGED" | cmd -p --skip-onboarding

Piping Output

Headless mode is pipe-friendly. Output goes to stdout, errors and warnings go to stderr:

# Save response to a file cmd -p "generate a README for this project" > README.md # Pipe to another command cmd -p "list all TODO comments" | grep "critical" # Use in command substitution SUMMARY=$(cmd -p "summarize this codebase in one paragraph")

Flags useful for headless and automated workflows:

FlagDescription
-p, --print [query]Run in headless mode
--dangerously-skip-permissionsAllow file writes and shell commands
--skip-onboardingSkip taste onboarding (for CI/automated runs)
-t, --trustAuto-trust project (skip initial permission prompt)
--planStart in plan mode (read-only exploration)
--permission-mode <mode>Set permission mode: standard, plan, auto-accept

LimitationDetails
Max turnsUp to 10 conversation turns per query (tool calls count as turns)
No interactive promptsCannot use slash commands, keyboard shortcuts, or interactive UI
Session scopeEach invocation is a standalone session with no conversation history
Stdin timeoutPiped stdin times out after 30 seconds if no data is received