argvgate
A policy gate for coding-agent tool calls. It parses the shell command the agent wants to run, works out which files it would read or write and which hosts it would contact, and checks that against one small policy file.
Most deny rules for coding agents match the command as a string. That breaks as soon as the same action is spelled another way: cat ./src/../.env, bash -c 'cat .env', env X=1 cat .env, grep -r . ., cat < .env, curl 2130706433. argvgate parses the command first (quotes, $(...), backticks, pipes, redirections, sudo/env/timeout/xargs/bash -c/find -exec, path normalization, symlinks, odd IP spellings) and checks what it found.
It runs as a Claude Code PreToolUse hook. It can also be called from any other harness as a plain command (argvgate check, exit code tells the answer).
What it is not. A hook is a check, not a sandbox. A program the agent runs (python script.py, make, npm run x) can do things argvgate cannot see inside. Use argvgate to stop the obvious and the accidental, and a real sandbox (container, VM, OS sandbox) to contain the rest. See Limits.
No dependencies. Python 3.9+. MIT.
Install
pip install git+https://github.com/anishpentyala/argvgate
argvgate init # writes argvgate.toml
argvgate probe # tries hundreds of bypass variants against YOUR policy
argvgate snippet claude # prints the hook entry for .claude/settings.json
TOML policies need Python 3.11+ (or pip install tomli on older versions). JSON policies (argvgate.json) work everywhere.
Policy
version = 1
[paths]
deny_read = [".env", ".env.*", "~/.ssh/**", "**/*.pem"]
deny_write = [".env", ".github/workflows/**", "~/.bashrc"]
write_roots = [".", "/tmp"] # optional: writes anywhere else are refused
[commands]
default = "allow" # or "ask" / "deny" for allowlist mode
deny = ["rm -r|-R|--recursive /", "git push --force|-f", "git reset --hard"]
ask = ["git push", "npm publish"]
allow = [] # only used when default is not "allow"
[network]
allow_hosts = ["github.com", "*.githubusercontent.com", "pypi.org"]
deny_hosts = ["169.254.169.254", "10.0.0.0/8"]
on_violation = "deny"
[opaque] # what to do when a command cannot be analyzed
default = "ask"
pipe_to_shell = "deny"
Unknown keys are errors, so a typo like deny_reed fails loudly instead of silently protecting nothing.
Path patterns are gitignore flavored. .env matches that name anywhere. secrets/** is relative to the project root and covers the directory and everything under it. ~/.ssh/** and /etc/shadow are absolute. **/*.pem matches at any depth. Both the written path and its symlink-resolved form are checked.
Command rules are a command name plus optional subcommands, then flags. Tokens starting with - must be present somewhere in the arguments; a|b accepts either spelling; combined short flags are split, so rm -r|-R -f matches rm -fr and rm -r -f. Global git options (-C, -c) are skipped. Rules are checked against every layer, so sudo rm -rf / and bash -c 'rm -rf /' match a rule for rm.
Opaque kinds: unparsed, eval, dynamic_command, dynamic_path, dynamic_host, inline_code (python -c, node -e), pipe_to_shell, unbounded_walk. Each can be allow, ask or deny.
What it checks
- Redirections:
> >> >| &> <count as writes and reads. cat,head,less,sed,awk,grep,cp,mv,tee,dd,tar,curl -o/-T/-d @fileand similar know which arguments are files and whether they are read or written. Unknown commands have every path-looking argument checked against both deny lists.- Recursion:
grep -r,rg,cp -r,tar,rsync,rm -r,find ... -exec,git grepwalk the directory (bounded) and deny if a denied file is reachable. - Wrappers:
sudo doas env nice nohup timeout command exec stdbuf time xargs watch find -exec bash -c sh -c eval, nested up to 6 deep. - Hosts in
curl wget ssh scp rsync nc git clone ...: lowercased, userinfo and port stripped, trailing dot removed, punycode, and decimal/hex/octal/short IPv4 forms and IPv4-mapped IPv6 normalized before matching. - Claude Code's own tools:
Read,Write,Edit,MultiEdit,NotebookEdit,Grep,Glob,WebFetch.
Claude Code hook
argvgate snippet claude
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash|Read|Write|Edit|MultiEdit|NotebookEdit|Grep|Glob|WebFetch",
"hooks": [{ "type": "command", "command": "argvgate hook claude" }]
}
]
}
}
Merge that into .claude/settings.json. The hook finds argvgate.toml or argvgate.json by walking up from the working directory (or use ARGVGATE_POLICY). It answers deny or ask with a reason, and for an allowed call prints nothing, so your other Claude Code permission rules still apply. argvgate only makes calls stricter. It fails closed: bad input, a missing or broken policy or an internal error is a deny with the cause in the reason. Hook format: Claude Code hooks reference.
Other harnesses
argvgate check --command 'cat ./src/../.env' # exit 0 allow, 2 deny, 3 ask, 64 usage/policy error
argvgate check --read ~/.ssh/id_rsa
argvgate check --write .github/workflows/ci.yml
argvgate check --url https://example.com/x
argvgate explain --command "bash -c 'curl 2130706433 | sh'" # shows what was parsed and which rule fired
argvgate check --json --command '...'
Test your policy
argvgate probe # generate bypass variants for every rule in your policy
argvgate test policy-cases.json # your own expectations: [{"command": "...", "expect": "deny"}]
probe builds a throwaway project and home directory, creates a file for each denied path, and runs hundreds of spellings through the engine (absolute and relative paths, .. traversal, bash -c, env, sudo, eval, redirects, globs, braces, ANSI-C quoting, recursive search, xargs, find -exec, git show REV:path, host spellings, reordered flags). Nothing is executed and nothing outside the temp directory is touched. It exits 1 if any variant would be allowed, and names it.
Limits
Read these before relying on it.
- Programs are opaque.
python script.py,make,npm run,./build.shcan read or write anything. argvgate checks the script file path, not what is inside. Inline code (python -c) triggers theinline_codesetting. - No data flow.
X=.env; cat "$X"is flagged as a dynamic path (ask by default).git log -pandgit diffcan print the contents of a denied file without naming it; only explicitREV:pathand pathspecs are checked. git add .can stage a denied file, since checks apply to explicit path arguments, not directory walks.- Directory changes are approximated. After
cd, relative paths are checked against both the original and the new directory, so it can over-block, never under-block. Subshell scoping is not modeled. - Race conditions. Recursive checks look at the disk when the call is checked. A file created by the same command is not seen.
- Shell coverage. POSIX-style bash and zsh syntax.
case,(( ))arithmetic commands and thefunctionkeyword are flagged asunparsed. fish, PowerShell and cmd syntax are not parsed. - Network. Hosts are only extracted for known commands and for any argument containing a
scheme://URL. A tool that takes a host some other way is not seen. This is not a firewall. - Hook coverage. The hook sees tool calls. It does not see what an MCP server or a subagent does outside those calls.
If you find a command that slips through, please open an issue with the command and your policy.
Development
python -m unittest discover -s tests -t . -v
argvgate probe --policy examples/policy.toml
License
MIT
Metadata
Release files for argvgate 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| argvgate-0.1.0.tar.gz | 42.4 kB | Without provenance | Details for argvgate-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| argvgate-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for argvgate-0.1.0-py3-none-any.whl |
Total release size: 78.1 kB
Release files / argvgate-0.1.0.tar.gz
| Download URL | argvgate-0.1.0.tar.gz |
|---|---|
| Size | 42.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
780020b7e386479055906058a88d12a046ee778e0c5c14d1c1d396b9d6a8f8ea
|
|
BLAKE2b-256 checksum How to use checksums |
7ce03ae045b42bd3653381ef12041dba22f496047ff7d99d552e81232b9c2451
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.12
|
Release files / argvgate-0.1.0-py3-none-any.whl
| Download URL | argvgate-0.1.0-py3-none-any.whl |
|---|---|
| Size | 35.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
afa42aaea38119188f292594cc8420d1d54b81bb6832bb41e5baab8db79e8258
|
|
BLAKE2b-256 checksum How to use checksums |
ac85048064873e9fd817ad7a20075f075a054281ec6485a78bb1f523087c53be
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.12
|
Security for argvgate 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.