9. Headless and CI

9 cards

Review this deck
All cards in this deck

`claude -p`

Runs non-interactively, prints the result and exits; exit 0 on success.

`--output-format json` + `--json-schema`

Structured JSON output in the `structured_output` field; check the field is present before using it.

`--allowedTools`

List of tools usable without asking, in permission rule syntax, e.g. `"Bash(git diff *),Read"`.

`--bare`

Skips auto-loading hooks, skills, subagents, plugins, MCP, auto memory, CLAUDE.md; recommended for CI and scripts; needs `ANTHROPIC_API_KEY`.

Running `claude -p` on an untrusted repo

Use `--bare` or `--setting-sources user`, because without `--bare` the repo's hooks and `.mcp.json` run without going through trust.

Headless run limits

`--max-turns` limits turns; `--max-budget-usd` limits budget; JSON output has an estimated `total_cost_usd`.

Claude Code GitHub Actions

`anthropics/claude-code-action@v1`; without `prompt` it responds to `@claude`, with `prompt` it runs automatically on events.

Quick GitHub Actions install

Run `/install-github-app` in Claude Code (needs a logged-in GitHub CLI and repo admin rights).

Controlling GitHub Actions

Key in GitHub Secrets, only users with write access can trigger, block bots, `--max-turns`, `timeout-minutes`, minimal permissions, review PRs like human code.

9. Headless and CI – Flashcards – Claude | Học Dev