Run
sudofrom Claude Code even though its Bash tool has no terminal.
Let Claude Code run sudo commands even though its shell has no terminal —
by authenticating sudo through a graphical askpass helper and caching the
password for a sliding ~1h window.
Claude Code runs Bash tool commands with no controlling tty, so plain
sudo fails with a terminal is required to authenticate. A PreToolUse hook
rewrites sudo … → SUDO_ASKPASS=… sudo -A … so sudo prompts via a GUI dialog
(no tty needed), and a tiny cache means you're only asked once in a while.
| folder | platform | password dialog |
|---|---|---|
linux/ |
Linux / Ubuntu (incl. sudo-rs) |
zenity / kdialog / ssh-askpass |
macos/ |
macOS | native osascript (AppleScript) dialog |
Both install to the same place (~/.claude/hooks/ + a PreToolUse hook in
~/.claude/settings.json) — a given machine uses one or the other.
# Linux
cd linux && ./install.sh
# macOS
cd macos && ./install.shSee the per‑OS README for requirements, verification, configuration, security notes, and uninstall.
This grants Claude Code the ability to obtain root via your password for the
cache window. The secret is stored user‑only and time‑limited — on macOS in the
login Keychain (encrypted, deleted after the idle window by a launchd
reaper); on Linux in a 0600 tmpfs file. That's the point — make sure it
matches your intent. ./uninstall.sh revokes it.
Claude Code · Anthropic Claude · sudo · SUDO_ASKPASS · askpass · PreToolUse
hook · updatedInput · no tty / "a terminal is required to authenticate" ·
sudo-rs · zenity / kdialog / ssh-askpass · macOS osascript password dialog ·
AI agent · LLM agent · CLI · developer tools · automation · macOS · Linux ·
Ubuntu.