Study FAQ
How can I run Claude Code in CI with narrow permissions and verifiable output?
Also asked as 2
- What should I configure before running claude -p in an unattended CI job?
- How do I keep a non-interactive Claude Code workflow from waiting for approval or releasing unvalidated output?
Answer
Use claude -p for a non-interactive CI step and configure the permission mode and permitted actions before it runs. Use a dedicated CI identity, a minimal checkout and narrowly scoped credentials. A Manual-mode run denies a call that needs approval unless an authorized approval mechanism handles it. If you configure a permission host, set --permission-prompts none with Claude Code v2.1.259 or later to decline instead of waiting.
Use --allowedTools for narrowly scoped pre-approval. To restrict available built-in tools, use --tools and review other sources of tools, including MCP servers and plugins, as well as deny policy and the shell sandbox. Bound wall-clock time and cost. If you use --output-format json with --json-schema, check that structured_output exists, validate it before consumption, and treat both generated content and tool output as untrusted input. Run required checks separately. A run can end without structured output.
Store the revision, effective configuration, workflow identifier, elapsed time, sanitized output and check results as artifacts. Fail the CI job explicitly if a required check or artifact is missing. Give merge or release privileges to an independently validated stage with its own identity. This keeps a generated recommendation from granting permission to deploy.
Claude Code non-interactive runs · Claude Code CLI flags · Claude Code permission rules
Full explanation
Claude Code Hooks, Plan Mode, Automation, and CI Workflows
Study guide · CCAR-F
Read the full explanation