Topic 5 of 5 · 4 min read
Terminal agents for shell and git chores
Goal: Hand a shell or git chore to a terminal agent with limits that stop it from deleting, pushing or leaking data.
Terminal agents are very good at chores that need many small shell and git commands, as long as you say what is read-only, what may change, and what is off limits.
Check yourself · 1 of 3
You want to know which commit changed a line. Which instruction is safest to give the agent?
Why it matters
Plenty of engineering time goes on tasks like "why did this deploy fail?", "who changed this line?" or "set up this project on a new machine". These need many commands in the right order and careful reading of the output. An agent does that quickly. It can also run the wrong command quickly, so the limits matter more than for code edits.
Common chores and their risks
- Log digging. The agent searches a log for an error, groups similar lines and finds the first occurrence. Risk: logs hold tokens, emails and personal data that then enter the model's context. Give it a redacted excerpt or a narrow
grep, not the whole log folder. - Git history questions. "Which commit introduced this bug?"
git log -S,git blameandgit bisectsuit this. These are read-only, except bisect, which checks out old commits. Run it on a branch with no uncommitted work. - Environment setup. Installing tools and dependencies from a README. Risk: it may run unreviewed install scripts, change global settings or write secrets into files.
- One-off scripts. Renaming 300 files, converting a CSV. Risk: a script that deletes or overwrites. Ask for a dry run first.
- Git housekeeping. Branch cleanup, rebases, changelogs. Risk: rewriting history and pushing it.
Setting limits in the prompt
Find which commit changed the default timeout in src/http.ts.
Use only read-only git commands (log, blame, show, diff).
Do not check out, reset, commit or push. Report the commit hash,
author date and the one-line reason, and show the command output.
For scripts, ask: "Write the script, run it in dry-run mode that prints what it would do, and wait for my approval before running it for real."
Before and after
Before: "Clean up my git branches."
The agent may delete unmerged branches or force-push.
After: "List local branches already merged into main with
git branch --merged main. Show the list and do not delete anything. I will say which to remove."
What goes wrong
- Pushing is permanent for others. A force push can overwrite a teammate's commits. Deny
git pushunless you ask for it. - Leaking data. Environment dumps,
.envfiles and logs travel to the model provider. - Plausible but wrong history. The agent may summarise a commit's purpose from its message alone. Ask for the command output as evidence.
Examples
A read-only history question
git log -S'timeout = 30' --oneline -- src/http.ts
git show 4be12a1 --stat
The agent finds the commit that changed the value and shows its diff. Both commands are read-only, so they are safe to allow.
Dry run first
for f in *.JPG; do echo mv "$f" "${f%.JPG}.jpg"; done
The echo makes this a dry run: it prints each rename without doing it. Check the list, then ask the agent to remove echo.
Key points
- Shell and git chores suit agents because they chain many small commands and read the output of each.
- State what is read-only, what may change and what is forbidden before the agent starts.
- Logs and environment files can hold secrets and personal data that then enter the model's context.
- For scripts that delete or overwrite, require a dry run and your approval before the real run.
- Pushing, force-pushing and history rewriting should stay denied unless you ask for them.
Common mistakes
- Pasting whole log files or environment dumps into the session.
- Asking for "cleanup" without naming what may be deleted.
- Letting the agent push or rewrite shared history without being asked.
- Accepting a history summary without the git command output behind it.
Check yourself · 2 of 3
Why is a dry run useful before an agent runs a bulk rename or delete script?
Check yourself · 3 of 3
What is the main risk of pasting a full application log into an agent session?
Practice items, not counted towards your mastery.
Start here
- How Claude Code works (opens in a new tab)DocsFree
A vendor's own description of the agent loop: gather context, take action, verify, repeat.
- Best practices for Claude Code (Claude Code docs) (opens in a new tab)DocsFree
Advice on giving the agent a way to verify its work, plus memory files and course correction.
- Configure permissions (Claude Code) (opens in a new tab)DocsFree
Allow, ask and deny rules and permission modes, with examples of command patterns.
More for this topic
- git-reflog (Git documentation) (opens in a new tab)DocsFree
How to find and restore earlier states of a branch after a bad reset or rebase.
- Aider documentation (opens in a new tab)DocsFree
An open-source terminal pair programmer that commits each change to git, so every edit is easy to undo.