Linux

Before You Approve That Shell Command: A Guide to AI Coding Agents

› Before you approve that shell command Laptop on a desk at night, a Linux terminal waiting at a confirmation prompt
In this article

By Michael Kantor, HOL

Your coding agent says it can clean up a project before running tests. It proposes this command:

git clean -fdx

That is a lot of power in one command. In a Git repository, clean removes untracked files. The -d option includes untracked directories, -f forces removal and -x includes files Git would normally ignore. That last group may contain local environment files, caches and build outputs. Some are easy to recreate. Others may not be.

Before approving a cleanup, check what directory the agent is in, which files the command would touch, and whether your agent has a control that can deny it before execution. You do not need to trust the agent's summary of its own plan.

Start with the working directory

The same command can be harmless in a throwaway test directory and damaging in the wrong repository. Ask the agent to show its working directory, or check it yourself:

● ● ●   terminal
user@linux:~$ cat racknerd.ad
 ____            _    _   _               _
|  _ \ __ _  ___| | _| \ | | ___ _ __ __| |
| |_) / _` |/ __| |/ /  \| |/ _ \ '__/ _` |
|  _ < (_| | (__|   <| |\  |  __/ | | (_| |
|_| \_\__,_|\___|_|\_\_| \_|\___|_|  \__,_|

	LINUX VPS • $19.95 / YEAR
> Affordable VPS hosting for Linux projects.
pwd
git status --short --ignored

The second command lists changes, untracked files and ignored paths by name. File names can themselves be sensitive, so do not paste the results into public issue threads without checking them. If Git reports that you are outside a repository, stop. Do not let the assistant guess another directory.

Preview the exact deletion

In the same working directory, run:

git clean -ndx

The -n option previews a matching clean without deleting anything. Read the output before considering the destructive version. If you see an unexpected directory, configuration file or local data, do not approve the cleanup.

A check in a disposable Git repository on Debian GNU/Linux 13 used Git 2.47.3 and Bash 5.2.37. It committed a Git ignore rule, then created an untracked dummy file named scratch.txt and a dummy file under the ignored build/ directory. The dry run printed:

Would remove build/
Would remove scratch.txt

Both dummy files still existed afterward. This was a manual shell check, not a test of an AI agent, HOL Guard or any enforcement mechanism. It shows the documented Git dry-run behavior only.

Here is the non-destructive setup if you want to reproduce that narrow check:

scratch="$(mktemp -d)"
cd "$scratch"
git init -q
printf 'build/\n' >.gitignore
git add -A
git -c user.name='Test Writer' -c user.email='test@example.invalid' commit -qm 'Add ignore rule'
printf 'dummy\n' > scratch.txt
mkdir build
printf 'dummy\n' > build/output.txt
git clean -ndx
test -f scratch.txt && test -f build/output.txt && echo "Dry run preserved both files"

The temporary directory is intentionally left in place for inspection. Do not replace the -n option with -f in this example, and do not run cleanup demonstrations in a real project.

Read the command beyond its first word

A short command may call a package script, launch another program or read local configuration. For example, npm test can run whatever the repository's package.json defines as its test script. Inspect that script and anything it calls before approval.

Check for pipes, output redirection, command substitution and external network addresses. Review every segment of a command chained with && or a semicolon. Pay particular attention to programs that read files and then send data to another host.

Remember that a coding agent can inherit environment variables and filesystem permissions from its process. Those may include credentials. Avoid printing variable values or private file contents into a chat transcript while assessing the environment.

Permission prompts have different scopes

Before you approve a command, find out what the approval covers. Some tools ask about a single command. Others allow a recurring command pattern, an entire workspace or a class of actions. Those are very different decisions.

If your agent offers "allow once" and "always allow", choose the one-time option for an unfamiliar action. If it has separate permissions for file reads, edits, shell execution and network access, review them independently. A command that only prints a path should not need the same access as a command that deletes files or publishes code.

Do not assume an approval prompt means the command is queued safely. Inspect whether execution waits for an explicit decision, what happens if the policy checker fails, and whether the same policy applies when the agent runs unattended. If the agent can switch to a different tool after a denial, check whether that alternative tool is covered. A policy that protects only one entry point cannot guarantee the same outcome through another.

Where a preview has limits

The output of git clean -ndx describes the files Git would remove at the time of that preview. It is useful, but it is not a permanent guarantee. A later process could create another untracked file, change the working directory or alter repository state before the destructive command runs. Recheck the directory and preview immediately before approval. If the command is risky and the project matters, make a verified backup first.

Not every tool offers a reliable dry-run mode. Do not assume that adding -n, –dry-run or –check will be harmless unless the tool's own documentation says so. For programs that have no documented preview, use a disposable environment or review the source and operation manually. When the risk is high and you cannot confirm its effects, declining the operation is a reasonable choice.

Know when the control runs

A post-command warning is useful evidence, but cannot prevent an action that has already completed. A pre-execution control can block a proposed tool call, provided it is installed, enabled and actually covers that call.

For example, Anthropic documents a PreToolUse hook for Claude Code that can deny a matching call before it runs. Its PostToolUse hook runs after execution. The event names alone do not guarantee coverage across every shell, plugin or external tool.

Test your own configuration safely. Use a disposable project and two harmless cases, one your policy permits and one it should deny. For the denied case, check both the recorded decision and whether the proposed file change was prevented. A visible warning without that second check does not prove enforcement.

Check connected tools too

Shell approval is only part of the picture. An MCP server may expose remote file operations, account actions, databases or other APIs. Read the tool names and permission scopes before connecting a server. Use a limited account where possible, and do not assume shell rules govern remote tool calls.

The July 28, 2026 MCP specification removed the older initialize/initialized exchange. If you use an MCP setup guide, check which protocol version your actual client and server use. Connection success does not establish that the tool's requested permissions are appropriate.

Verify the outcome

After an agent runs an approved command, check what changed:

git status --short --ignored
git diff --stat

These commands answer different questions. Git diff –stat summarizes tracked changes. It does not show every ignored or untracked artifact. An agent's message that says "cleanup complete" is not a substitute for checking the workspace.

Where an extra security layer helps

I lead HOL, which maintains HOL Guard, an open-source security project for AI coding agents. It reviews supported actions through integrations such as agent hooks and managed tool paths, and records decisions for those paths. Coverage depends on the agent and integration. It should not be mistaken for universal interception of every shell command or MCP tool call.

You can apply these checks without installing a security product. Confirm the working directory, preview destructive effects, inspect delegated commands, test the control boundary and verify the resulting changes. That is a practical routine for any Linux developer working with a coding agent.

Technical references

Git's git-clean manual: https://git-scm.com/docs/git-clean

Anthropic's Claude Code hook guidance: https://claude.com/resources/articles/how-to-configure-hooks

MCP 2026-07-28 specification notes: https://github.com/modelcontextprotocol/modelcontextprotocol/blob/main/blog/content/posts/2026-07-28-spec-ga/index.md

Author disclosure: Michael Kantor leads HOL, the organization maintaining HOL Guard. The Git example above was a manual, non-destructive shell check, not a product or AI-agent evaluation.

● ● ●   terminal
user@linux:~$ cat racknerd.ad
 ____            _    _   _               _
|  _ \ __ _  ___| | _| \ | | ___ _ __ __| |
| |_) / _` |/ __| |/ /  \| |/ _ \ '__/ _` |
|  _ < (_| | (__|   <| |\  |  __/ | | (_| |
|_| \_\__,_|\___|_|\_\_| \_|\___|_|  \__,_|

	LINUX VPS • $19.95 / YEAR
> Affordable VPS hosting for Linux projects.
author avatar
Michael Kantor
Michael Kantor leads HOL, the organization maintaining HOL Guard. The Git example above was a manual, non-destructive shell check, not a product or AI-agent evaluation.