Skip to content

fix: update fallback user in remote_user_run function to use current user#60

Open
darthrevan030 wants to merge 2 commits into
stu-bell:mainfrom
darthrevan030:fix/claude-code-remote-user-fallback
Open

fix: update fallback user in remote_user_run function to use current user#60
darthrevan030 wants to merge 2 commits into
stu-bell:mainfrom
darthrevan030:fix/claude-code-remote-user-fallback

Conversation

@darthrevan030

@darthrevan030 darthrevan030 commented May 19, 2026

Copy link
Copy Markdown

Fix: fall back to current user when UID 1000 does not exist

Problem:

When using this feature with standard Microsoft devcontainer base images (e.g. mcr.microsoft.com/devcontainers/typescript-node, python, go, cpp), the build fails with:
su: user vscode does not exist or the user entry does not contain all the required fields.

This happens because devcontainer features run during the Docker build phase, but the vscode user (UID 1000) is only created at container startup. So id -un 1000 fails and falls back to the hardcoded string "vscode", which doesn't exist in /etc/passwd at build time.

Fix

In util.sh, change the fallback in remote_user_run from:
sh_REMOTE_USER="$(id -un 1000 2>/dev/null || echo "vscode")" # vscode fallback
to:
sh_REMOTE_USER="$(id -un 1000 2>/dev/null || id -un)" # fallback to current user

id -un returns whoever is actually executing the script (root during build), which is guaranteed to exist. Claude Code's install script handles installing to the correct home directory regardless.

@FabianSchurig FabianSchurig left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @stu-bell The PR makes sense and LGTM, could you merge this, please. Thanks!

@FabianSchurig

Copy link
Copy Markdown

@darthrevan030 maybe you want to bump the version of the feature so tah it does not overwrite/ collide with the existing published one?

@darthrevan030

Copy link
Copy Markdown
Author

@FabianSchurig Done, bumped feature version to 1.0.1 and updated the version comment in util.sh too

@stu-bell

stu-bell commented Jun 2, 2026

Copy link
Copy Markdown
Owner

Hey @darthrevan030, I appreciate your work on this 🙌

Can you share a minimal reproducible example that causes the failure? For example, the following works fine for me, I'm able to build, shell in and launch claude without error:

{
  "image": "mcr.microsoft.com/devcontainers/typescript-node",
  "features": {
      "ghcr.io/stu-bell/devcontainer-features/claude-code": { }
  }
}

The first username is node, not vscode, but it exists when the feature is built, so the vscode fallback isn't triggered.

Please could you let me know:

  • host (mac/linux/windows)
  • container runtime and version (docker, podman, something else)
  • devcontainer tool and version (vscode, devcontainer cli, something else etc)
  • the devcontainer.json and dockerfile (if applicable) you're using
  • output of the build logs that includes the error

Your suggested fix may well be the answer, but I want to understand why you're getting the error and I'm not before merging.

Thanks!

@darthrevan030

Copy link
Copy Markdown
Author

Hey @stu-bell , here is the minimal reproducible example and the logs you requested.

Environment:

Host: Windows 11 (running via WSL 2 / Ubuntu)
Runtime: Docker Desktop v4.72.0 (Engine 29.4.2)
Tool: VS Code v1.120.0, Dev Containers Extension v0.459.0 (@devcontainers/cli 0.86.1)

MRE devcontainer.json:

{
  "name": "Node/TS",
  "image": "mcr.microsoft.com/devcontainers/typescript-node:24",
  "features": {
    "ghcr.io/stu-bell/devcontainer-features/claude-code:0": {}
  }
}

Build Log Output:

0.298 Installing Claude Code via https://claude.ai/install.sh
0.298 Note install script does not output progress...
0.298 Running as: vscode, command: curl -fsSL https://claude.ai/install.sh | bash
0.302 su: user vscode does not exist or the user entry does not contain all the required fields
0.302 ERROR: Feature "Claude Code" (ghcr.io/stu-bell/devcontainer-features/claude-code) failed to install!

Why it works for you but fails for me:
On your machine, during the Docker build phase, id -un 1000 is successfully resolving to node. Because it succeeds, it never hits the fallback.

On my setup (and likely others using Windows/WSL Dev Container CLI), id -un 1000 evaluates to nothing during this specific feature-installation layer. Because it fails to find UID 1000, it evaluates your fallback (|| echo "vscode"). Since the typescript-node image natively uses node and has no vscode user, the script executes su vscode and the build fatally crashes.

Falling back to id -un (as proposed in the PR) makes the script bulletproof. If UID 1000 isn't mapped or found during the build stage, it simply defaults to the current executing user (which is root during the container build), avoiding the su crash entirely. Claude Code's install script handles the rest perfectly.

Let me know if you need me to test anything else! Happy to share a full copy of the build logs if you need them!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants