"zsh compinit: insecure directories" warning on every Oh My Zsh startup — fix permissions or accept the framework's skip flag?
0 reputation · 22 May 2023, 04:00 UTC
0 reputation · 22 May 2023, 04:00 UTC
On shell startup, Oh My Zsh builds fpath from the enabled plugins and then invokes compinit, which can emit zsh compinit: insecure directories, run compaudit for list. This is Zsh's own security check reacting to group- or world-writable completion directories, not an Oh My Zsh bug.
My installed framework revision appears to pass a flag to compinit that suppresses the interactive prompt rather than resolving the underlying permissions, so the warning behavior may differ between Oh My Zsh and Zsh versions. The directories involved may include Homebrew-managed paths on macOS, where blanket permission changes risk breaking the package manager's expectations. Separately, I am weighing whether trimming my plugins=(...) array is worthwhile, since the project leaves startup-latency mitigation entirely to users.
1. Should I correct ownership/permissions on the paths reported by compaudit, or is relying on the framework's compinit flag an acceptable long-term posture?
2. How do I safely handle Homebrew-owned directories that compaudit flags, without breaking brew?
3. Is there a framework-supported way to cache the completion dump, or is manual .zcompdump management still the only option?
32275 reputation · 22 May 2023, 05:03 UTC
Correct the permissions on the directories that compaudit reports. The -C flag that Oh My Zsh passes to compinit only silences the message; it does not make the directories safe. Adjust ownership/permissions so that no directory in $fpath is group‑ or world‑writable, then run compinit normally (e.g. compinit -u). If you cannot change a directory (e.g. a Homebrew‑owned path), keep the -C flag but accept the security risk, or move that completion to a user‑owned location.
When compinit runs it calls compaudit to scan $fpath for directories that are writable by group or others. Any such directory could be modified by an untrusted user, allowing injection of arbitrary completion code. Oh My Zsh’s compinit -C skips this check, but the underlying risk remains.
compaudit
This lists every directory that fails the ownership/permission check./opt/homebrew/share/zsh/site-functions, note that Homebrew expects that directory to be writable by your user but not group‑writable.sudo chown -R $(whoami) <dir>
chmod -R 755 <dir>
Replace <dir> with the actual path. Do not change ownership to root unless you understand the consequences for package managers.compinit. In a fresh shell, execute:
compinit -u
The -u flag tells compinit to use the cached dump but still perform the audit.zsh session and ensure no “insecure directories” message appears.Homebrew installs completions under /opt/homebrew/share/zsh/site-functions (or /usr/local/share/zsh/site-functions on Intel macOS). These directories are normally owned by your user and set to 755, which is safe. If compaudit flags them, double‑check that the group or others bits are not set to 2 or 4. You can leave them as is if they are already 755; the warning may be a false positive if the directory is a symlink. In that case, you can either remove the symlink from $fpath or create a copy of the directory under $HOME/.oh-my-zsh/custom/completions and add that path to $fpath instead.
zsh automatically writes a compiled dump of all completions to $ZDOTDIR/.zcompdump (by default ~/.zcompdump). There is no Oh My Zsh‑specific cache beyond this. If you want to force a fresh dump after changing permissions, run:
rm -f ~/.zcompdump && compinit -u
This regenerates the file and clears the warning cache.
If the steps above do not resolve the warning, please run compaudit and share the exact list of directories it reports. That will help determine whether a non‑standard location is causing the issue.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.