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.