Apply agent account selection to CLI subprocesses (#14233)

* Apply agent account selection to CLI subprocesses

* Fix account dispatch edge cases and remove redundant shell wrappers

* Use the current account when launching a new agent session
This commit is contained in:
David Heinemeier Hansson authored and GitHub committed 2026-10-04 09:01:06 -04:00
1 parent 5657a91f8d
commit f9646299bf
15 files changed
+351 -67

No files matched your search

+15 -7
View File
@@ -136,19 +136,27 @@ pi)
;;
esac
# Claude, Codex, and Grok start as the active subscription account, the same
# as the shell functions in default/bash/fns/agent-accounts. The home travels
# in the command itself, since a terminal launched through uwsm doesn't
# inherit this process's environment.
# A new session uses the current selection rather than its parent's account
# pin. Explicit provider homes still override the selection. Carry the new pin
# in the command, since terminals launched through uwsm don't inherit our env.
case "$agent" in
claude) home_env="CLAUDE_CONFIG_DIR" ;;
codex) home_env="CODEX_HOME" ;;
grok) home_env="GROK_HOME" ;;
*) home_env="" ;;
esac
if [[ -n $home_env && -z ${!home_env:-} ]]; then
home=$(omarchy-agent-account-home "$agent")
[[ -n $home ]] && command=(env "$home_env=$home" "${command[@]}")
if [[ -n $home_env ]]; then
account_pin="OMARCHY_AGENT_${agent^^}_HOME"
if [[ -v $account_pin && ${!home_env:-} == "${!account_pin}" ]]; then
unset "$home_env"
fi
unset "$account_pin"
if [[ -z ${!home_env:-} ]]; then
home=$(omarchy-agent-account-home "$agent")
account_env=(env -u "$home_env" "$account_pin=$home")
[[ -n $home ]] && account_env+=("$home_env=$home")
command=("${account_env[@]}" "${command[@]}")
fi
fi
if [[ $inline == "true" ]]; then