skip to content

Every new zsh session on a machine prints `zsh compinit: insecure directories, run compaudit for list` and then asks whether to continue. What is compinit checking, why does it care, and how should you resolve it?

level: middleimportance: should knowfreq 46%

answer

  1. completion functions are code you never read
  2. group- or world-writable is the trigger
  3. ownership matters as much as mode
  4. one function lists the offenders
  5. -u trusts them, -i skips them

basics

~20 s

compinit refuses to load completion functions from directories or files that are writable by group or others, or not owned by root or by you, because those functions are shell code that runs as you. Run compaudit to list the offenders and tighten their ownership and permissions.

solid answer

~50 s

Completion functions are ordinary shell code that zsh sources into your interactive session, so anyone who can write a file on `fpath` can run commands as you the next time you press Tab. At startup `compinit` performs a security check — the same one exposed as the `compaudit` function — and flags any `fpath` directory or completion file that is group- or world-writable, or owned by someone other than root or the current user. The correct fix is to run `compaudit`, look at what it lists, and repair it: `chmod g-w,o-w` the directories and files, and `chown` anything owned by a stray account. The wrong fix is to paste `compinit -u` into your config, which tells zsh to use the insecure files anyway; `compinit -i` at least ignores them rather than trusting them, but both are silencing the alarm rather than fixing the cause.

code

bash · 2 lines
bash
compaudit
compaudit | xargs chmod g-w,o-w

go deeper

for a junior

Know that the message is a real security check, that compaudit lists the offending paths, and that the fix is to correct their permissions rather than to silence the warning.

for a middle

Explain the two failure conditions the audit tests — group or other write access, and ownership by neither root nor you — and why a good file inside a bad directory still counts as insecure.

for a senior

Demonstrate the threat model out loud: a completion function is code that runs as the user at Tab time, so a writable fpath entry is a privilege-escalation path on a multi-user host, and the fix belongs in whatever created the modes.

for a principal

Own the fleet answer: decide who owns the completion directories on managed machines, whether -i is an acceptable default in your baseline dotfiles, and how you keep an installer from re-creating group-writable paths every upgrade.

## Why a completion function is a security-relevant file zsh's completion system loads functions from the directories in `fpath` and runs them in your interactive shell whenever you press Tab against the matching command. There is no sandbox: a completion function can run any command, read any file you can read, and write anywhere you can write. That makes an `fpath` entry equivalent, in blast radius, to a line in your `.zshrc` — except that you never open it and never review it. That is why `compinit` does a permissions audit before it trusts what it finds. ## What the check actually tests For each directory on `fpath` and each completion file inside it, compinit considers it insecure if: - it is writable by group or by others, or - it is owned by neither root nor the effective user running the shell. Both conditions describe the same threat: some account other than you (or the system) can replace the contents. The check walks up as needed, so a securely-permissioned file inside a group-writable directory is still a finding — anyone who can write the directory can replace the file. When the check fails you get the `insecure directories, run compaudit for list` warning and, in an interactive shell, a prompt asking whether to ignore the insecure directories and continue or abort compinit. Abort leaves you with no completion system at all, which is why people reach for the silencing flags. ## compaudit `compaudit` is the function that performs and reports the audit. Run it on its own and it prints the offending paths: ```bash compaudit ``` Read the output before changing anything — it tells you which component of your setup created the problem. Typical causes are an installation that unpacked with a group-writable umask, a shared machine where a completion directory belongs to a service account, or a completion directory sitting inside a user-writable prefix that was created by a different account. ## Fixing it properly The repair is ownership and mode, applied to exactly what compaudit named: ```bash compaudit | xargs chmod g-w,o-w ``` and, where the owner is wrong, `chown` the path to root or to yourself, whichever matches how that directory is meant to be managed. Then start a new shell; the warning should be gone. If the offending directory is one you do not actually need, the cleanest fix is to remove it from `fpath` altogether. ## The flags, and what each one really means - `compinit -i` — silently **ignore** insecure files and directories. Completion from them does not load; everything else works. This is the safe silencer: you lose functionality rather than trust bad files. - `compinit -u` — **use** them anyway, no questions asked. This is the dangerous silencer, and it is unfortunately the one most widely copy-pasted, because it makes the warning disappear without losing any completions. - `compinit -C` — a different thing entirely: it skips the check for new or changed completion functions and reuses the dump file as-is, purely for startup speed. On a single-user laptop where the group in question is your own login group and no other human has an account, `-u` is a defensible risk decision — but it is a decision, and it should be made deliberately rather than pasted from an internet answer. On a shared host, a build machine, or anything with more than one interactive account, treat the finding as real: a group-writable `fpath` directory is a privilege-escalation path from any member of that group to every user who tabs a command. ## The recurring-warning trap Because many setups fix the modes but leave the original creator in place, the warning comes back the next time that component reinstalls itself. If you find yourself re-running the same `chmod` every few weeks, fix the umask or the install step that produces the bad modes rather than repairing the symptom on a schedule.

  • What is the practical difference between `compinit -i` and `compinit -u`?
    `-i` silently ignores the insecure files, so their completions simply do not load and the rest of the system works. `-u` uses them anyway, which loads and runs code from files that another account can rewrite. Both suppress the prompt; only `-i` preserves the security property the check exists to enforce.
  • Why is a securely-permissioned completion file inside a group-writable directory still flagged?
    Directory write permission is what governs replacing a file, not the file's own mode. Anyone who can write the directory can unlink the good file and create their own in its place, so the file's 644 root-owned mode gives no protection. The audit therefore judges the containing directory too.
  • On a single-user laptop, is the warning ever safe to ignore?
    It can be, if compaudit's findings are all owned by you and group-writable only to a group with no other members. That is a risk decision, though, not a non-issue — and it stops being safe the moment the same dotfiles land on a shared host. Fixing the modes costs one command and travels better.

saying these in an interview costs you the question

  • Adds compinit -u to make the warning go away
  • Thinks the warning is only cosmetic noise
  • Believes only the file's own mode matters, not the directory's
  • Chmods 777 to make the error stop
  • Cannot say what a completion function is allowed to do

context