#!/usr/bin/env bash set -euo pipefail # install.sh -- install Claude Code for this user. # Installs or updates the Claude Code binary, then writes the systemd user # drop-in $XDG_CONFIG_HOME/environment.d/50-claude.conf, which points # CLAUDE_CONFIG_DIR at this repo and disables Claude Code auto-memory. # Idempotent; the drop-in takes effect on next login. Run standalone or via # `dotfiles sync`. # Install or update the Claude Code binary. if command -v claude >/dev/null; then claude update else curl -fsSL https://claude.ai/install.sh | bash fi # The drop-in location depends on XDG_CONFIG_HOME. When it is unset, fall back # to ~/.config, but warn first and, when interactive, pause so the user can set # it and re-run rather than silently landing on the default. config_home=${XDG_CONFIG_HOME:-$HOME/.config} if [[ -z ${XDG_CONFIG_HOME:-} ]]; then echo "Warning: XDG_CONFIG_HOME is unset; defaulting to $config_home." >&2 if [[ -t 0 ]]; then read -rp "Set it and re-run, or Enter to use the default… " fi fi dst="$config_home/environment.d/50-claude.conf" # Literal $HOME so systemd environment.d expands it at login. content='CLAUDE_CONFIG_DIR=$HOME/.config/claude CLAUDE_CODE_DISABLE_AUTO_MEMORY=1' mkdir --parents "${dst%/*}" if [[ -f $dst ]] && [[ $(cat "$dst") == "$content" ]]; then echo "$dst already up to date" else printf '%s\n' "$content" >"$dst" echo "Installed $dst" fi # environment.d is read only at login: warn if the drop-in's vars are not yet # active in this session, so the user knows to log back in. for var in CLAUDE_CONFIG_DIR CLAUDE_CODE_DISABLE_AUTO_MEMORY; do if [[ -z ${!var:-} ]]; then echo "Log back in to load $dst into this session." break fi done