CC-301l · Module 1

CLI Automation

4 min read

Claude Code is not just an interactive terminal application — it is a CLI tool with flags that enable programmatic usage. The -p flag (prompt mode) sends a single prompt to Claude and outputs the result to stdout, then exits. No interactive session. No waiting for input. This transforms Claude Code from a conversational tool into a scriptable command that can be embedded in shell scripts, cron jobs, and CI pipelines.

The basic invocation: claude -p "Explain the auth module in this project" outputs Claude's response to stdout. Pipe it to a file: claude -p "Generate a changelog from the last 10 commits" > CHANGELOG.md. Chain it with other commands: git diff HEAD~1 | claude -p "Review this diff for security issues". The -p flag is the bridge between interactive AI and automated workflows.

# Generate a changelog from recent commits
claude -p "Generate a changelog from the last 10 commits. \
  Format: markdown, grouped by type (feat, fix, refactor)." \
  > CHANGELOG.md

# Review a diff for security issues
git diff main...HEAD | claude -p "Review this diff. \
  Flag any security concerns: SQL injection, XSS, \
  hardcoded secrets, missing input validation."

# Generate documentation for a module
claude -p "Read src/auth/ and generate API documentation \
  for all exported functions. Format: JSDoc style."