plandex-ai/plandex · error
failed to apply update due to permission error; please try r
Error message
failed to apply update due to permission error; please try running your command again with 'sudo': %w
What it means
When the 'plandex' binary is found in the tar, update.Apply (github.com/inconshreveable/go-update) swaps it in place. If that fails specifically with fs.ErrPermission, the CLI returns a dedicated message advising 'sudo'. go-update needs write permission on the installed executable's path (and possibly the containing directory when it renames the file into place).
Source
Thrown at app/cli/upgrade.go:150
}
defer gzr.Close()
tarReader := tar.NewReader(gzr)
for {
header, err := tarReader.Next()
if err == io.EOF {
break // End of archive
}
if err != nil {
return fmt.Errorf("failed to read tar header: %w", err)
}
// Check if the current file is the binary
if header.Typeflag == tar.TypeReg && (header.Name == "plandex" || header.Name == "plandex.exe") {
err = update.Apply(tarReader, update.Options{})
if err != nil {
if errors.Is(err, fs.ErrPermission) {
return fmt.Errorf("failed to apply update due to permission error; please try running your command again with 'sudo': %w", err)
}
return fmt.Errorf("failed to apply update: %w", err)
}
break
}
}
return nil
}
func restartPlandex() {
exe, err := os.Executable()
if err != nil {
term.OutputErrorAndExit("Failed to determine executable path: %v", err)
}
cmd := exec.Command(exe, os.Args[1:]...)
cmd.Stdin = os.StdinView on GitHub (pinned to e2d772072e)
Solutions
- Re-run the upgrade command with sudo: sudo plandex (then accept the upgrade prompt).
- Move the binary to a user-writable location, e.g. ~/.local/bin, and update PATH.
- chown the binary to your user: sudo chown $(whoami) $(which plandex).
- Reinstall via the official install script into a user-owned prefix.
Example fix
// before: user-writable install avoids the error $ ls -l /usr/local/bin/plandex # root-owned, upgrade fails // after $ sudo chown $(whoami) /usr/local/bin/plandex $ # or relocate: $ mv /usr/local/bin/plandex ~/.local/bin/ && export PATH=$HOME/.local/bin:$PATH
Defensive patterns
Strategy: fallback
Validate before calling
exe, _ := os.Executable()
fi, err := os.Stat(exe)
if err == nil {
if unix.Access(exe, unix.W_OK) != nil || fi.Mode().Perm()&0200 == 0 {
fmt.Println("Binary not writable by current user; run with sudo or reinstall to a user-owned path")
}
} Try / catch
err = update.Apply(tarReader, update.Options{})
if err != nil {
if errors.Is(err, fs.ErrPermission) {
fmt.Println("Permission denied replacing binary. Re-run with sudo, or reinstall to ~/.local/bin")
return
}
return err
} Prevention
- Install the binary in a user-writable directory (e.g. ~/.local/bin)
- Avoid root-owned installs if you plan to self-update
- Check writability of os.Executable() before attempting upgrade
- Use sudo deliberately for system-path installs
When it happens
Trigger: update.Apply fails with a permission error because the installed plandex binary (e.g. /usr/local/bin/plandex) is owned by root or the user lacks write access to it or its directory.
Common situations: plandex was originally installed with sudo into /usr/local/bin; system-managed install paths; non-root user running the self-upgrade.
Understand the failure class
Background: Permission denied / not authorized / 403 Forbidden: access-control rejections when the caller lacks the required role, grant, or ownership — this error's family across 18 libraries.
Related errors
- error setting auth: %v
- error writing auth: %v
- error reading accounts.json: %v
- error walking directory: %s
- error checking for .plandexignore file: %s
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/d0599571879c94fa.
Report an issue: GitHub.