This resume is also available in English.

8. Security and working with AI3 / 7 · All columns

Columns › 8. Security and working with AI › Part 33

Bringing AI Workflows into the Team Process: PR Review, CI and Human Gates

AI 工作流接進團隊流程:PR 審查、CI 與人工把關

Fit AI agents into a team's development lifecycle from ticket to pull request: what AI may do and what only humans or automated gates decide, with CI checks, branch protection, least-privilege tokens and versioned prompts, and how to measure the effect honestly.

  • AI
  • Claude Code
  • CI
  • Code Review
In this article
  1. What this article solves
  2. Step 1: First map where AI sits in the development lifecycle
  3. Step 2: Tickets and planning — write requirements so both AI and people can verify them
  4. Step 3: Required CI gates — AI output must pass the same checks as code people write
  5. Step 4: Add AI review to CI — suggestions only, no power to decide
  6. Step 5: Human gates — branch protection, CODEOWNERS and "whoever merges is responsible"
  7. Step 6: Prompts are code too — in the repo, versioned and reproducible
  8. Step 7: Measure the effect honestly
  9. Step 8: Team guidelines and a go-live checklist
  10. Common pitfalls
  11. Key takeaways
  12. Next

In the previous article, “Building Go Microservices with Claude Code: Rules, Permissions and Security Review”, we looked at how one person can use an AI agent safely on their own computer: CLAUDE.md, permission rules, hooks, subagents and a test-first workflow. This article widens the scope to the whole team: when anyone might hand in code that was partly written by AI, how should PRs, CI and the review process change?

What this article solves

When one person uses an AI agent, a mistake affects their own branch; when a whole team uses it, faulty code reaches the main branch and production and affects everyone. Teams adopting AI tend to fall into one of two extremes: either nobody manages it at all, everyone works their own way, and reviewers have no idea how a piece of code came about; or people trust it too much, letting AI review replace human review, or letting AI automatically merge PRs that "look fine".

This article builds the middle road, answering these questions:

  • Along the line "ticket → planning → coding → testing → review → merge", where does AI fit?
  • How do you set up AI review in CI? What can it decide, and what can it not?
  • Which gates must be machine rules (tests, go test -race, govulncheck, lint), and which must be people?
  • How much access should the token used by AI in CI have? What can go into a prompt, and what can't?
  • How do you version prompts like code so that results can be reproduced?
  • How do you measure the effect of adopting AI honestly, rather than going on gut feeling or making numbers up?
  • When code written by AI goes wrong, who is responsible?

This article covers only the development side — from ticket to merge. Deployment automation and troubleshooting in production are left for the next article. The examples continue with the shop system (example.com/shop) repo, and CI is shown with GitHub Actions; the ideas apply equally to other CI systems.

Step 1: First map where AI sits in the development lifecycle

List every stage a ticket goes through from start to merge, and ask of each one: what does this step produce? Who notices when it goes wrong? Is AI here "producing a draft" or "making a decision"?

Ticket Plan AI drafts, a human decides Code and tests local agent, on a branch Open a PR state what AI helped with Required CI gates (block merging) gofmt, go vet, go test -race govulncheck, integration tests decided by machines, not by AI AI review (suggestions only) read-only access, versioned prompt comments or writes to the run log cannot approve, cannot merge Human approval CODEOWNERS, branch protection Merge → deploy whoever merges owns the code

Figure: AI appears mainly in planning, coding and review suggestions; what decides whether to merge is the required CI gates and human approval.

StageWhat AI can doWho decidesHow errors are found
TicketTurn a vague request into acceptance criteria, list unclear pointsProduct owner and engineersPlanning meeting
PlanningRead the code, find what to change, propose an approach and risksThe engineer who owns the ticketPlan review (the output of plan mode)
CodingWrite table-driven tests first, then the implementationThe engineer decides whether to acceptTests, CI
TestingAdd edge cases, write integration testsEngineer and reviewerReview checks the tests cover the request
ReviewPoint out likely bugs, security problems and omissionsHuman reviewerThe reviewer verifies each item
MergeNot involvedCI gates + human approvalBranch protection

The key to this table is the "Who decides" column: not one row says AI. AI's role is to make the drafts at each stage arrive faster and more complete, while every decision point has a clearly responsible person or machine rule. This matches the principle from the previous article: what AI writes is drafts and leads, not conclusions.

AI can do (drafts and suggestions) • Break a ticket into steps, list the risks • Write table-driven tests, then the code • Point out likely bugs and holes in a diff • Explain why CI failed • Write the PR description, update docs • Draft migrations for a human to check Only humans (or rules) decide • Approve and merge PRs • Deploy to production, roll back • Change permissions, secrets, branch protection • Judge whether a security finding is real • Run database migrations in production • Whether tests are "enough": coverage and review

Figure: on the left are the drafts and suggestions AI can produce; the decisions on the right can only be made by people, or by explicit machine rules.

Writing this boundary into the team's development guidelines matters more than any tool setting. When the boundary is unclear, what usually happens is "diffusion of responsibility": the author assumes the AI reviewed it, the AI review assumes someone will look, the reviewer assumes CI will block it, and in the end nobody has actually read that code.

Step 2: Tickets and planning — write requirements so both AI and people can verify them

Where AI agents go wrong most easily isn't the coding itself but understanding the requirement. Given a ticket that only says "cancelling an order should release stock", a person will ask about the details, while AI will often just pick an interpretation that looks reasonable. So after adopting AI, ticket quality matters even more. A good ticket has at least:

  • Background and goal: why it is being done, and what will be different for users or the system afterwards.
  • Acceptance criteria: concrete conditions that can be turned straight into tests. For example, "after a pending order is cancelled its status is cancelled and an OrderCancelled event is emitted", "a paid order cannot be cancelled directly; return 409", "someone else's order returns 404".
  • Out of scope: say explicitly what is not being done. For example, "this ticket does not handle refunds; refunds get a separate ticket". This line is very effective at stopping AI from changing a pile of unrelated things "while it's at it".
  • Relevant locations: the services and files already known to need changes, such as internal/order/service.go and internal/inventory/.

What AI can help with at this step is "making the draft complete": give it the ticket and the code, ask it to list unclear points and possible edge cases, and have a person answer them. The planning stage uses the plan mode from the previous article: it reads the code and proposes which files to change and how to verify, and a person reviews the plan before work starts. The plan can be pasted straight into the ticket or the PR description, so the reviewer knows how the author originally intended to do it and can more easily spot where the implementation drifted.

Tip: when acceptance criteria are concrete enough, each one becomes a row of a table-driven test. That makes the "tests first, then implementation" flow feel natural, and reviewers can check the tests against the acceptance criteria row by row.

Step 3: Required CI gates — AI output must pass the same checks as code people write

Whoever wrote the code, it must pass the same set of machine rules before reaching the main branch. These gates are deterministic: the same code gets the same result every time, and nothing gets through because it "looks reasonable". For Go services, the basic set is:

GateWhat it blocksRelated articles
No output from gofmt -l .Inconsistent formatting“Go Project Layout and Go Modules”
go vet ./...Common mistakes: format strings, copied locks, unreachable code
go test -race ./...Functional bugs, data races“Testing in Go: Table-Driven Tests, httptest and Integration Tests”, “Concurrency Pitfalls: From Data Races to Overselling”
Integration testsInteraction with the database and message queue“Deploying a Whole Microservice System with Docker Compose”
govulncheck ./...Calls into code with known vulnerabilities“Microservice Security: Authentication, Authorisation, Secrets and Supply Chain”
lint (e.g. staticcheck)More static problems and style rules

-race is especially important here. Concurrent code written by AI often "looks right": there are goroutines, channels and mutexes, but one shared variable is left unprotected. Errors like this usually don't show up in ordinary tests; only the race detector catches them. Likewise, govulncheck stops old versions of dependencies that AI pulled in to solve a problem.

These gates should be set as required status checks in branch protection: no merge without passing, no exceptions. If the team is used to "CI failed but I'm sure it's fine, merge now and sort it out later", adopting AI amplifies the problem, because code is produced faster and more checks get skipped.

AI also has a practical role at this step: explaining failures. When CI fails, handing the error log to AI and asking it to analyse the cause and possible fixes is often faster than reading it yourself from the start. But the fix still goes through the same process: on a branch, CI re-run, reviewed. Never loosen a gate to get AI's change through — for example by deleting a failing test, adding //nolint or removing -race. When you see a change like that in review, ask why in particular.

Step 4: Add AI review to CI — suggestions only, no power to decide

AI review can run automatically when a PR is opened or updated, taking a first pass before human review. Anthropic provides Claude Code GitHub Actions (anthropics/claude-code-action), which runs Claude Code inside a workflow. According to the official documentation it has two modes: without a prompt it runs in interactive mode, waiting for someone to mention @claude in an issue or PR comment; with a prompt it runs in automation mode, executing directly on the triggering event, and by default the result is written to the workflow run log. Running /install-github-app in Claude Code guides you through installing the GitHub App and setting up the secret; there is also an official Code Review feature that doesn't require you to maintain a workflow file yourself.

The workflow below puts two things together: checks are the required machine gates; ai-review is the AI review, with read-only access, giving suggestions only. It calls the repo's /review-go skill (Step 6), so that local runs and CI use the same review prompt:

name: ci
on:
  pull_request:
    branches: [main]

permissions:
  contents: read

jobs:
  checks:
    runs-on: ubuntu-latest
    timeout-minutes: 20
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-go@v5
        with:
          go-version-file: go.mod
      - name: gofmt
        run: test -z "$(gofmt -l .)"
      - name: vet
        run: go vet ./...
      - name: test (race)
        run: go test -race ./...
      - name: govulncheck
        run: go run golang.org/x/vuln/cmd/govulncheck@latest ./...

  ai-review:
    # Skip drafts; PRs from forks get no secrets, so skip them too
    if: >-
      github.event.pull_request.draft == false &&
      github.event.pull_request.head.repo.full_name == github.repository
    runs-on: ubuntu-latest
    timeout-minutes: 15
    permissions:
      contents: read
      pull-requests: read
      issues: read
      id-token: write
    steps:
      - uses: actions/checkout@v6
        with:
          fetch-depth: 0
      - uses: anthropics/claude-code-action@v1
        with:
          anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
          prompt: '/review-go ${{ github.event.pull_request.base.sha }}'
          claude_args: >-
            --max-turns 15
            --allowedTools "Read,Grep,Glob,Bash(git diff *),Bash(git log *)"

A few design decisions:

  • The top-level permissions: contents: read gives every job read-only access by default; a job that needs more declares it itself. The id-token: write on ai-review is required by this Action's default GitHub App authentication (per the official example); it has no contents: write, so it cannot push code.
  • --allowedTools gives only file reading, search, git diff and git log. In automation mode, tool calls that aren't allowed and would need approval are refused, so it can't run arbitrary commands or change files.
  • --max-turns and timeout-minutes limit how much time and money a single review can spend, preventing runaway runs.
  • The if condition: draft PRs aren't reviewed; PRs from forks get no secrets in a public repo, so it simply doesn't run. Never switch to pull_request_target and check out the PR's code in order to review fork PRs — that amounts to running code sent by anyone in an environment that has secrets.
  • ai-review is not a required check. If it fails or times out, that shouldn't block the merge; its results are for the reviewer's reference. Only checks is required.

If you want review results to appear directly as comments on the PR, you need to give it commenting tools and the pull-requests: write permission; the official documentation's example does this through the code-review plugin and the corresponding MCP tools. For every permission you add, think through "if it is influenced by prompt injection in the PR content, what is the worst it can do?". The worst case for something that can only comment is a misleading comment; the worst case for something that can push code is far more serious.

The Actions in the example use version tags for readability; in a real repo, third-party Actions should be pinned to a commit SHA, with an automated tool regularly opening PRs to update them — an extension of the supply-chain step in the previous article.

Step 5: Human gates — branch protection, CODEOWNERS and "whoever merges is responsible"

Machine gates block "things known to be wrong"; human review blocks "things machines don't know about": whether the requirement was misunderstood, whether the design is sound, whether the tests really cover the acceptance criteria, whether this change will affect other services. AI review can make human review more efficient, but it can't replace it.

The protection rules on the main branch should include at least:

  • Changes must be merged through a PR; no direct pushes.
  • Required checks (checks from Step 3) must pass before merging, and the branch must be up to date with the main branch.
  • At least one reviewer with the right access approves; the author's own approval doesn't count.
  • New commits dismiss earlier approvals (so nothing changes after approval).
  • Specific paths need review by specific people.

The last one is done with CODEOWNERS. For the shop system, amount calculation, authorisation, deployment configuration and CI itself should all have designated reviewers:

# .github/CODEOWNERS: changes to these paths must be approved by the designated owners
*                               @shop/backend
/internal/payment/              @shop/payments
/internal/order/service.go      @shop/payments @shop/security
/api/proto/                     @shop/api-owners
/deploy/                        @shop/platform
/.github/                       @shop/platform @shop/security
/.claude/                       @shop/platform @shop/security
/CLAUDE.md                      @shop/platform

Note the last two lines: .claude/ (permission settings, hooks, skills, subagents) and CLAUDE.md are protected too. They decide what the AI agent can do on everyone's computer and in CI, so changing them has as wide an impact as changing the CI configuration.

The most important rule in the team guidelines is: code written by AI is the responsibility of whoever merges it — more precisely, the PR author and the approver share responsibility, exactly as for hand-written code. The point of this rule is to give everyone a reason to read carefully: the author can't say "the AI wrote it", and the reviewer can't say "the AI already reviewed it". In practice you can add a disclosure and self-check section to the PR template:

## Changes

<!-- What this PR does and why; link the ticket -->

## How it was verified

- [ ] `go test -race ./...` passes (paste the summary)
- [ ] New or changed tests map to the ticket's acceptance criteria
- [ ] Methods that read or write orders have an owner check and a "someone else's order" test

## AI assistance

- [ ] This PR did not use an AI agent
- [ ] It did: scope was ______ (e.g. test drafts, implementation, PR description)
- [ ] I have read every line of AI-generated code and can explain every change
- [ ] Every AI review finding has been handled: confirmed and fixed, or explained why it doesn't hold

## Risk and rollback

<!-- Which services are affected, whether there is a database migration, how to roll back if something goes wrong -->

The point of disclosure isn't to treat AI-written code differently, but to tell reviewers what to pay particular attention to: for example, whether tests written by AI merely describe the implementation's behaviour, or whether there are changes beyond the scope of the ticket. The template also provides the marker needed for measuring in Step 7.

Step 6: Prompts are code too — in the repo, versioned and reproducible

If everyone asks AI for a review with their own prompt, the results can't be compared or improved. Storing the team's common prompts as files in the repo, reviewed through PRs just like code, means: everyone and CI use the same one, changes are recorded, and if results get worse you can look back at which change caused it.

The skills introduced in the previous article fit perfectly: put them in .claude/skills/<name>/SKILL.md, invoke them locally with /<name>, and in CI write /<name> in the prompt (provided the workflow checks out the repo first). The review prompt used in Step 4 is:

---
name: review-go
description: Review the Go changes on the current branch against the given base according to team guidelines; suggestions only, no edits
disable-model-invocation: true
argument-hint: '<base-ref>'
---

Review the changes in `git diff $ARGUMENTS...HEAD`. Read only: do not modify any file, and do not run any command other than tests.

First read CLAUDE.md to learn the project rules, then check in order:

1. Correctness: are errors swallowed? Is `context` passed down? Are timeouts and retries sensible?
2. Concurrency: is shared state protected? Can goroutines leak? Can a channel block forever?
3. Authorisation: do methods that read or write an Order compare the owner? Do admin functions check the role?
4. Data: is SQL parameterised? Are transaction boundaries correct? Are amounts int64 cents?
5. Tests: does new behaviour have table-driven tests? Were existing tests deleted or weakened?
6. Scope: are there changes unrelated to the PR description? Were dependencies added?

Output format:

- One paragraph per finding: severity (high / medium / low), file:line, the problem, why it is a problem, the suggested fix.
- Mark anything uncertain as "to be confirmed" and say what would need to be checked to be sure.
- If there are no findings, write "No problems found"; don't pad the list with style suggestions.
- Always end with this line: "The above are AI review suggestions and must be confirmed by a human reviewer."

Things to watch in prompts: no secrets of any kind (the prompt file is in the repo, visible to anyone who can read the repo, and it is sent to the model service when it runs); no personal data or production data; require a fixed output format so reviewers can skim it quickly and it is easy to tally later.

The same skill can also run locally in non-interactive mode. Running it yourself before opening a PR saves a round trip:

# Before opening a PR, review your own branch with the same skill as CI (non-interactive, read-only tools only)
claude -p "/review-go main" \
  --allowedTools "Read,Grep,Glob,Bash(git diff *),Bash(git log *)" \
  --output-format json | jq -r '.result'

# Measurement: the last 100 merged PRs, grouped by whether they carry the ai-assisted label, time from opening to merge (hours)
gh pr list --state merged --limit 100 --json number,createdAt,mergedAt,labels | jq -r '
  map({ai: any(.labels[]; .name == "ai-assisted"),
       hours: (((.mergedAt | fromdateiso8601) - (.createdAt | fromdateiso8601)) / 3600)})
  | group_by(.ai)[]
  | (map(.hours) | sort) as $h
  | "\(if .[0].ai then "ai-assisted" else "other" end)\tPRs=\(length)\tmedian≈\($h[length / 2 | floor]) hours"'

The second command is the measurement discussed in the next step. claude -p is Claude Code's non-interactive mode, and --output-format json puts the result in the result field. In CI or scripts, the official documentation suggests considering --bare, so it doesn't automatically load hooks, plugins and personal settings from the environment and results are consistent on every machine; but note that --bare also doesn't automatically load the project's skills, so you then need a flag such as --append-system-prompt-file to bring the prompt in.

Step 7: Measure the effect honestly

After adopting AI, teams often want to know "is it actually helping?". The question deserves a serious answer, because feelings are easily fooled: writing code faster is an obvious sensation, but if review takes longer and more defects appear after merging, things may not be better overall. A few principles for measuring:

Measure the whole process, not just the coding. Common metrics:

MetricHow to measureWhat it tells you
Lead timeFrom starting the ticket to merge (or to deployment)Whether things are faster overall
PR cycle timeFrom opening the PR to mergeWhether review has become a bottleneck
Review roundsNumber of "changes requested" per PRWhether AI-produced code needs more back-and-forth
PR sizeLines changedWhether PRs got too big to review because producing is easier
Defect rateBugs reported, rollbacks and hotfixes after merge, traced back to the PRWhether quality has dropped
CI failure rateShare of PRs whose first CI run failsWhether local verification is being skipped
AI review acceptanceShare of AI review findings that were confirmed and fixedWhether AI review is really useful, or noise

Get a baseline before comparing. Measure for a while before adopting (or on the part of the work that doesn't use it yet); otherwise there's nothing to compare against. The PR template and ai-assisted label from Step 5 are what make the data groupable; the gh command in the previous step shows the simplest grouped calculation.

Make sure the comparison is fair. PRs that use AI and PRs that don't may involve different kinds of task to begin with (for example, people tend to give the simple work to AI), so comparing averages directly leads to wrong conclusions. Compare similar kinds of work, look at trends rather than single numbers, and use the median rather than the mean (a few unusually long PRs skew the mean badly).

Don't make numbers up, and don't turn metrics into targets. A claim like "efficiency rose X% after adoption" has no place in any report unless it has a baseline, a comparison and an explanation of how it was measured. And once "lines of AI-produced code" or "number of PRs" becomes a target, people optimise for it, and the result is usually more, bigger and harder-to-review PRs. Metrics are for finding problems: for example, review time steadily getting longer suggests that PRs should be split smaller, or that the tickets given to AI need to be better.

Step 8: Team guidelines and a go-live checklist

Finally, gather everything above into guidelines the team can adopt directly. I suggest putting them in the repo's CONTRIBUTING.md or the team wiki and referencing them from CLAUDE.md, so people and AI read the same document:

  1. Responsibility: the PR author and approver are responsible for the merged code, however it was produced.
  2. Disclosure: the PR template states the scope of AI assistance, and the PR gets an ai-assisted label.
  3. Verification: the author must have run the tests themselves and be able to explain every change; code they can't explain isn't sent for review.
  4. Gates: required CI checks are never loosened to get AI's code through; deleting or weakening tests must be explained in the PR description.
  5. AI review: suggestions only; every finding is confirmed or explained away; it cannot approve or merge.
  6. Permissions: AI in CI has read-only access (or at most commenting as well); it cannot push or access production secrets.
  7. Secrets and data: no secrets, personal data or production data in prompts, conversations or tickets.
  8. Prompts as code: shared prompts live in .claude/skills/, and changes go through PRs and CODEOWNERS review.
  9. Scope: one PR does one thing; changes AI made "while it was at it" are split out or removed.

Before adopting, you can confirm with this checklist:

ItemDone
Main branch protection: PRs required, required checks, at least one approval, new commits dismiss approvals☐
Required checks include gofmt, go vet, go test -race, govulncheck☐
CODEOWNERS covers payments, authorisation, deployment, CI, .claude/ and CLAUDE.md☐
The AI job in CI has read-only access, --allowedTools, and limits on turns and time☐
PRs from forks never run in an environment with secrets☐
AI review is not a required check, and its results say "needs human confirmation"☐
Shared prompts are in the repo and reviewed☐
The PR template has AI-assistance disclosure and a self-check☐
There is baseline data from before adoption; lead time, review time and defect rate are reviewed regularly☐
The team guidelines state "whoever merges is responsible"☐

Common pitfalls

  • Letting AI review replace human review. AI review is an extra layer, not a substitute; it produces false positives and misses cross-service and requirement-level problems.
  • Making AI review a required check. Its results aren't deterministic; it will block legitimate PRs and push people to "keep the AI happy" rather than make the code correct.
  • Giving AI in CI write access. It reads PR content, and PR content may contain prompt injection; an AI that can push code is push access that someone else can control remotely.
  • Using pull_request_target to review fork PRs and checking out their code. That runs untrusted code in an environment with secrets.
  • Loosening CI to get AI's changes through. Deleting tests, adding nolint, removing -race: the problems are just hidden.
  • Prompts scattered across everyone's computers. The results can't be compared or improved; put them in the repo and version them.
  • Pasting secrets and production data into prompts or tickets. This content is sent to an external service and also stays in the logs.
  • Measuring only "how fast it was written". Lead time, review time and defect rate are the overall effect; don't write percentages with no baseline.
  • "The AI wrote it" becoming an excuse. Whoever merges is responsible, no exceptions.

Key takeaways

  • At every stage from ticket to merge, AI produces drafts and suggestions; decisions are made by people or by deterministic machine rules.
  • Tickets need acceptance criteria and an "out of scope" section; this directly decides the quality of what AI produces, and it turns into table-driven tests.
  • gofmt, go vet, go test -race and govulncheck are required checks; AI's code must pass them just like code people write, and they are never loosened for it.
  • AI review in CI (for example the automation mode of Claude Code GitHub Actions) gets read-only access, limited tools and turns, is not a required check and does not handle fork PRs.
  • Branch protection, CODEOWNERS (including .claude/ and CLAUDE.md) and AI disclosure in the PR template give human review a focus; whoever merges is responsible for the code.
  • Prompts are stored as skills in the repo, shared by local runs and CI, reviewed and version-controlled; no secrets or personal data in prompts.
  • Measure lead time, review time, PR size and defect rate: get a baseline first, compare similar work, use the median, and don't make numbers up.

Next

This article stops at the merge step. The next one, “Automating Deployments and Troubleshooting with AI Workflows”, carries on from there: how to let AI take part in the deployment process, and how to use it to help troubleshoot when production has problems, with its permissions kept under control.