Automating Code Review and Batch File Processing with AI Coding Assistants

    This article explains how to move AI coding assistants beyond one-off question-and-answer sessions and embed them into a repeatable development pipeline. It covers environment preparation, the difference between interactive and non-interactive (print mode) invocation, prompt design for parseable output, session and context management, model selection, result aggregation, and risk controls. A practical bash skeleton, common pitfalls, and a four-week rollout plan are included to help teams build automated code review and batch processing into their workflow.

    1. Background: Knowing Commands Is Not the Same as Automating

    After adopting AI coding tools, many teams see strong enthusiasm in the first week. By the second week, they notice usage is stuck in a “question-and-answer” pattern: ask a question when an error appears, or have the tool explain a function after writing it. This has value, but the ceiling is low because the tool is not embedded in the development workflow. Real efficiency gains come from combining two capabilities: conversational interaction for exploration, diagnosis, and understanding; and non-interactive (print mode) invocation that packages model capabilities into scripts, where the script controls the input scope, execution order, and output format.

    Automated code review and batch file processing sit exactly at the intersection of these two capabilities. The former requires judgment and suits human-AI collaboration; the latter is highly repetitive with clear rules and suits full automation. Linking the two forms a reusable pipeline: a script scans the changeset, builds a review prompt for each file, the model returns structured conclusions, the script aggregates them into a report, and humans handle only high-risk items.

    2. Environment Preparation: Remove Uncertainty Early

    The first step in automation is not writing prompts, but making the runtime environment predictable. Three lessons are worth confirming in advance.

    First, OS and terminal compatibility is a common pitfall. Some tools are designed natively for Linux-like environments, and running them directly in a native Windows terminal can easily cause path, line-ending, and permission errors. The safe approach is to install and run inside a Linux compatibility layer (such as WSL) first, avoiding mistaking environment problems for model problems.

    Second, build a “self-check before troubleshooting” habit. Most CLI tools provide health-check subcommands that verify whether configuration, authentication, and dependencies are complete. When a command hangs, a permission error appears, or output looks wrong, run the self-check first, then look at the network and business code. This usually saves a lot of blind trial-and-error time.

    Third, put versions and configuration under version control. Tools iterate frequently, so pin the version inside the project and commit configuration files, prompt templates, and scripts together. That way, every team member checks out the same repository and reproduces the same automation behavior, instead of each maintaining implicit “works on my machine” knowledge.

    3. Two Invocation Modes: Interactive for Thinking, Print Mode for Output

    Interactive sessions suit exploratory tasks: reading an unfamiliar module, tracing a call chain, or evaluating a refactoring plan. Their value is context continuity, letting you keep asking follow-up questions.

    Non-interactive invocation (commonly the -p parameter, which takes a prompt, prints the result, and exits) is the entry point for automation. Its key property is that it can be wrapped by scripts: input and output are text, exit codes are checkable, and it fits naturally into loops, pipes, and scheduled jobs.

    A minimal working skeleton for batch review looks like this:

    1. #!/usr/bin/env bash
    2. set -euo pipefail
    3. TARGET_DIR="./src"
    4. REPORT_DIR="./reports"
    5. mkdir -p "$REPORT_DIR"
    6. # Process only changed files or a specified suffix to avoid the noise and cost of a full scan
    7. FILES=$(git diff --name-only --diff-filter=ACM | grep -E '\.(py|js|ts|go|java)$')
    8. for f in $FILES; do
    9. [ -f "$f" ] || continue
    10. prompt="Act as a senior reviewer and review the file $f. Output in the following structure:
    11. 1) Defects (with severity and line number)
    12. 2) Security risks
    13. 3) Performance concerns
    14. 4) Readability and naming
    15. 5) Suggested changes (outline a minimal diff)
    16. Judge only based on the file content; do not speculate about context that was not provided."
    17. out="$REPORT_DIR/$(echo "$f" | tr '/' '_').md"
    18. # --print means non-interactive output; check the documentation of the tool you use for exact flags
    19. claude -p "$prompt" < "$f" > "$out"
    20. done
    21. echo "Review complete. Reports are in $REPORT_DIR"

    There are three design points here: use the changeset rather than all files to control scope; use exit codes with set -e to make failures visible; and use “structured output requirements” so downstream steps can parse results.

    4. Prompt Design: Make Output Parseable and Comparable

    The biggest enemy in batch scenarios is unstable output. If the same code produces differently formatted review conclusions on two runs, they cannot be aggregated. The solution is to treat the prompt as an interface contract:

    • Define the role and goal clearly: a senior reviewer focused on correctness, security, and maintainability.
    • Define the evidence boundary: judge only from the provided code and explicit notes; mark “more information needed” when context is missing; never invent caller behavior.
    • Fix the output structure: a graded list plus line numbers plus suggestions; require JSON when necessary.
    • Control granularity: review one file or one function at a time, avoiding long contexts that dilute attention.
    • Add a self-check instruction: ask the model to list “uncertain items” at the end so humans can focus there.

    If the output must be machine-consumed, require strict JSON:

    1. {"file":"src/a.py","issues":[{"level":"high","line":42,"type":"security","desc":"...","fix":"..."}]}

    5. Session and Context Management: Don’t Let Memory Become a Burden

    Long tasks get interrupted; that is normal. Tools with session save and resume can use continue to restore the most recent context, or restore a specific session by ID. The practical advice is to layer usage: use continue for exploratory analysis to keep the thread of thought; use print mode for one-off questions and discard them afterward, avoiding the interference and extra cost of context bloat.

    For batch processing, prefer a “stateless” approach: call the model independently for each file and share no session. A single failure then does not affect the whole run, and parallelism and retries are easier.

    6. Model and Parameter Selection: Allocate Compute by Task

    Different tasks emphasize different capabilities: large-scale refactoring needs stronger reasoning and long context; light tasks such as format checks and comment generation can use lighter configurations to reduce cost and latency. The way to decide is a small controlled comparison: take 20 representative files, run them with different configurations, compare defect detection rate and false positive rate, then fix the choice in the script.

    7. Result Aggregation and Risk Control

    Automated review produces a large volume of output, so a convergence mechanism is required:

    1. Aggregate: merge the per-file JSON, count by severity, and output a top-issues list.
    2. Deduplicate and suppress: template-group similar issues (such as missing exception handling) to reduce noise.
    3. Gate: block merges only for high-severity issues and turn the rest into to-dos.
    4. Auditability: archive reports together with prompt templates so you can review whether rules are too strict or too loose.
    5. Security boundary: restrict accessible directories during batch processing and exclude sensitive files (keys, configuration) to avoid sending confidential content into external calls.

    8. Common Pitfalls

    • Chasing full scans: high noise and high cost; focus on the changeset.
    • Vague prompts: unparseable output and failed aggregation.
    • Sharing sessions in batch runs: contexts pollute each other and failures are hard to locate.
    • Reading conclusions but not evidence: ignoring “uncertain items” lets misjudgments reach the main branch.
    • Skipping environment self-checks: treating configuration problems as model capability problems.

    9. Suggested Rollout Path

    Week one, do one thing only: get print mode working and produce a structured report for a single file. Week two, connect the changeset and report directory into a repeatable script. Week three, add gating and statistics, and plug into the CI pipeline. Week four, run a controlled evaluation, tune model configuration and prompt templates, and finalize the standards.

    If a team wants to host this pipeline in the cloud, it can typically be assembled from general-purpose service categories: use a code hosting service to trigger the pipeline, a container platform to run batch jobs, object storage to archive reports, and logging plus monitoring and alerting to track failure rate and duration. This upgrades automated review from a personal script to team infrastructure, and general cloud product categories from providers such as Baidu AI Cloud can serve as an optional foundation for such a pipeline.