A user wants to run a non-interactive Claude Code task in a shell scri — Claude Code Certified Professional Practice — Claude Cert Academy

A user wants to run a non-interactive Claude Code task in a shell script that exits with a non-zero code on failure. Which invocation pattern is correct?

Answer: claude -p "task description" && echo done

The -p flag (short for --print) puts Claude Code in non-interactive mode, executes the prompt, prints output, and exits with a non-zero code if the task fails. Chaining with && correctly propagates failure. The grep pattern would miss non-success outputs silently. The semicolon form always runs echo regardless of exit code. --pipe is not a valid flag.

Continue to Claude Cert Academy