Skip to content

Permissions

asksh checks layered TOML rules in permissions.toml and runs a Bash AST preflight analyzer before executing tool calls or runbook steps.

File lookup order

asksh searches for permission files from deepest directory to shallowest:

  1. <cwd>/.asksh/permissions.toml
  2. Each parent directory's .asksh/permissions.toml walking up to /
  3. Global ~/.config/asksh/permissions.toml (or $ASKSH_CONFIG_DIR/permissions.toml)

The first file containing a matching rule decides the outcome.

Rule precedence

Each file can define [permissions] and optional [targets.<env>] sections:

[permissions]
allow = [
  "ShellHistory",
  "CommandHelp(git*)",
  "Read(**/*.md)",
  "Shell(git status)",
  "Shell(git diff *)",
  "MCP(greendale/*)",
]
deny = [
  "Read(.env)",
  "Shell(rm)",
  "MCP(greendale/drop_table)",
]

[targets.prod]
ask = ["Shell(*)"]
deny = ["Write(*)"]
  • When --target ...?env=<env> or /target ...?env=<env> is active, [targets.<env>] is evaluated before [permissions] in the same file.
  • Within a section, precedence is ask > deny > allow.
  • If no rule matches in any file, the default is Ask (except static LoadSkill calls without dynamic embedded commands, which default to Allow).

Rule syntax

Rules follow <ToolKind> or <ToolKind>(<scope>):

Rule kind Governed tools Scope matching
Read / Read(<glob-or-path>) read_file, grep_files, glob_files Doublestar globs, basename, relative-to-CWD, ~/$VAR expansion, and symlink resolution
Write / Write(<glob-or-path>) edit_file, write_file Same file matching as Read; any Write rule also grants Read for matching paths
Shell / Shell(<pattern>) execute_shell_command, runbook steps Parsed via Bash AST into subcommands and redirections (see below)
ShellHistory shell_history Unscoped
CommandHelp / CommandHelp(<glob>) command_help Glob matched against normalized command tokens (for example CommandHelp(git *))
LoadSkill load_skill Unscoped
MCP / MCP(<server>) / MCP(<server>/<tool>) mcp__<server>__<tool> Supports * wildcards on <server> and <tool>

There are no separate Grep, Glob, or Edit rule kinds; use Read and Write.

How Shell rules match

asksh parses shell commands using mvdan.cc/sh/v3 into subcommands and redirections:

  • allow rules: every subcommand in a pipeline or list must be covered. Opaque or dynamic constructs (such as eval, dynamic command names or redirections, or parse failures) are never allowed unless you specify bare Shell or Shell(*). Patterns without * require an exact word match (Shell(git status) matches git status only); a trailing * matches by word prefix (Shell(git *) matches git and git status, not gitk).
  • deny and ask rules: match if any subcommand matches. Patterns without * match as a word prefix, so Shell(rm) matches rm foo as well as rm.

AST preflight risk assessment

asksh inspects shell commands with permissions.AnalyzeCommand (internal/permissions/preflight.go) before suggesting or executing them. The analyzer unwraps wrappers (sudo, env, command, nohup, nice, time, xargs), recurses into sh -c / bash -lc up to depth 4, inspects $(...) and <(...), and expands globs for rm, mv, chmod, and chown (up to 50 paths).

Detected risk findings raise the command's risk level:

  • High risk: eval, mkfs / mkfs.*, downloader (curl, wget, fetch, xh, http, https) piped or process-substituted into a shell, rm -rf, rm -r, rm / rm -f on critical paths (/, /*, ~, $HOME, *, ., .., system directories, or critical dotfiles), dd of=/dev/..., recursive chmod 777 or chmod 777 on critical paths, git reset --hard, git clean with -f and -d/-x/-X, git push -f / --force / +ref, kubectl delete (unless --dry-run), docker system prune, docker rm -f, and redirection overwrites to system paths or critical dotfiles (.bashrc, .zshrc, .profile, .env, .netrc, .gitconfig, .ssh, .gnupg, .aws, .kube, .asksh, and related shell rc files).
  • Medium risk: sudo, opaque or unparseable commands, non-downloader pipe to shell, rm -f outside /tmp/ and /var/tmp/, dd writing to a non-device path, non-critical chmod 777, git clean -f, git push --force-with-lease, and redirection overwrites to non-critical dotfiles.