#!/usr/bin/env bash # Entrypoint for the Claude Code container. # Creates a user matching the host UID/GID so that files created # inside the container have the correct ownership on the host volume. set -e # claude.sh starts a git worktree in its host path. env.sh sets paths from # its own location, so source the copy there to keep the paths the same. ENV_SH=/workspace/env.sh if [ -f "${PWD}/env.sh" ]; then ENV_SH="${PWD}/env.sh" fi if [ -n "${HOST_UID}" ] && [ -n "${HOST_GID}" ]; then USER_NAME="claude-user" USER_HOME="/home/${USER_NAME}" # Create group (reuse existing if GID is taken) if ! getent group "${HOST_GID}" > /dev/null 2>&1; then groupadd --gid "${HOST_GID}" "${USER_NAME}" fi GROUP_NAME=$(getent group "${HOST_GID}" | cut -d: -f1) # Create user (reuse existing if UID is taken) if ! getent passwd "${HOST_UID}" > /dev/null 2>&1; then useradd \ --uid "${HOST_UID}" \ --gid "${HOST_GID}" \ --groups sudo \ --no-create-home \ --home-dir "${USER_HOME}" \ --shell /bin/bash \ "${USER_NAME}" else USER_NAME=$(getent passwd "${HOST_UID}" | cut -d: -f1) usermod --home "${USER_HOME}" "${USER_NAME}" fi # Passwordless sudo echo "${USER_NAME} ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/claude-user chmod 0440 /etc/sudoers.d/claude-user # The engine creates .cache as root when it mounts .cache/bazel. # Bazelisk writes to .cache/bazelisk, so the user owns .cache too. mkdir -p "${USER_HOME}/.cache" export HOME="${USER_HOME}" chown "${HOST_UID}:${HOST_GID}" "${USER_HOME}" "${USER_HOME}/.cache" touch "${USER_HOME}/.hushlogin" # Set up ORFS environment (PATH to tools, FLOW_HOME, etc.) # Sourced here; inherited through setpriv into all child processes. if [ -f "${ENV_SH}" ]; then set +e . "${ENV_SH}" > /dev/null set -e fi exec setpriv \ --reuid "${HOST_UID}" \ --regid "${HOST_GID}" \ --init-groups \ -- "$@" else # No UID/GID mapping requested; run as root if [ -f "${ENV_SH}" ]; then set +e . "${ENV_SH}" > /dev/null set -e fi exec "$@" fi