Fix: bin/claude fallback workdir when cwd is outside mounted project

When CS Core's A2A server process (cwd = ~/.context-studio/core) runs
'claude --version' to check requirements, bin/claude passed --workdir $PWD
to podman exec. But the core dir is not mounted in the container, so
podman fails → check reports claude-code missing → server exits code 1.

Fix: if $PWD is not under $PROJECT_DIR (the only mounted path), fall back
to $PROJECT_DIR as the container workdir.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Eli 2026-03-09 13:43:30 +01:00
commit 16c0053d68

View file

@ -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"