Sub topic 3
Checking Terminal Coding Agents Safely
Assume you can use a shell, run project tests, and use basic Git. The examples use npm, but the workflow applies to other build systems.
Check the agent's work
Treat an agent's output as a proposed change. Ask it to explain its plan first, then inspect the diff, run focused tests, and run the full test suite.
git diff
npm test
npm run lintTests show whether known behavior still works. Review also checks naming, scope, security, and whether the change solves the actual requirement.
Use Git as a safety net
Create a branch before delegating work. Keep commits small so you can revert one logical change. Stage only the files you reviewed.
git switch -c agent/fix-date-parsing
# Run the agent on a narrow task
git diff
git add -p
git commit -m "Fix date parsing"Do not commit generated files, secrets, or unrelated edits. A clean baseline makes the agent's changes easier to identify.
Run agents from scripts
Non-interactive commands fit CI helpers and shell pipelines. Limit the prompt and check the exit status before accepting output.
set -e
claude -p "Explain the build script in package.json"
codex exec "Run the unit tests and report failures"
copilot -p "Review the current diff for security problems"Connect external tools through MCP
Model Context Protocol (MCP) lets an agent call external services through configured servers. A server might expose issue tracking, documentation, or a database. Grant only the tools and data the task requires. Test an MCP server with harmless read-only operations before allowing writes.
Extend the workflow
Custom commands capture repeated prompts. Hooks can run formatting or tests after an edit. Subagents can divide research, implementation, and review. These extensions improve consistency, but each adds code and permissions to maintain.
Account for security risks
Repository text, issues, and tool output can contain prompt injection: instructions designed to redirect the agent. Treat external text as untrusted data. Never let an agent reveal secrets, run destructive commands, or modify production without explicit approval.
> callout warning > An agent with shell and MCP access can affect everything those permissions can affect. Sandboxing reduces the blast radius; it does not make untrusted instructions safe.
Compare tools and choose
| Tool | Useful starting point | Main decision |
|---|---|---|
| Claude Code | Interactive repository work | Strong conversational workflows and project instructions |
| Codex CLI | Controlled execution | Approval and workspace sandbox settings |
| Copilot CLI | GitHub-centered workflows | Integration with the GitHub ecosystem |
Choose based on authentication, repository integration, approval controls, MCP support, and team policy. Compare behavior on the same small task rather than relying only on feature lists.
Exercise
What should you do before accepting an agent-generated change?
Show answer
Inspect the Git diff, run focused and full checks, review for security and scope, then stage and commit only the changes you accept.