64 lines
2.0 KiB
Bash
Executable File
64 lines
2.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#ddev-generated
|
|
## Description: Run Claude Code CLI inside the web container
|
|
## Usage: claude [--account <n|email|alias>]
|
|
## Example: "ddev claude --version"
|
|
set -euo pipefail
|
|
|
|
INSTALL_SCRIPT="${DDEV_APPROOT}/.ddev/claude-code/install.sh"
|
|
SWAP_INSTALL_SCRIPT="${DDEV_APPROOT}/.ddev/claude-code/install-swap.sh"
|
|
PERSIST_BASE="${DDEV_APPROOT}/.ddev/claude-code"
|
|
PERSIST_HOME="${PERSIST_BASE}/home"
|
|
PERSIST_BIN="${PERSIST_HOME}/.local/bin/claude"
|
|
CSWAP_BIN="${PERSIST_HOME}/.local/bin/cswap"
|
|
|
|
# Optional multi-account routing: "ddev claude --account <sel>" starts a session
|
|
# pinned to a claude-swap account via "cswap run". With no flag, a project
|
|
# default can come from $DDEV_CLAUDE_SWAP_ACCOUNT or the first line of
|
|
# .ddev/claude-code/claude-swap-account. When neither is set this behaves
|
|
# exactly like a plain Claude Code launch.
|
|
ACCOUNT=""
|
|
ARGS=()
|
|
while [ $# -gt 0 ]; do
|
|
case "$1" in
|
|
--account=*) ACCOUNT="${1#--account=}"; shift ;;
|
|
--account|-A)
|
|
if [ $# -lt 2 ]; then
|
|
echo "ddev claude: --account requires an argument" >&2
|
|
exit 1
|
|
fi
|
|
ACCOUNT="$2"; shift 2 ;;
|
|
-A*) ACCOUNT="${1#-A}"; shift ;;
|
|
*) ARGS+=("$1"); shift ;;
|
|
esac
|
|
done
|
|
|
|
if [ -z "${ACCOUNT}" ]; then
|
|
if [ -n "${DDEV_CLAUDE_SWAP_ACCOUNT:-}" ]; then
|
|
ACCOUNT="${DDEV_CLAUDE_SWAP_ACCOUNT}"
|
|
elif [ -f "${PERSIST_BASE}/claude-swap-account" ]; then
|
|
ACCOUNT="$(head -n1 "${PERSIST_BASE}/claude-swap-account" | tr -d '[:space:]')"
|
|
fi
|
|
fi
|
|
|
|
"${INSTALL_SCRIPT}"
|
|
|
|
export HOME="${PERSIST_HOME}"
|
|
export XDG_CONFIG_HOME="${PERSIST_BASE}/config"
|
|
export XDG_DATA_HOME="${PERSIST_BASE}/data"
|
|
export XDG_STATE_HOME="${PERSIST_BASE}/state"
|
|
export PATH="${PERSIST_HOME}/.local/bin:${PATH}"
|
|
unset SSH_AUTH_SOCK
|
|
|
|
cd "${DDEV_APPROOT}"
|
|
|
|
if [ -n "${ACCOUNT}" ]; then
|
|
"${SWAP_INSTALL_SCRIPT}"
|
|
if [ "${#ARGS[@]}" -gt 0 ]; then
|
|
exec "${CSWAP_BIN}" run "${ACCOUNT}" -- "${ARGS[@]}"
|
|
fi
|
|
exec "${CSWAP_BIN}" run "${ACCOUNT}"
|
|
fi
|
|
|
|
exec "${PERSIST_BIN}" ${ARGS[@]+"${ARGS[@]}"}
|