Repository navigation
fix: a server running as root starts Claude, and a headless install gets past sudo - #863
Merged
Merged
Conversation
…s flag
Installed and started as root (a VPS, an LXC container), every local Claude
session died at once: the default permission mode launches Claude Code with
--dangerously-skip-permissions, and Claude Code refuses that flag under uid 0
("cannot be used with root/sudo privileges for security reasons", pane dead
with status 1). Shell sessions were fine. Measured 2026-11-27 with the public
installer in a fresh ubuntu:24.04 container.
Docker cases already answer the same refusal for a root container with
overlays.docker.rootCommand. This is the host-level form, as registry data:
- An enum launch param may declare rootValue, a map from a value to the value
it takes when the server process runs as uid 0 and the launch is local.
Claude declares claudeMode: dangerously-skip-permissions -> normal. The
schema holds keys and replacements to the param's values.
- applyRootValues() (config/cli-registry/root-launch.ts, pure) rewrites the
param values before the argv engine sees them and hands back the object it
was given when nothing changes, so a launch that is not root is
byte-identical (the spawn goldens are untouched).
- serverRunsAsRoot() (utils/server-uid.ts) reads the uid at call time. Under
vitest it answers false unless a test stubs it.
- The uid is asked in two places only. serverRootSpawnOptions() feeds the two
tmux launches (createSession, respawnPane), which every local tmux launch
goes through: new session, resume, dead-pane respawn, restartCli(), cron,
quick-start, reboot restore. buildPermissionArgs() covers the two launches
with no tmux, the direct-PTY fallback and the one-shot run.
- Remote and Docker pane commands never read it, and auto, allowedTools and
normal are passed through unchanged. IS_SANDBOX is not set.
- Each swap is logged once per launch, naming the cause and the way out.
Checked end to end in a throwaway ubuntu:24.04 container running this tree's
server as root with Claude Code 2.1.332: the pane command carries no bypass
flag, the pane stays alive on Claude's first-run screen, and the log line is
there. The same run as an ordinary user keeps the flag.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…udo step A non-root account with a working passwordless sudo and no controlling terminal (su - user -c, cron, a CI runner, cloud-init) ended on "Failed to obtain sudo privileges". The /dev/tty node exists there and cannot be opened; install.sh tested [[ -e /dev/tty ]] and then ran sudo -v < /dev/tty, whose redirect fails before sudo starts. Measured 2026-11-27 in a fresh ubuntu:24.04 container: node present, open refused, sudo -n true fine, install dead at "Installing Git via apt". - tty_openable() opens the node, the probe has_tty() already used, and every redirect from /dev/tty now sits behind it instead of a file test: ensure_sudo, sudo_session_try, the message choice in sudo_session_start, and the three sites with the same shape (Homebrew, the Tailscale installer, tailscale up). With no terminal they fall back to the plain command. - ensure_sudo returns as soon as sudo -n true works. sudo -v is no substitute for that test: it asks for a password as soon as one sudoers entry of the account asks for one, so an account in the sudo group with a NOPASSWD entry of its own (the cloud-image layout) runs sudo <command> freely and is refused by sudo -v (measured on sudo 1.9.15). test/install-sh-invariants.test.ts fails for a file test on /dev/tty and for a redirect from it that is not directly under the probe, and drives the sudo helpers in a real bash with no controlling terminal against a stub sudo. Checked in a throwaway ubuntu:24.04 container, through su - user -c with CODEMAN_NONINTERACTIVE=1: the installer before this change stops at the sudo step, this one installs git, tmux, Node.js and the build tools, clones and was building when the check was stopped. The helpers were also run under bash 3.2.57. The Homebrew branch could not be run here (no macOS). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two first-run failures of the public installer, found with a clean-machine check (
curl -fsSL https://getcodeman.com/install | bashin freshubuntu:24.04containers, 1.51.1). As a normal user at a terminal everything passed. Two other common setups did not.1. A server running as root: every Claude session died at once
Installed and started as root, which is the normal account on many VPSes and in Proxmox LXC containers, the install succeeds and shell sessions work, but every local Claude session is a dead pane:
The default permission mode launches Claude Code with
--dangerously-skip-permissions, and Claude Code refuses that flag under uid 0. Docker cases already handle the same refusal for a root container withoverlays.docker.rootCommand. This adds the host-level form, as registry data:rootValue: a map from a value to the value it takes when the server process runs as uid 0 and the launch is local. Claude declaresclaudeMode: { 'dangerously-skip-permissions': 'normal' }. The schema requires the keys and replacements to be among the param'svalues. No code outsidestock.tsnames a CLI.applyRootValues()(src/config/cli-registry/root-launch.ts, pure) rewrites the param values before the argv engine sees them. When nothing changes it returns the object it was given, so a launch that is not root is byte-identical; the spawn goldens are untouched.serverRunsAsRoot()(src/utils/server-uid.ts) reads the uid at call time. Under vitest it answers false unless a test stubs it, so the suite gives the same command lines when run as root.serverRootSpawnOptions()feeds the two tmux launches (createSession,respawnPane), which cover new session, resume, dead-pane respawn,restartCli(), cron, quick-start and reboot restore.buildPermissionArgs()covers the two launches without tmux: the direct-PTY fallback and the one-shot run.auto,allowedToolsandnormalpass through unchanged.IS_SANDBOXis not set: the bypass is not forced back on.So under root, Claude starts in normal mode and asks before it acts.
docs/wiki/Troubleshooting.mdgets a section for that, anddocs/cli-registry.mddocumentsrootValue.2. The installer stopped in headless runs with a passwordless sudo
A non-root account with working passwordless sudo and no controlling terminal (
su - user -c, cron, a CI runner, cloud-init) ended onFailed to obtain sudo privileges. The/dev/ttynode exists there but cannot be opened;install.shtested[[ -e /dev/tty ]]and then ransudo -v < /dev/tty, whose redirect fails before sudo starts.tty_openable()opens the node (the probehas_tty()already used), and every redirect from/dev/ttynow sits behind it instead of a file test:ensure_sudo,sudo_session_try, the message insudo_session_start, and the three sites of the same shape (Homebrew, the Tailscale installer,tailscale up). With no terminal they fall back to the plain command.ensure_sudoreturns as soon assudo -n trueworks.sudo -vis no substitute: it asks for a password as soon as one sudoers entry of the account does, so an account in thesudogroup with a NOPASSWD entry of its own (the cloud-image layout) runssudo <command>freely and is refused bysudo -v(measured on sudo 1.9.15).test/install-sh-invariants.test.tsfails on a file test of/dev/ttyand on a redirect from it that is not directly under the probe, and drives the sudo helpers in a real bash with no controlling terminal against a stub sudo. Bash 3.2 clean.How it was checked
ubuntu:24.04containers, installing this branch with its owninstall.sh:su - user -c,CODEMAN_NONINTERACTIVE=1): install exits 0 and the server answers. The same run on 1.51.1 stops at the sudo step;generate:cli-catalog --check,check:frontend-syntaxandbash -n install.shpass. Fullnpm test: 774 files passed, 1 skipped; 17,851 tests passed, 13 skipped.Two changesets (patch). Also one sentence in CLAUDE.md's CLI registry paragraph pointing at
rootValue.Not fixed here: on an image without the
en_US.UTF-8locale every pane starts withsetlocale: LC_ALL: cannot change locale (en_US.UTF-8). Cosmetic, separate change.