CLI Flags & Commands — Claude Cert Academy
CLI Flags & Commands
Claude Code is invoked as `claude` from the terminal. Flags control authentication, execution mode, output, and debugging. Most flags are composable — combine them as needed.
Auth & Config
- --model MODEL — specify the Claude model to use (e.g. claude-opus-4-8, claude-sonnet-4-6). Overrides the model in settings.json for this invocation.
- ANTHROPIC_API_KEY — environment variable. Must be set for Claude Code to authenticate. Set in shell profile or pass inline.
- --add-dir PATH — add an extra directory to Claude Code's allowed read/write scope. Can be passed multiple times.
- CLAUDE_HOME — override the directory Claude Code uses for global config (~/.claude by default).
# Auth & config examples
export ANTHROPIC_API_KEY=sk-ant-...
claude --model claude-sonnet-4-6 "summarize this codebase"
claude --add-dir /tmp/scratch --add-dir /data "analyze both dirs"
CLAUDE_HOME=/opt/claude-config claude "use custom home"
Execution Mode
- -p "prompt" — headless / non-interactive mode. Runs the prompt, prints output to stdout, exits. Required for scripting and pipelines. Short form of --print.
- -p — without a prompt string reads from stdin when combined with piped input.
- --plan — plan-only mode: Claude generates a plan and shows it but does not execute any tools. Use for review before action.
- --dangerously-skip-permissions — bypass all tool permission prompts. Only safe in fully isolated environments (Docker, CI sandbox). Never use on machines with production credentials.
# Mode examples
claude -p "list all TODO comments in src/" > todos.txt
echo "fix the bug in auth.ts" | claude -p
claude --plan "refactor the payments module"
# Dangerous: only in isolated CI
claude --dangerously-skip-permissions -p "run the test suite"
I/O
- stdin piping — pipe content into claude via cat or heredoc combined with -p.
- < redirect — redirect file contents as stdin.
- stdout — in -p mode, final text response goes to stdout. Tool calls and intermediate output go to stderr.
- exit codes — 0: success, 1: error (API error, timeout, model error), 2: permission denied (tool blocked by settings).
# I/O examples
cat error.log | claude -p "what caused this error?"
claude -p "explain this code" < src/main.py
claude -p "generate a test" > test_generated.py
# Exit code usage in scripts
if claude -p "check for security issues in auth.ts" > report.txt; then
echo "Scan complete"
else
echo "Claude failed with exit $?"
fi
Debug
- --debug — enable verbose debug output: API requests, tool calls, token counts, timing. Useful for diagnosing slow or failing sessions.
- --version — print the installed Claude Code version and exit.
# Debug examples
claude --debug "why is this function slow?"
claude --version
# => claude 1.2.3
Continue to Claude Cert Academy