diff --git a/lib/container.sh b/lib/container.sh index af3882c..224b1c5 100644 --- a/lib/container.sh +++ b/lib/container.sh @@ -17,6 +17,7 @@ generate_container_scripts() { # Claude Code wrapper — runs claude inside the agents container. # CS Core on the host calls this instead of the real claude binary. CONTAINER_NAME="${container_name}" +PROJECT_DIR="${project_dir}" RUNTIME="\$(command -v podman || command -v docker || true)" if [[ -z "\$RUNTIME" ]]; then @@ -30,11 +31,21 @@ if ! "\$RUNTIME" container inspect "\$CONTAINER_NAME" --format '{{.State.Running exit 1 fi +# Use PWD as workdir only if it is inside the mounted project tree. +# When CS Core's server process calls claude --version its cwd is the +# core directory (~/.context-studio/core) which is NOT mounted, causing +# podman exec --workdir to fail. Fall back to PROJECT_DIR in that case. +if [[ "\$PWD" == "\$PROJECT_DIR"* ]]; then + WORKDIR="\$PWD" +else + WORKDIR="\$PROJECT_DIR" +fi + # Pass through TTY if available, relay working directory into container if [ -t 0 ]; then - exec "\$RUNTIME" exec -it --workdir "\$PWD" "\$CONTAINER_NAME" claude "\$@" + exec "\$RUNTIME" exec -it --workdir "\$WORKDIR" "\$CONTAINER_NAME" claude "\$@" else - exec "\$RUNTIME" exec -i --workdir "\$PWD" "\$CONTAINER_NAME" claude "\$@" + exec "\$RUNTIME" exec -i --workdir "\$WORKDIR" "\$CONTAINER_NAME" claude "\$@" fi WRAPPER chmod +x "$project_dir/bin/claude"