Skip to content

MikeRzDev/claude-code-root-hook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

claude-code-root-hook

Run sudo from Claude Code even though its Bash tool has no terminal.

License: MIT Platform: macOS | Linux Shell: sh / bash Claude Code: PreToolUse hook GitHub stars

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.

Pick your OS

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.sh

See the per‑OS README for requirements, verification, configuration, security notes, and uninstall.

Security in one line

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.

Keywords

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.

About

Run sudo from Claude Code without a terminal: a PreToolUse hook that authenticates sudo via a graphical askpass prompt (macOS osascript + Linux zenity/sudo-rs) with a sliding password cache.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages