Certopolis

Claude Certified Architect – Foundations

Claude Code in CI: claude -p, --bare and GitHub Actions

Run Claude Code in a pipeline with claude -p "<prompt>", which runs non-interactively and exits 0 on success. Add --bare so the run skips local hooks, skills, MCP servers and CLAUDE.md and behaves the same on every machine, and pre-approve tools with --allowedTools.

Make runs reproducible

Without --bare, claude -p discovers hooks, skills, subagents, plugins, MCP servers, auto memory and CLAUDE.md just as an interactive session does, including anything in ~/.claude or the project's .mcp.json. --bare skips all of that. Pass what you need explicitly: --append-system-prompt, --settings, --mcp-config or --agents. Bare mode does not use your subscription login, so set ANTHROPIC_API_KEY.

-p reads stdin, so cat build-error.txt | claude -p 'concisely explain the root cause of this build error' > output.txt works like any command-line tool. Piped input is capped at 10MB.

Permissions without a person

--allowedTools "Bash(git diff *),Read" approves listed tools without prompting. The space before * matters: Bash(git diff*) would also match git diff-index. --permission-mode dontAsk denies every call that would otherwise prompt, which suits locked-down CI. --permission-mode acceptEdits lets Claude write files and run common filesystem commands. --permission-prompts none stops a run waiting on a permission host nobody is watching.

Machine-readable output

--output-format json returns the text in result plus the session ID and metadata. To get a fixed shape, add --json-schema with a JSON Schema and read the structured_output field. --output-format stream-json emits newline-delimited events.

To keep Claude Code's default prompt and add a role, use --append-system-prompt; --system-prompt replaces the default entirely. To continue a specific run, capture session_id from the JSON and pass it to --resume.

GitHub Actions

anthropics/claude-code-action@v1 runs Claude Code in workflows. Without a prompt input it answers @claude mentions in issues and pull requests; with one it runs automatically on any event. Pass CLI flags such as --max-turns and --allowedTools through claude_args, and store ANTHROPIC_API_KEY as a secret. Run /install-github-app to set it up.

Where the exam catches people

  • --output-format json alone does not fix the shape of the answer; the schema-checked data is in structured_output only when you pass --json-schema.
  • --system-prompt replaces Claude Code's default instructions; use --append-system-prompt to add to them.
  • A plain claude -p run still loads the checkout's hooks and .mcp.json servers without a trust dialog; --bare is what stops that.
  • --continue picks the most recent conversation, so parallel runs should resume by session ID with --resume.

Written from Anthropic's documentation

Try 3 questions on this

Pick an answer to see why each option is right or wrong.

  1. Your continuous integration job runs claude -p inside each developer's checkout, and the results differ from machine to machine because some checkouts carry their own hooks, MCP servers and CLAUDE.md files. Every run needs to start from the same state. What's the correct approach to run Claude Code in an automated pipeline?

    Right. In the game that’s Renown for your Claude Code Configuration and Workflows building.

    Not that one: A is right. In the game your Claude Code Configuration and Workflows building would lose a little Renown, and this question would come back later.

  2. A release script calls claude -p to pull the changed public function names out of a diff, and it needs them as a JSON array rather than prose. You already pass --output-format json and read .result with jq, and the shape of that text changes from run to run, so the parser downstream keeps breaking. What's the most effective way to make the run return a machine-readable list?

    Right. In the game that’s Renown for your Claude Code Configuration and Workflows building.

    Not that one: C is right. In the game your Claude Code Configuration and Workflows building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    The pair turns a formatting request into a contract: if the schema itself is not valid, claude exits with Error: --json-schema is not a valid JSON Schema rather than quietly returning text.

    Written from code.claude.com/docs/en/headless.md

  3. Your review script pipes a pull request diff into claude -p, and you want every run to answer as a security engineer hunting vulnerabilities. Claude Code's default instructions still have to apply, and you would rather not keep a copy of them in the script. What's the most effective way to add that instruction?

    Right. In the game that’s Renown for your Claude Code Configuration and Workflows building.

    Not that one: D is right. In the game your Claude Code Configuration and Workflows building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    The documented example is exactly this shape — gh pr diff "$1" | claude -p --append-system-prompt "You are a security engineer. Review for vulnerabilities." --output-format json.

    Written from code.claude.com/docs/en/headless.md