What you will be able to do
- Run Claude Code as a scoped, non-interactive CI step that commits, reviews or comments on pull requests
- Choose PreToolUse or PostToolUse hooks to keep an audit trail of agent edits
- Set up automated pull request review and keep its findings focused on correctness
- Refactor in small, test-verified steps and split a large migration into parallel batches you can verify
1.Branches, commits and pull requests with Claude Code
Claude Code works inside your normal git loop. In an interactive session you can ask it to summarize your changes, then say create a pr, then ask it to improve the description with more context. In CI the same agent runs without a terminal through Headless mode (claude -p) and streaming output, which is what lets it run as a pipeline step.
Commits happen only when you ask for one. Claude Code does not commit after every edit. You request a commit in the prompt and pre-approve only the git commands that task needs:
claude -p "Look at my staged changes and create an appropriate commit" \
--allowedTools "Bash(git diff *),Bash(git log *),Bash(git status *),Bash(git commit *)"On a locked-down CI runner, --permission-mode dontAsk denies every call that would otherwise prompt. Calls covered by your --allowedTools entries still run. When a later step needs to read the output, --output-format json returns structured JSON with the result, the session ID and metadata. jq -r '.result' extracts the text, and --resume "$session_id" continues the same session in a later step.
On GitHub, the Claude Code GitHub Action packages this setup. Running /install-github-app installs the Claude GitHub App, adds an ANTHROPIC_API_KEY or CLAUDE_CODE_OAUTH_TOKEN secret, and opens a pull request that adds the workflow. The action has two modes. In interactive mode it waits for an @claude mention in an issue or pull request comment. In automation mode, a prompt input makes it run on the event itself. Two checks limit who can start a run: on issue and pull request events the triggering user needs write access, and bot actors are rejected unless you list them in allowed_bots, so bots cannot trigger Claude in a loop.
Checkpoint 1 of 9· Fill the gap
This headless CI step should let Claude inspect staged changes and commit them, with only these four git command families pre-approved. Which flag completes it?
claude -p "Look at my staged changes and create an appropriate commit" \
? "Bash(git diff *),Bash(git log *),Bash(git status *),Bash(git commit *)"--allowedTools pre-approves the listed tool patterns. Here that means only the git diff, log, status and commit commands, so the commit runs without a prompt and nothing else is approved. --permission-mode takes a mode such as dontAsk rather than a list of commands. --output-format and --resume control the output and the session, not permissions.
Source: code.claude.comCheckpoint 2 of 9· Check yourself
You want the Claude Code GitHub Action to run on every newly opened pull request, without anyone posting a comment. What makes it do that?
With no prompt input, the action is in interactive mode and waits for an @claude mention. A prompt input switches it to automation mode, where it runs on the event itself. allowed_bots lists bot actors, not events. dontAsk controls which tool calls are denied, not what starts a run.
“Automation mode: when the workflow provides a prompt input, Claude runs without waiting for a mention”Source: code.claude.com
2.An audit trail for agent edits
Git history records what was committed, not every edit an agent made along the way. When compliance requires every file change to be traceable, use hooks. Hooks are callbacks the Agent SDK runs at fixed points in the agent loop, and matchers decide which tools trigger them. The general mechanics of hooks are covered in Claude Hooks. For an audit trail, the choice is about timing.
| Hook event | What triggers it | Audit use |
|---|---|---|
| PreToolUse | Tool call request (can block or modify) | Record the intended change before Edit or Write puts it on disk |
| PostToolUse | Tool execution result | Log file changes to an audit trail after the change lands |
| PostToolUseFailure | Tool execution failure | Log edits that were attempted and failed |
If the requirement says the log entry must exist before the change reaches disk, use PreToolUse with a matcher limited to the Edit and Write tools. If the requirement is to record what actually changed, use PostToolUse on the same tools. Three other options look plausible but don't do this job. acceptEdits only lets Claude write files without prompting; it keeps no log. A commit happens only when something runs git commit. A subagent starts with a fresh context and never sees the main agent's tool calls, so it cannot watch and log them.
A pipeline that also has to reach an external system, such as a ticket tracker, connects through an MCP server, for example claude mcp add --transport http notion https://mcp.notion.com/mcp. Building those servers is covered in MCP Server Development.
Checkpoint 3 of 9· Check yourself
A compliance rule says each file change the agent makes must be logged before it reaches disk. A teammate suggests running the agent with --permission-mode acceptEdits to meet the rule. What is wrong with that suggestion?
acceptEdits is a permission mode. It removes the approval prompt for file writes but records nothing. When the log entry must exist before the change reaches disk, use a PreToolUse hook matched to Edit and Write. A subagent cannot do this job because it starts with a fresh context and never sees the main agent's tool calls.
“acceptEdits: Claude writes files without prompting, and Claude Code auto-approves common filesystem commands such as mkdir, touch, mv, and cp.”Source: code.claude.com
Checkpoint 4 of 9· Exam question
A team wants every file edit that an autonomous coding agent makes to be recorded in a version-control-friendly audit log before the change is written to disk, so that the change history stays traceable alongside normal git commits. Which Agent SDK mechanism should they use?
Correct answer: A — Register a PreToolUse hook matched to the Edit and Write tools that appends the intended change to the audit log before the tool executes
- A. Correct. A PreToolUse hook matched on Edit and Write runs custom logic, such as appending to an audit file, before the tool executes, which is exactly the interception point needed.
- B. Incorrect. The SDK does not automatically create git commits for tool calls; commits only happen if the agent or a hook explicitly runs git commands.
- C. Incorrect. acceptEdits only controls whether edit-type tool calls are auto-approved without a prompt; it does not produce any audit logging on its own.
- D. Incorrect. A subagent with no tools cannot observe tool calls made by a separate agent context; hooks, not passive subagents, are the interception mechanism.
3.Automated pull request review
Before setting up automated review, decide where it runs and what starts it. The options range from a managed service to a reviewer you write yourself:
| Option | What starts a review | Where it runs | Who can use it |
|---|---|---|---|
| Code Review | Pull request activity, or an @claude review comment | Anthropic infrastructure | Team or Enterprise organizations with GitHub repositories |
| /code-review | You run the command on your branch | Your Claude Code session | Anyone, on any plan |
| Ultrareview | You start it from Claude Code | A cloud sandbox | Requires signing in with a claude.ai account |
| Claude in your own CI (GitHub Actions or GitLab CI/CD) | Pipeline events, such as every pull request | Your own CI runners | Anyone with a Claude API key or cloud provider credentials |
| Your own reviewer, as a subagent or skill | You or Claude invoke it during a session | Wherever you run Claude Code | Anyone who writes one |
The managed Code Review runs in four stages: several agents examine the diff and the surrounding code in parallel, a verification step filters out false positives, the remaining findings are deduplicated and ranked by severity, and the results are posted. It reads code without building or running it. Its access to the repository is read-only, and it never pushes commits. Findings appear as inline comments plus a check run named Claude Code Review. That check run never concludes as a failure, so it informs reviewers rather than blocking a merge. Its instructions come from REVIEW.md on the base or default branch, never from the pull request's own changes, so a pull request cannot weaken its own review. Draft and fork pull requests are skipped. You can choose the depth: Quick, Standard (the default) or Deep.
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 1
- uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
plugin_marketplaces: "https://github.com/anthropics/claude-plugins-official.git"
plugins: "code-review@claude-plugins-official"
prompt: "/code-review:code-review --comment ${{ github.repository }}/pull/${{ github.event.pull_request.number }}"
claude_args: '--allowedTools "mcp__github_inline_comment__create_inline_comment"'This workflow runs on pull_request events (opened, synchronize, ready_for_review, reopened). Its permissions for contents, pull requests and issues are read-only, and the one tool claude_args allows is the one that posts inline comments. Because the prompt input is set, the action runs in automation mode and doesn't wait for an @claude mention.
Three habits keep reviews focused and actionable. First, have someone who didn't write the code do the review. /code-review reviews the diff in a fresh subagent that never saw your conversation, so the reasoning that produced the code can't sway it. Second, give it a narrow brief, such as checking the diff against a spec and reporting gaps that affect correctness while skipping style. Third, in a custom headless review, assign a role and request JSON so the next CI step can parse the result:
gh pr diff "$1" | claude -p \
--append-system-prompt "You are a security engineer. Review for vulnerabilities." \
--output-format jsonCheckpoint 5 of 9· Match them up
Your team is comparing four ways to have Claude review changes before merge. Match each option to where it runs and what it requires.
Tap a term, then the definition that fits it.
The managed Code Review is the only option that runs on Anthropic infrastructure, and it is limited to Team and Enterprise organizations. /code-review runs locally in your session on any plan. Ultrareview runs in a cloud sandbox and needs a claude.ai sign-in. A CI setup runs on your own runners using your API key or cloud credentials.
“Code Review | Pull request activity, as each repository is set, or an @claude review comment | Anthropic infrastructure”Source: code.claude.com
Checkpoint 6 of 9· Exam question
A platform architect is mapping SDLC stages to the correct Agent SDK or API feature for a pipeline that must run automated code review, enforce a version-control audit trail, and connect to an external ticketing system as part of the workflow. Which pairings correctly match each SDLC need to the right feature? (Select 3)(Select 3)
Correct answers: A, B, C — Automated code review of changed files is delegated to a subagent defined with a description and prompt scoped to review, invoked via the Agent tool; A version-control audit trail is produced by a PostToolUse hook on Edit and Write that appends each modified file path to a log after the change lands; Connecting to the external ticketing system is handled through MCP, which links the agent to external systems such as APIs and databases via existing servers
- A. Correct. Subagents are the documented pattern for delegating a focused review subtask with a scoped description and prompt.
- B. Correct. A PostToolUse hook on Edit and Write runs after the change lands on disk, matching the requirement to log the modified path for an audit trail.
- C. Correct. MCP is documented as the way to connect an agent to external systems such as APIs, which covers linking to a ticketing system.
- D. Incorrect. The Files API manages document and asset uploads; it is not documented as a code review mechanism for pull request diffs.
- E. Incorrect. Hooks are not documented as incompatible with git workflows; PostToolUse hooks are in fact a documented way to log file changes made via tools like Bash running git commands.
- F. Incorrect. The Memory tool stores information across conversations locally; MCP, not the Memory tool, is documented for reaching external REST APIs.
4.Refactoring in small, verified increments
A safe refactor follows a fixed loop: find the target, get a recommendation, apply it without changing behaviour, then run the tests. In Claude Code that is four prompts: find deprecated API usage in our codebase, then a request for suggestions on one file, then refactor utils.js to use ES2024 features while maintaining the same behavior, then run tests for the refactored code. Keep each step small enough to test on its own. When the suite fails, the cause is then the last small change, not one of fifty. Where callers depend on the old interface, say in the prompt that the change must stay backward compatible.
Choose the tool that matches the size of the change. Renaming one variable inside one function is a job for Edit, which performs string replacement in a file and leaves the rest of the file untouched. Write produces a whole file, which is the wrong tool for a one-line change. Glob only matches file paths against patterns; it can find files but cannot change their contents.
Every increment needs a check that confirms it. The lightest option is a line in the prompt: run the tests after the change and keep going until they pass. To have the harness enforce the check, add a Stop hook. It runs your script whenever Claude tries to end its turn and sends Claude back to work if the script exits with code 2:
{
"hooks": {
"Stop": [
{
"hooks": [
{ "type": "command", "command": "pnpm tsc --noEmit 1>&2 || exit 2" }
]
}
]
}
}Checkpoint 7 of 9· Fill the gap
During a refactor, Claude should not be able to end its turn until the typecheck passes, and the harness rather than the prompt should enforce this. Which hook event belongs in the blank?
{
"hooks": {
" ? ": [
{
"hooks": [
{ "type": "command", "command": "pnpm tsc --noEmit 1>&2 || exit 2" }
]
}
]
}
}A Stop hook runs whenever Claude tries to end its turn. If the script exits with code 2, Claude goes back to work, so the turn cannot end while the typecheck fails. PreToolUse, PostToolUse and PostToolUseFailure fire around individual tool calls, not when the turn ends.
Source: code.claude.comCheckpoint 8 of 9· Exam question
A developer asks an Agent SDK-powered assistant to perform a small, localized refactor: renaming a single poorly named variable within one function in utils.py. Which built-in tool is the most appropriate for making this precise, targeted change?
Correct answer: A — The Edit tool, since it is designed for making precise edits to existing files without rewriting unrelated content
- A. Correct. The Edit tool is documented for making precise edits to existing files, which matches a small, localized rename inside one function.
- B. Incorrect. Write creates or fully overwrites files; using it for a single variable rename risks discarding unrelated content and is not the tool built for precise edits.
- C. Incorrect. Bash runs terminal commands and scripts; it is not the documented precise-edit tool, even though a shell command could technically perform text replacement.
- D. Incorrect. Glob only finds files by pattern; it has no capability to modify file contents.
5.Large migrations as parallel, verifiable batches
Porting a whole codebase to a new language is too large for one loop of small edits. The work has to be split into batches that agents can run in parallel and that you can check independently. Anthropic's approach starts from one principle: when the output is wrong, you don't patch the code. You fix the process (the loop) that produced it.
Start by building the judge. A migration has no exit condition until you can test the original and the port on equal terms. Original-language test suites often depend on internal functions that won't exist in the port, so first sort the tests into those that can call the code from outside and those that can't, then rewrite the external ones as assertions that run against both versions. Validate the judge in two directions: it must pass on the original code, and it must fail on deliberately broken code.
Next comes the plan. Write a rulebook for how code translates, then a gap inventory of the places the rulebook's defaults won't cover, then a dependency map that orders the workstreams. The dependency map is what lets independent batches run at the same time. Locally, give each parallel batch its own worktree so concurrent edits don't collide, and put a gate between stages. Mike Krieger's Python-to-TypeScript port used hundreds of agents, eight phase gates, three adversarial review rounds and a final parity check against the Python original.
The Bun port from Zig to Rust shows what this produces at scale: a million lines in under two weeks, with 100% of the existing test suite passing in CI before merge. Nineteen regressions surfaced after merge, and all were fixed. It cost roughly $165,000 at API pricing. Because all of this happens on a branch, the worst case is deleting the branch and trying again.
Checkpoint 9 of 9· Put it in order
A team is preparing to port a large service to a new language with parallel agents. Put their preparation steps in the order the migration process requires.
- 1.Sort the existing tests into those that can call the code from outside and those that depend on internals the port won't have
- 2.Build the gap inventory of places the rulebook's defaults won't cover
- 3.Write the rulebook for how code translates between the languages
- 4.Validate the judge: confirm it passes on the original code and fails on deliberately broken code
- 5.Rewrite the external-facing tests as assertions that run against both the original and the port
The judge comes first because without it the migration has no exit condition. It is built by categorizing tests, rewriting the portable ones and then validating it in both directions. Planning comes next, and the gap inventory can only follow the rulebook because it is defined by what the rulebook's defaults don't cover.
“A prerequisite before starting on your migration project is to have a strong judge in place, otherwise you won’t have an exit condition”Source: claude.com
Practise it for real
Run a headless security review of a pull request diff and continue the same review in a second CI-style step.
1.In a repository with an open pull request, set PR_NUMBER to that pull request's number, then run: gh pr diff "$PR_NUMBER" | claude -p --append-system-prompt "You are a security engineer. Review for vulnerabilities." --output-format json > review.json
Why: The diff arrives on stdin, the appended system prompt narrows the review to security, and JSON output gives the next step something it can parse.
You should see: review.json holds one JSON object that includes a result field and a session_id.
2.Run: jq -r '.result' review.json
Why: A pipeline step extracts the text before posting or storing it.
You should see: The review findings print as plain text.
3.Run: claude -p "Now list only the findings that affect correctness" --resume "$(jq -r '.session_id' review.json)"
Why: Resuming by session ID continues the same review in a later step instead of starting from scratch.
You should see: A shorter list that refers back to the first review's findings.
Stuck? Get a nudge
If the second step seems to know nothing about the diff, check that you passed the session_id from review.json, not an empty string.
Sources
(8)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.https://code.claude.com/docs/en/headlessOfficial docs
“dontAsk: Claude Code denies every call that would otherwise prompt, which is useful for locked-down CI runs”
↩︎ Branches, commits and pull requests with Claude Code“json: structured JSON with result, session ID, and metadata”
↩︎ Branches, commits and pull requests with Claude Code“acceptEdits: Claude writes files without prompting”
↩︎ Exam trap 1“acceptEdits: Claude writes files without prompting, and Claude Code auto-approves common filesystem commands such as mkdir, touch, mv, and cp.”
↩︎ Checkpoint - 2.https://code.claude.com/docs/en/github-actionsOfficial docs
“Automation mode: when the workflow provides a prompt input, Claude runs without waiting for a mention”
↩︎ Branches, commits and pull requests with Claude Code“rejects a bot actor unless you list it in allowed_bots, which keeps bots from triggering Claude in a loop”
↩︎ Branches, commits and pull requests with Claude Code“Without it, Claude posts nothing, and you read the findings in the workflow run log.”
↩︎ Prediction - 3.https://code.claude.com/docs/en/agent-sdk/hooksOfficial docs
“Tool call request (can block or modify)”
↩︎ An audit trail for agent edits“Log file changes to an audit trail”
↩︎ An audit trail for agent edits - 4.https://code.claude.com/docs/en/best-practicesOfficial docs
“reviews the diff in a fresh subagent that never saw your conversation”
↩︎ An audit trail for agent edits“claude mcp add --transport http notion https://mcp.notion.com/mcp”
↩︎ An audit trail for agent edits“report gaps that affect correctness and skip style”
↩︎ Automated pull request review“sends Claude back to work if the script exits with code 2”
↩︎ Refactoring in small, verified increments - 5.https://code.claude.com/docs/en/code-reviewOfficial docs
“Verify: a verification step checks the candidate findings against the code and filters out false positives.”
↩︎ Automated pull request review“a review works from reading the diff and the surrounding code, without building or running your code.”
↩︎ Automated pull request review“REVIEW.md from the base or default branch and never from the pull request’s own changes.”
↩︎ Exam trap 2“The check run doesn’t conclude as a failure.”
↩︎ Exam trap 3“Code Review | Pull request activity, as each repository is set, or an @claude review comment | Anthropic infrastructure”
↩︎ Checkpoint - 6.https://code.claude.com/docs/en/common-workflowsOfficial docs
“Do refactoring in small, testable increments”
↩︎ Refactoring in small, verified increments“Request that changes maintain backward compatibility when needed”
↩︎ Refactoring in small, verified increments“Run parallel sessions with worktrees so concurrent edits”
↩︎ Large migrations as parallel, verifiable batches - 7.
“Perform fast file pattern matching using glob patterns”
↩︎ Refactoring in small, verified increments“Perform string replacement in a file”
↩︎ Exam trap 4 - 8.https://claude.com/blog/ai-code-migrationSecondary source
“A prerequisite before starting on your migration project is to have a strong judge in place”
↩︎ Large migrations as parallel, verifiable batches“a dependency map to order our migration implementation workstreams”
↩︎ Large migrations as parallel, verifiable batches“with 100% of Bun's existing test suite passing in CI before merge”
↩︎ Large migrations as parallel, verifiable batches“You fix the process (loop) that produced the code.”
↩︎ Large migrations as parallel, verifiable batches“A prerequisite before starting on your migration project is to have a strong judge in place, otherwise you won’t have an exit condition”
↩︎ Checkpoint