One command adds a shell guard to Claude Code, Cursor, Codex, Gemini CLI and Copilot

Five coding agents, five hook formats. Here is what npx deedglass protect writes into each agent's config, what each agent does with an ask, and how to take it all out again.

The short answer

Run npx deedglass protect. It looks for Claude Code, Cursor, Codex CLI, Gemini CLI and GitHub Copilot CLI in your home directory, prints one plan naming each file it will change, and after you say yes adds Deedglass’s shell guard as each agent’s before-a-command hook.1 From then on, a command that would destroy a database, a volume or infrastructure stops for a decision before it runs. It is a second check, not a sandbox.

The rest of this post is what it actually wrote on a test machine, what each agent does with the answer, and where the approach stops.

Deedglass sits between an AI agent and your system. Your rules decide each change before it runs; afterwards Deedglass checks what really changed. In our demo the agent said 1 row; the database changed 301.

What the plan looks like

We ran deedglass 0.13.0 against a scratch home directory that held an empty config folder for each of the five agents. The dry run writes nothing:1

Code What the screen or file shows, copied as is.

$ npx deedglass@0.13.0 protect --dry-run
deedglass protect  5 of 5 agents found · dry run

  Claude Code     → adds the guard (PreToolUse)
                    ~/.claude/settings.json
  Cursor          → adds the guard (beforeShellExecution)
                    ~/.cursor/hooks.json
  Codex CLI       → adds the guard (PreToolUse)
                    ~/.codex/hooks.json
  Gemini CLI      → adds the guard (BeforeTool)
                    ~/.gemini/settings.json
  GitHub Copilot  → adds the guard (preToolUse)
                    ~/.copilot/hooks/deedglass.json

  hook  npx -y deedglass@0.13.0 guard shell

Dry run: nothing was written. 5 files would change.

Without --dry-run it shows the same plan and waits for y. It backs up every file first, and only adds: it merges into the JSON already there and keeps your own hooks.1 A second run on the same machine printed “already has the guard” for all five and “Nothing to change.”1

--client claude-code,cursor limits it to some agents, and --project also writes into the current repository’s folders, so the hook travels with the code.1

The five files it writes

Each agent names the event, the matcher and the timeout differently. This table is taken from the files protect wrote in our run.1

Agent File Event Matcher Timeout
Claude Code ~/.claude/settings.json PreToolUse Bash 10 (seconds)
Cursor ~/.cursor/hooks.json beforeShellExecution none (shell only) 10
Codex CLI ~/.codex/hooks.json PreToolUse ^Bash$ 10
Gemini CLI ~/.gemini/settings.json BeforeTool ^run_shell_command$ 10000 (milliseconds)
Copilot CLI ~/.copilot/hooks/deedglass.json preToolUse none timeoutSec: 10

Here is the Codex entry, the one with the most moving parts:

Code Data in JSON, the format software uses to pass records and settings.

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "^Bash$",
        "hooks": [
          {
            "type": "command",
            "command": "npx -y deedglass@0.13.0 guard shell --client codex",
            "timeout": 10,
            "statusMessage": "Deedglass shell guard"
          }
        ]
      }
    ]
  }
}

The hook pins the version it was installed with, so an upgrade elsewhere doesn’t change what runs inside your agent. If you installed the binary rather than using npx, the hook starts it by its path instead.1

In 0.13.0 the guard was one catalog: 55 rows, 53 command shapes and 2 read limits.2 In 0.14.1 it has 58 rows, 56 command shapes and 2 read limits, each with a primary source and the date it was checked.2 Run npx deedglass guard shell --list to read it.

Ask in three agents, deny in two

The guard answers “ask” when part of a command matches the catalog. Not every agent can ask.

  • Claude Code, Cursor and Copilot CLI show you the command and the reason, and wait.1
  • Codex CLI parses an “ask” answer but doesn’t support it yet: it marks the hook as failed and runs the command.3 So with Codex the guard denies instead.
  • Gemini CLI hook decisions are allow and deny; there is no ask.6 There, too, it denies and shows why.
  • Copilot’s cloud agent, and Copilot CLI in autopilot, treat ask as deny.5

Protect prints this at the end of the run, so nobody is surprised later:

Code What the screen or file shows, copied as is.

✓ Added the guard to 5 files. Backups are in ~/.deedglass/protect/20261027T095409.469184000Z.
  • Codex runs the hook after you trust it with /hooks. It can't ask, so the guard denies.
  • Gemini CLI can't ask, so the guard denies and shows why.

That Codex line matters. A non-managed Codex hook runs only after you review and trust it with /hooks.3 Until you do, Codex has the file but not the guard.

To see the answer a command would get without starting an agent, give the guard the command directly. Exit 1 means it would stop:2

Code What the screen or file shows, copied as is.

$ npx deedglass@0.13.0 guard shell --no-files --command 'terraform destroy'
Deedglass asks first: terraform destroy destroys every resource the configuration manages.
  terraform-destroy  terraform destroy destroys every resource the configuration manages

When the guard can’t run

Every one of these hooks has a failure mode, and you should know which way it falls. If the guard can’t run at all (no deedglass on the PATH, Windows without Git Bash, a timeout) the command goes ahead unchecked.2 The agents agree on this more than you might expect:

  • Cursor’s failClosed defaults to false, so a crash, a timeout or a non-zero exit other than 2 lets the action through.4
  • Copilot hook timeouts fail open for every event, including preToolUse.5
  • Copilot’s preToolUse is the exception for errors: a non-zero exit other than 2 denies the call.5

That last rule is why the Copilot entry protect wrote ends in || true:

Code Data in JSON, the format software uses to pass records and settings.

"bash": "npx -y deedglass@0.13.0 guard shell --client copilot || true"

Without it, a machine where npx can’t start would deny every tool call Copilot makes. With it, a broken guard fails open like the others. That is a choice, and it is the same trade the other four agents make by default: a guard that can’t answer doesn’t freeze your editor.

Practical advice: run the dry run on a new laptop, then run one guarded command through each agent you use, before trusting it.

Undo, and rolling it out to a team

deedglass protect --undo puts each file back byte for byte, or, if you edited the file since, takes out only the guard.1 In our run it printed one line per agent and “Put back 5 files.”1

For a team, two approaches work:

  1. Per developer. Each person runs npx deedglass protect. It touches only their home directory.
  2. Per repository. Run npx deedglass protect --project once and commit the files it writes in the repository, so every clone gets the hook. Codex still loads a project’s hooks only when that project is trusted.3

If you use the Deedglass plugin for Claude Code, its shell guard is already on by default from v0.12.0; DEEDGLASS_SHELL_GUARD=off turns it off.2

After a successful run, protect prints a README badge that links to the free checker.1 The badge says the hook was installed. It doesn’t say the repository is safe, and you shouldn’t read it that way.

What it won’t catch

A pre-command hook reads text. A value known only at run time, such as a variable, an alias, a Makefile target, encoded text, code an interpreter runs or a database reached over HTTP, passes untouched.2 We ran a set of commands through 0.14.1 to show the edges. These got “Nothing to ask about”:2

Command Why it passes
rm -rf node_modules The catalog covers data stores and infrastructure, not files
git push --force origin main Not in the catalog
terraform state rm aws_db_instance.main Removes the binding, not the database
docker system prune -a --volumes Not in the catalog; docker volume prune is
redis-cli FLUSHALL Redis isn’t in the catalog
python manage.py shell -c "Order.objects.all().delete()" ORM code run by an interpreter

Three commands that 0.13.0 let through now get an ask in 0.14.1: docker compose down -v, helm uninstall and mongosh --eval with dropDatabase() or a collection’s drop().22

So treat protect as one layer. The others are a database role that can’t drop tables, cloud credentials that can’t delete, and backups you have restored at least once. The checklist before an agent touches production puts them in order, and how each agent’s hooks differ goes deeper on the formats. If you’d rather write your own hook, start from the 14-line Claude Code version and the glossary entry on the PreToolUse hook.

To try it without changing anything, run npx deedglass protect --dry-run. It prints the plan and writes nothing. To grade what an agent can reach on your own machine, run npx deedglass scan (what the grade means). To watch the checks without installing anything, open the playground.

Written with AI assistance and checked against our claims register.

The takeaway

protect found 5 of 5 agents in a test home, wrote one hook per agent with a 10 s timeout, changed nothing on a second run, and put all 5 files back on undo.

Read nextHow to stop an AI coding agent from running terraform destroy Try it: install in 7 s

Related on this site

More posts

Sources

  1. 1Deedglass docs: protect · docs.deedglass.com · checked 27 October 2026
  2. 2Deedglass docs: The shell guard · docs.deedglass.com · checked 27 October 2026
  3. 3Codex documentation: Hooks · learn.chatgpt.com · checked 25 October 2026
  4. 4Cursor documentation: Hooks · cursor.com · checked 25 October 2026
  5. 5GitHub Docs: Copilot hooks reference · docs.github.com · checked 26 October 2026
  6. 6Gemini CLI documentation: Hooks reference · geminicli.com · checked 25 October 2026
  7. 7deedglass/deedglass #72: the shell guard in Codex CLI, Gemini CLI, Copilot and Cursor · github.com · checked 25 October 2026

Published 27 October 2026, updated 28 October 2026, sources last checked 28 October 2026. If something here is out of date, write to hello@deedglass.com.

Try it on your own setup

npx deedglass scan

Grades only your own setup. Nothing is uploaded.

Pricing