chore: initial commit

This commit is contained in:
Björn Fromme committed 2026-09-16 12:37:50 +02:00
commit 63f3199076
9 files changed
+567

No files matched your search

+85
View File
@@ -0,0 +1,85 @@
#!/usr/bin/env bash
#ddev-generated
set -euo pipefail
# Lazy installer for claude-swap (cswap): a multi-account manager for Claude Code.
# It is NOT installed during "ddev start" - the first "ddev claude-swap ..." call
# (or "ddev claude --account ...") runs this script, which installs uv and then
# "claude-swap" into the same project-local, persisted profile that the Claude
# Code CLI uses. Pass --upgrade to update an existing install.
#
# All state lives under .ddev/claude-code so it survives container rebuilds
# without being committed to the project repository, exactly like install.sh.
PERSIST_BASE="${DDEV_APPROOT}/.ddev/claude-code"
PERSIST_HOME="${PERSIST_BASE}/home" # replaces $HOME inside the container
PERSIST_CONFIG_HOME="${PERSIST_BASE}/config" # XDG_CONFIG_HOME
PERSIST_DATA_HOME="${PERSIST_BASE}/data" # XDG_DATA_HOME
PERSIST_STATE_HOME="${PERSIST_BASE}/state" # XDG_STATE_HOME
PERSIST_BIN_DIR="${PERSIST_HOME}/.local/bin" # shared with the claude launcher
UV_BIN="${PERSIST_BIN_DIR}/uv"
CSWAP_BIN="${PERSIST_BIN_DIR}/cswap"
mkdir -p \
"${PERSIST_HOME}" \
"${PERSIST_CONFIG_HOME}" \
"${PERSIST_DATA_HOME}" \
"${PERSIST_STATE_HOME}" \
"${PERSIST_BIN_DIR}"
# Point HOME / XDG paths at the persisted profile before any install or health
# check so cswap's own data (Linux: ${XDG_DATA_HOME}/claude-swap) is per-project
# and survives restarts with no extra configuration.
export HOME="${PERSIST_HOME}"
export XDG_CONFIG_HOME="${PERSIST_CONFIG_HOME}"
export XDG_DATA_HOME="${PERSIST_DATA_HOME}"
export XDG_STATE_HOME="${PERSIST_STATE_HOME}"
export PATH="${PERSIST_BIN_DIR}:${PATH}"
# Keep every artifact uv creates inside the persisted tree.
export UV_INSTALL_DIR="${PERSIST_BIN_DIR}" # uv / uvx binaries
export UV_TOOL_BIN_DIR="${PERSIST_BIN_DIR}" # tool entry points (cswap)
export UV_TOOL_DIR="${XDG_DATA_HOME}/uv/tools" # tool virtualenvs
export UV_PYTHON_INSTALL_DIR="${XDG_DATA_HOME}/uv/python" # uv-managed CPython
export UV_CACHE_DIR="${XDG_DATA_HOME}/uv/cache" # download / build cache
# Remove an unrunnable persisted uv (e.g. wrong arch after a host OS change).
if [ -x "${UV_BIN}" ] && ! "${UV_BIN}" --version >/dev/null 2>&1; then
echo "Persisted uv binary is not runnable, reinstalling ..."
rm -f "${UV_BIN}" "${PERSIST_BIN_DIR}/uvx"
fi
# Install uv when missing. uv fetches its own CPython 3.12 below, so the DDEV web
# image's system Python (3.11) is never relied upon. Do not let the installer
# edit shell rc files in the persisted HOME - PATH is set by the launchers.
if [ ! -x "${UV_BIN}" ]; then
echo "Installing uv ..."
curl -fsSL https://astral.sh/uv/install.sh | env INSTALLER_NO_MODIFY_PATH=1 sh
fi
if [ ! -x "${UV_BIN}" ]; then
echo "uv installation completed but no executable was found at ${UV_BIN}." >&2
echo "If outbound access to astral.sh is blocked this step cannot succeed." >&2
exit 1
fi
if [ "${1:-}" = "--upgrade" ]; then
echo "Upgrading claude-swap ..."
"${UV_BIN}" tool upgrade claude-swap
echo "claude-swap version: $("${CSWAP_BIN}" --version)"
exit 0
fi
# Install claude-swap when missing or unrunnable.
if [ ! -x "${CSWAP_BIN}" ] || ! "${CSWAP_BIN}" --version >/dev/null 2>&1; then
echo "Installing claude-swap ..."
"${UV_BIN}" tool install --force --python 3.12 claude-swap
fi
if [ ! -x "${CSWAP_BIN}" ] || ! "${CSWAP_BIN}" --version >/dev/null 2>&1; then
echo "claude-swap installation completed but ${CSWAP_BIN} is not runnable." >&2
echo "First install needs outbound access to astral.sh, pypi.org," >&2
echo "files.pythonhosted.org and github.com (uv-managed CPython)." >&2
exit 1
fi
echo "claude-swap version: $("${CSWAP_BIN}" --version)"
+76
View File
@@ -0,0 +1,76 @@
#!/usr/bin/env bash
#ddev-generated
set -euo pipefail
# All Claude Code state is stored under .ddev/claude-code so it survives
# container rebuilds without being committed to the project repository.
PERSIST_BASE="${DDEV_APPROOT}/.ddev/claude-code"
PERSIST_HOME="${PERSIST_BASE}/home" # replaces $HOME inside the container
PERSIST_CONFIG_HOME="${PERSIST_BASE}/config" # XDG_CONFIG_HOME (e.g. ~/.config)
PERSIST_DATA_HOME="${PERSIST_BASE}/data" # XDG_DATA_HOME (e.g. ~/.local/share)
PERSIST_STATE_HOME="${PERSIST_BASE}/state" # XDG_STATE_HOME (e.g. ~/.local/state)
PERSIST_BIN_DIR="${PERSIST_HOME}/.local/bin" # Claude native installer target
PERSIST_BIN="${PERSIST_BIN_DIR}/claude" # full path to the claude executable
PERSIST_GITIGNORE_GLOBAL="${PERSIST_HOME}/.gitignore_global" # mirrors $HOME/.gitignore_global
# Capture the container's original HOME before we override it below, so we can
# seed the persisted gitignore from the container image on first run.
CONTAINER_HOME="${HOME:?HOME must be set}"
CONTAINER_GITIGNORE_GLOBAL="${CONTAINER_HOME}/.gitignore_global"
# Ensure all persistence directories exist.
mkdir -p \
"${PERSIST_HOME}" \
"${PERSIST_CONFIG_HOME}" \
"${PERSIST_DATA_HOME}" \
"${PERSIST_STATE_HOME}" \
"${PERSIST_BIN_DIR}"
# Seed the persisted gitignore from the container image on first run only.
if [ -f "${CONTAINER_GITIGNORE_GLOBAL}" ] && [ ! -f "${PERSIST_GITIGNORE_GLOBAL}" ]; then
cp -f "${CONTAINER_GITIGNORE_GLOBAL}" "${PERSIST_GITIGNORE_GLOBAL}"
fi
# Claude Code's native installer stores its launcher, auth, settings, downloads,
# and versioned package data relative to HOME/XDG paths.
export HOME="${PERSIST_HOME}"
export XDG_CONFIG_HOME="${PERSIST_CONFIG_HOME}"
export XDG_DATA_HOME="${PERSIST_DATA_HOME}"
export XDG_STATE_HOME="${PERSIST_STATE_HOME}"
export PATH="${PERSIST_BIN_DIR}:${PATH}"
# If a persisted binary exists but fails to run (e.g. wrong architecture after
# a host OS change), remove it so the install step below fetches a fresh copy.
if [ -x "${PERSIST_BIN}" ] && ! "${PERSIST_BIN}" --version >/dev/null 2>&1; then
echo "Persisted Claude Code binary is not runnable, reinstalling ..."
rm -f "${PERSIST_BIN}"
fi
# Download and install the current stable Claude Code native build only when
# missing. Use "ddev claude update" to check for and install newer versions.
if [ ! -x "${PERSIST_BIN}" ]; then
echo "Installing Claude Code CLI ..."
curl -fsSL https://claude.ai/install.sh | bash -s stable
fi
# Verify the binary is present and runnable after installation.
if [ ! -x "${PERSIST_BIN}" ]; then
echo "Claude Code installation completed but no executable was found at ${PERSIST_BIN}." >&2
exit 1
fi
if ! "${PERSIST_BIN}" --version >/dev/null 2>&1; then
echo "Claude Code installation completed but ${PERSIST_BIN} is not runnable." >&2
exit 1
fi
# Point git's global excludes file at the persisted copy when available,
# so git inside the container respects user-defined ignore patterns.
if command -v git >/dev/null 2>&1 && [ -f "${PERSIST_GITIGNORE_GLOBAL}" ]; then
CURRENT_EXCLUDESFILE="$(git config --global --get core.excludesfile || true)"
if [ "${CURRENT_EXCLUDESFILE}" != "${PERSIST_GITIGNORE_GLOBAL}" ]; then
git config --global core.excludesfile "${PERSIST_GITIGNORE_GLOBAL}"
fi
fi
echo "Claude Code version: $("${PERSIST_BIN}" --version)"