CertSafari
    Anthropic Claude Certified Developer – Foundations (CCDV-F)· Lessons

    Domain 2 · Lesson 7/25

    Claude Code in the SDLC: CI, automated review and refactoring

    Software Engineering Foundations

    17 min read
    5.52% of exam
    8 sources
    Published 17 Nov 2026
    Docs as of 11 Nov 2026

    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:

    A headless commit, with only four git command families pre-approvedbash
    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 *)"

    Checkpoint 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?

    Sources12

    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.

    Tool hooks and the audit job each one fits
    Hook eventWhat triggers itAudit use
    PreToolUseTool call request (can block or modify)Record the intended change before Edit or Write puts it on disk
    PostToolUseTool execution resultLog file changes to an audit trail after the change lands
    PostToolUseFailureTool execution failureLog 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?

    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?

    Sources34

    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:

    Ways to have Claude review a change
    OptionWhat starts a reviewWhere it runsWho can use it
    Code ReviewPull request activity, or an @claude review commentAnthropic infrastructureTeam or Enterprise organizations with GitHub repositories
    /code-reviewYou run the command on your branchYour Claude Code sessionAnyone, on any plan
    UltrareviewYou start it from Claude CodeA cloud sandboxRequires signing in with a claude.ai account
    Claude in your own CI (GitHub Actions or GitLab CI/CD)Pipeline events, such as every pull requestYour own CI runnersAnyone with a Claude API key or cloud provider credentials
    Your own reviewer, as a subagent or skillYou or Claude invoke it during a sessionWherever you run Claude CodeAnyone 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.

    Review steps of a pull_request workflow: plugin-based review, allowed only to post inline commentsyaml
        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:

    A custom security review of a PR diff, emitted as JSONbash
    gh pr diff "$1" | claude -p \
      --append-system-prompt "You are a security engineer. Review for vulnerabilities." \
      --output-format json

    Checkpoint 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.

    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)

    0 of 3 selected

    Sources54

    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:

    A Stop hook that keeps Claude working until the typecheck passesjson
    {
      "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" }
            ]
          }
        ]
      }
    }

    Checkpoint 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?

    Sources647

    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. 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. 2.Build the gap inventory of places the rulebook's defaults won't cover
    3. 3.Write the rulebook for how code translates between the languages
    4. 4.Validate the judge: confirm it passes on the original code and fails on deliberately broken code
    5. 5.Rewrite the external-facing tests as assertions that run against both the original and the port

    Sources68

    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. 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. 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. 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. 1.
      “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. 2.
      “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. 3.
      “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. 4.
      “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. 5.
      “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. 6.
      “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. 7.
      “Perform fast file pattern matching using glob patterns”
      ↩︎ Refactoring in small, verified increments
      “Perform string replacement in a file”
      ↩︎ Exam trap 4
    8. 8.
      “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

    Ready to test yourself?

    Practise the 9 questions on this subdomain.

    Spotted a mistake, or was something unclear? Tell us.