AI Coding Agents: TUI, Headless Mode, and SDK—A Practical CLI Guide
AI coding agents are more than next-line code completion: they can break down tasks, read multiple files, run commands, and revise their output based on results. This article explains three common agent forms—interactive TUI, headless mode, and SDK—and when each makes sense. It also provides a runnable headless batch-docstring script and an SDK-based code review workflow, plus a deployment checklist covering task granularity, data sanitization, model hosting, backups, and audit logs.
AI Coding Agents: TUI, Headless Mode, and SDK
AI coding agents are no longer just about completing a few lines of code. They can decompose tasks, read multiple files, execute commands, and correct their own output based on the results. Many teams run into the same problem: their tools only support a single question-and-answer exchange and cannot participate in bulk code changes or CI pipelines. This article looks at the division of labor between three common agent forms and provides examples you can adapt directly. It covers only the TUI, headless mode, and SDK forms, and does not compare pricing or feature sets of specific products.
How is an agent different from ordinary code completion?
Ordinary completion relies on a few dozen lines of code near the cursor and produces the next piece of text. An agent works differently. It first interprets the requirement, then decides which files to read, which tools to call, whether to run tests, and finally adjusts its plan based on execution results.
This mechanism depends on two key design elements.
The first is skills. A skill is a reusable instruction package that encodes team conventions, such as interface naming rules, exception handling patterns, and log format requirements. When the agent encounters a matching task, it automatically loads the corresponding skill. Once conventions are part of the prompt, generated output more closely matches how the project is actually written, and the model is less likely to invent library functions or parameters.
The second is context management. Large code repositories cannot be fed entirely into the model’s input window. A common approach is to first retrieve relevant files, function definitions, and call relationships, then pass compressed snippets to the model. The search index must be kept in sync with code changes, or results will go stale. When the index is unavailable, the tool should fall back to filtering by directory or file name and allow developers to specify the scope manually. A fallback is more reliable than silently using the wrong context.
How do you choose among the three forms?
| Dimension | TUI (interactive terminal) | Headless mode | Agent SDK |
|---|---|---|---|
| Interaction | Multi-turn dialogue between a human and the agent | Unattended, invoked by scripts | Invoked by code you write yourself |
| Best for | Exploring unfamiliar modules, discussing approaches, reviewing a single change | Bulk rewrites, CI checks, scheduled jobs | Internal review bots, integration into engineering platforms |
| Resource usage | Runs inside the terminal with low overhead; suitable for remote servers | Consumes CI machine resources; concurrency must be controlled | Requires development, testing, and long-term maintenance |
| Prerequisites | Install the CLI and sign in | Authentication, timeouts, log retention | Pinned SDK version, authentication, rate limiting |
| Main risk | Accidental file modification; human confirmation required | Automatic writes may overwrite code | High development cost; upgrades may break compatibility |
Three questions can guide the choice. Does the task require repeated human judgment? If so, use the TUI. Are the task rules clear and expressible in a script? If so, use headless mode. Will the task be reused long-term and embedded in your team’s own systems? Only then is SDK development worth the investment.
IDE plug-ins offer a more intuitive interaction, but they consume more memory and cannot be used on servers without a graphical interface. The TUI is lighter in these environments.
How do you batch-generate docstrings in headless mode?
The following example adds docstrings to functions in a Python source directory. ai-coder is a placeholder name; replace it with the actual command and parameters of the tool you use.
Confirm the following conditions before running:
- The code has been committed to Git and runs on a separate branch so changes can be rolled back.
- The corresponding CLI is installed and sign-in or key configuration is complete.
- A per-run timeout and concurrency limit are set in the configuration file.
- Start with the default preview mode. Preview mode only generates temporary files and does not modify the source.
#!/usr/bin/env bashset -euo pipefailSRC_DIR="./src"DRY_RUN="${DRY_RUN:-1}" # Preview by default; set to 0 to write to sourceBACKUP_DIR="./.docstring-backup/$(date +%Y%m%d-%H%M%S)"LOG_FILE="./docstring-run.log"mkdir -p "$BACKUP_DIR"find "$SRC_DIR" -name "*.py" -print0 | while IFS= read -r -d '' file; dotmp_out="$(mktemp)"if ! ai-coder --headless --task "generate-docstrings" \--file "$file" --output "$tmp_out" >>"$LOG_FILE" 2>&1; thenecho "Failed: $file" | tee -a "$LOG_FILE"rm -f "$tmp_out"continuefiif [ "$DRY_RUN" = "1" ]; thenecho "Preview: result for $file is in $tmp_out"elsemkdir -p "$BACKUP_DIR/$(dirname "$file")"cp -p "$file" "$BACKUP_DIR/$file" # Keep an original copy before writingcat "$tmp_out" > "$file" # Overwrite the source file, preserving permissionsrm -f "$tmp_out"echo "Written: $file"fidone
The execution order is as follows.
- Run
DRY_RUN=1 bash batch_docstrings.sh. Results are saved to temporary files. - Use
diffto compare the original files with the temporary files. Spot-check at least a few functions to confirm the docstrings match the code. - Once everything looks correct, run
DRY_RUN=0 bash batch_docstrings.sh. - Use
git diffto review the overall change. If the results are not as expected, roll back withgit checkout -- <file>or copy the files back from the backup directory.
The script logs failures and continues processing rather than aborting the whole batch when a single file fails. Keep the log file so you can identify which files need manual attention.
How do you build a custom code review bot with the SDK?
Enterprises often have their own code red lines, such as banning certain dangerous functions, enforcing a unified log format, or prohibiting plaintext secrets in code. General-purpose tools cannot automatically recognize these rules, so you need the SDK to encapsulate them.
Below is a minimal architecture-level flow. The specific class and function names depend on the SDK you choose and must be adjusted according to its official documentation.
- Pin the version: Lock the SDK version in your dependency file to avoid interface changes after an upgrade that would make review results inconsistent.
- Configure authentication: Read model service credentials from the CI secret store. Credentials must not be written into code, configuration files, or logs.
- Register skills: Write red-line rules as skill files, such as a list of banned functions, log format examples, and secret detection rules. Each rule should include a violation example and a suggested fix.
- Write the entry script: Use the command below to get the Python files involved in this merge, call the agent on each one, and output results in JSON format.
git diff --name-only origin/main...HEAD -- '*.py'
- Integrate into the pipeline: Return a non-zero exit code when violations exist to block the merge. Also set timeouts and concurrency limits, and retain logs for at least 30 days for auditing.
Review bot results still need human review. The model may produce false positives or miss issues. In the early stage, use results only as review comments rather than blocking merges directly, and enable blocking once the false-positive rate stabilizes.
What should you watch out for during rollout?
The following checklist can be used directly as a team standard.
- Task granularity: Limit each task to a single function or module. Split tasks when more than 10 files are involved in a single run. Smaller granularity improves the success rate per generation and makes review easier.
- Sanitized fields: Remove database connection strings, access tokens, phone numbers, internal IP addresses, and customer data before uploading code. Teams should maintain a list of fields to sanitize and encode it into skill files or preprocessing scripts.
- Model hosting: For unpublished core algorithms or code subject to compliance constraints, use locally hosted models. Public repositories or general-purpose tooling code can use cloud models, but confirm the provider’s data retention and training terms first.
- Backups and rollback: Perform all automatic writes on a separate branch and keep a backup directory. Scripts should default to preview mode.
- Audit logs: Record the time, target file, model version, and execution result of each call. When problems arise, this lets you identify which call introduced the error.
Conclusion
- Start with the TUI to get familiar with the tool, and codify common team conventions as skills.
- Use headless mode for batch tasks with clear rules, previewing by default and writing only after confirmation.
- Invest in SDK development only when long-term reuse is needed and someone is responsible for maintenance.
