Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions bin/omarchy-remove-agent
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/bin/bash

# omarchy:summary=Remove an Omarchy-managed coding agent CLI while keeping its data
# omarchy:args=[--check] <agent>
# omarchy:examples=omarchy remove agent codex | omarchy remove agent --check hermes
set -euo pipefail

mode=remove
if [[ ${1:-} == "--check" ]]; then mode=check; shift; fi
if (( $# != 1 )); then
echo "Usage: omarchy-remove-agent [--check] <agent>" >&2
exit 1
fi
agent=$1
case "$agent" in
codex) tool=codex; name='Codex CLI' ;;
cursor-agent) tool=cursor-agent; name='Cursor CLI' ;;
claude) tool=claude; name='Claude Code' ;;
crush) tool=crush; name=Crush ;;
agy) tool=antigravity-cli; name='Antigravity CLI' ;;
gemini) tool=gemini; name='Gemini CLI' ;;
copilot) tool=copilot; name='Copilot CLI' ;;
opencode) tool=opencode; name=OpenCode ;;
pi) tool=pi; name=Pi ;;
omp) tool=github:can1357/oh-my-pi; name='Oh My Pi' ;;
grok) tool=npm:@xai-official/grok; name='Grok CLI' ;;
ori) tool=github:OpenRouterLabs/ori-releases; name=Ori ;;
muse) tool='http:muse[url=https://api.meta.ai/muse-launcher.sh,bin=muse,version_list_url=https://api.meta.ai/muse-code/channels/muse-stable,version_json_path=.version]'; name='Muse Code' ;;
hermes) tool='pipx:hermes-agent[extras=all]'; name='Hermes CLI' ;;
*) echo 'Unknown agent.' >&2; exit 1 ;;
esac

wrapper="$HOME/.local/bin/$agent"
owned_wrapper() {
[[ -f $wrapper && ! -L $wrapper ]] || return 1
if [[ $agent == "hermes" ]]; then
! omarchy-pkg-present hermes-desktop && omarchy-install-hermes-cli --owns
else
# Match the complete generated wrapper, including older wrappers without
# the release-age setting. Do not remove a user's independent installation.
# Quote the RHS: backend options contain brackets, which are glob syntax.
local expected actual
actual=$(cat "$wrapper")
expected=$(printf '#!/bin/bash\nexport MISE_MINIMUM_RELEASE_AGE=0\nmise use -g --quiet "%s" || exit 1\nexec mise x "%s" -- "%s" "$@"\n' "$tool" "$tool" "$agent")
[[ $actual == "$expected" ]] && return 0
expected=$(printf '#!/bin/bash\nmise use -g --quiet "%s" || exit 1\nexec mise x "%s" -- "%s" "$@"\n' "$tool" "$tool" "$agent")
[[ $actual == "$expected" ]]
fi
}

# Return 0 for installed versions, 1 for none, and 2 for an unreadable inventory.
# A selected version may be missing while other versions remain installed.
has_installed_versions() {
local inventory
inventory=$(mise ls "$tool" --installed --json 2>/dev/null) || return 2
jq -e 'type == "array" and all(.[]; type == "object" and (.installed | type == "boolean"))' \
<<<"$inventory" >/dev/null 2>&1 || return 2
jq -e 'any(.[]; .installed == true)' <<<"$inventory" >/dev/null
}

installed() {
owned_wrapper && has_installed_versions
}

if [[ $mode == "check" ]]; then installed; exit $?; fi
if ! installed; then
echo "$name is not an installed Omarchy-managed CLI." >&2
exit 1
fi

gum confirm --default=false "Remove all mise-managed versions of $name? Chats and settings will be kept." || exit 130
# Recheck after the prompt in case another process replaced the launcher.
owned_wrapper || exit 1
if [[ $agent == "hermes" ]]; then
omarchy-install-hermes-cli --remove
else
mise rm -g --no-prune "$tool"
mise uninstall --all "$tool"
# Keep the wrapper if uninstall did not actually remove the environment.
if has_installed_versions; then
echo "$name still has a mise installation; launcher retained." >&2
exit 1
else
inventory_status=$?
if (( inventory_status != 1 )); then
echo "Could not verify $name removal; launcher retained." >&2
exit 1
fi
fi
owned_wrapper || exit 1
rm -f -- "$wrapper"
fi

default_file="$HOME/.config/omarchy/defaults/agent"
if [[ -f $default_file ]] && [[ $(cat "$default_file") == $agent ]]; then
rm -f -- "$default_file"
fi
printf '%s removed. Chats and settings were kept.\n' "$name"
15 changes: 15 additions & 0 deletions default/omarchy/omarchy-menu.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,21 @@
"remove.theme": {"icon":"󰸌","label":"Theme","action":"omarchy-theme-remove"},
"remove.gaming": {"icon":"","label":"Gaming","title":"Remove"},
"remove.browser": {"icon":"","label":"Browser","title":"Remove"},
"remove.agents": {"icon":"󰚩","label":"Agents","title":"Remove Agents"},
"remove.agents.agy": {"icon":"󰫢","label":"Antigravity","when":"omarchy-remove-agent --check agy","action":"omarchy-launch-floating-terminal-with-presentation omarchy-remove-agent agy"},
"remove.agents.claude": {"icon":"󰛄","label":"Claude Code","when":"omarchy-remove-agent --check claude","action":"omarchy-launch-floating-terminal-with-presentation omarchy-remove-agent claude"},
"remove.agents.codex": {"icon":"","iconFont":"omarchy","label":"Codex CLI","when":"omarchy-remove-agent --check codex","action":"omarchy-launch-floating-terminal-with-presentation omarchy-remove-agent codex"},
"remove.agents.copilot": {"icon":"","label":"Copilot CLI","when":"omarchy-remove-agent --check copilot","action":"omarchy-launch-floating-terminal-with-presentation omarchy-remove-agent copilot"},
"remove.agents.crush": {"icon":"󰋑","label":"Crush","when":"omarchy-remove-agent --check crush","action":"omarchy-launch-floating-terminal-with-presentation omarchy-remove-agent crush"},
"remove.agents.cursor-agent": {"icon":"","iconFont":"omarchy","label":"Cursor CLI","when":"omarchy-remove-agent --check cursor-agent","action":"omarchy-launch-floating-terminal-with-presentation omarchy-remove-agent cursor-agent"},
"remove.agents.grok": {"icon":"","iconFont":"omarchy","label":"Grok CLI","when":"omarchy-remove-agent --check grok","action":"omarchy-launch-floating-terminal-with-presentation omarchy-remove-agent grok"},
"remove.agents.hermes": {"icon":"","iconFont":"omarchy","label":"Hermes CLI","when":"omarchy-remove-agent --check hermes","action":"omarchy-launch-floating-terminal-with-presentation omarchy-remove-agent hermes"},
"remove.agents.muse": {"icon":"󰛤","label":"Muse Code","when":"omarchy-remove-agent --check muse","action":"omarchy-launch-floating-terminal-with-presentation omarchy-remove-agent muse"},
"remove.agents.omp": {"icon":"","iconFont":"omarchy","label":"Oh My Pi","when":"omarchy-remove-agent --check omp","action":"omarchy-launch-floating-terminal-with-presentation omarchy-remove-agent omp"},
"remove.agents.opencode": {"icon":"","iconFont":"omarchy","label":"OpenCode","when":"omarchy-remove-agent --check opencode","action":"omarchy-launch-floating-terminal-with-presentation omarchy-remove-agent opencode"},
"remove.agents.ori": {"icon":"","iconFont":"omarchy","label":"Ori","when":"omarchy-remove-agent --check ori","action":"omarchy-launch-floating-terminal-with-presentation omarchy-remove-agent ori"},
"remove.agents.pi": {"icon":"","iconFont":"omarchy","label":"Pi","when":"omarchy-remove-agent --check pi","action":"omarchy-launch-floating-terminal-with-presentation omarchy-remove-agent pi"},
"remove.agents.gemini": {"icon":"󰫢","label":"Gemini CLI","when":"omarchy-remove-agent --check gemini","action":"omarchy-launch-floating-terminal-with-presentation omarchy-remove-agent gemini"},
"remove.webapp": {"icon":"","label":"Web App","when":"grep -qE '^Exec=.*(omarchy-launch-webapp|omarchy-webapp-handler)' $HOME/.local/share/applications/*.desktop","action":"omarchy-webapp-remove"},
"remove.tui": {"icon":"","label":"TUI","when":"grep -qE '^Exec=.*(\\$TERMINAL|xdg-terminal-exec).*-e' $HOME/.local/share/applications/*.desktop","action":"omarchy-tui-remove"},
"remove.windows": {"icon":"󰍲","label":"Windows","when":"[[ -f $HOME/.local/share/applications/windows-vm.desktop ]]","action":"omarchy-launch-floating-terminal-with-presentation 'omarchy-windows-vm remove'"},
Expand Down
6 changes: 6 additions & 0 deletions manual/17-ai.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ Once you've chosen, `Super + Shift + Ctrl + A` launches the default agent in a d

There are terminal shortcuts too: `a` runs the default agent inline in the current terminal, while `c`, `cx`, and `cy` start OpenCode, Claude Code, and Codex directly (again in their auto-approving modes). Theme changes sync to the agents as well: Claude Code, Pi, OpenCode, and Hermes (once Hermes Desktop is installed) all follow along when you switch the Omarchy theme.

### Removing an agent

Use _Remove > Agents_ in the Omarchy Menu to uninstall a coding-agent CLI installed through Omarchy's mise launcher, or run `omarchy remove agent codex` with the agent's command name. Only installed agents with an Omarchy-managed launcher appear. Agents installed another way must be removed with their own installer.

After confirmation, removal deletes all mise-managed versions of that agent, including versions used by other projects, and its launcher. Chats, credentials, settings, and project files stay. If it was your default agent, that selection is cleared. Hermes Desktop and OpenClaw use their existing entries under _Remove > AI_.

### The agents panel

The top bar grows an agents icon the first time Omarchy finds AI coding usage on the machine (and stays out of the way until then). The panel behind it tracks every subscription in one place: your plan, the percentage used of the 5-hour session and weekly limits (or the remaining prepaid balance), and token usage by day and by model. Claude Code, Codex, and Fireworks are covered out of the box.
Expand Down
1 change: 1 addition & 0 deletions test/shell.d/menu-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ assertDeepEqual(
'remove.theme',
'remove.gaming',
'remove.browser',
'remove.agents',
'remove.webapp',
'remove.tui',
'remove.windows',
Expand Down
198 changes: 198 additions & 0 deletions test/shell.d/remove-agent-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
#!/bin/bash

set -euo pipefail

source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
require_command jq

test_tmp=$(mktemp -d)
trap 'rm -rf "$test_tmp"' EXIT
test_home="$test_tmp/home"
mock_bin="$test_tmp/bin"
inventory="$test_tmp/inventory.json"
log="$test_tmp/calls"
mkdir -p "$test_home/.config/omarchy/defaults" "$mock_bin"

cat >"$mock_bin/mise" <<'SH'
#!/bin/bash
printf '%s\n' "$*" >>"$OMARCHY_TEST_LOG"
case "$1" in
ls)
[[ ${OMARCHY_TEST_INVENTORY_FAIL:-false} == "false" ]] || exit 2
cat "$OMARCHY_TEST_INVENTORY"
;;
where) exit 1 ;; # A missing selected version must not hide installed versions.
rm) [[ ${OMARCHY_TEST_REMOVE_FAIL:-false} == "false" ]] ;;
uninstall)
[[ ${OMARCHY_TEST_UNINSTALL_FAIL:-false} == "false" ]] || exit 1
case ${OMARCHY_TEST_AFTER:-empty} in
empty) echo '[]' >"$OMARCHY_TEST_INVENTORY" ;;
remaining) ;;
malformed) echo invalid >"$OMARCHY_TEST_INVENTORY" ;;
unavailable) rm -f "$OMARCHY_TEST_INVENTORY" ;;
esac
;;
*) exit 99 ;;
esac
SH

cat >"$mock_bin/gum" <<'SH'
#!/bin/bash
printf 'gum %s\n' "$*" >>"$OMARCHY_TEST_LOG"
if [[ ${OMARCHY_TEST_REPLACE:-false} == "true" ]]; then
printf '#!/bin/bash\necho custom\n' >"$HOME/.local/bin/codex"
fi
[[ ${OMARCHY_TEST_CANCEL:-false} == "false" ]]
SH

cat >"$mock_bin/omarchy-pkg-present" <<'SH'
#!/bin/bash
[[ $1 == "hermes-desktop" && ${OMARCHY_TEST_DESKTOP:-false} == "true" ]]
SH
chmod +x "$mock_bin/"*

run_agent() {
env HOME="$test_home" OMARCHY_PATH="$ROOT" PATH="$mock_bin:$ROOT/bin:$PATH" \
OMARCHY_TEST_INVENTORY="$inventory" OMARCHY_TEST_LOG="$log" \
"$ROOT/bin/omarchy-remove-agent" "$@"
}

reset_fixture() {
rm -f "$test_home/.local/bin/codex"
env HOME="$test_home" "$ROOT/bin/omarchy-mise-install" codex
echo '[{"version":"1.0.0","installed":true,"active":false}]' >"$inventory"
echo codex >"$test_home/.config/omarchy/defaults/agent"
: >"$log"
}

reset_fixture
run_agent --check codex || fail "an installed version remains visible when the selected version is missing"
[[ $(cat "$log") == 'ls codex --installed --json' ]] || fail "visibility only reads installed versions"
pass "visibility uses the installed inventory, not the selected version"

echo '[]' >"$inventory"
if run_agent --check codex; then fail "a cold launcher is not an installed agent"; fi
echo invalid >"$inventory"
if run_agent --check codex; then fail "malformed inventory does not mark an agent installed"; fi
reset_fixture
if OMARCHY_TEST_INVENTORY_FAIL=true run_agent --check codex; then fail "inventory failure is not installation"; fi
pass "empty, malformed, and unavailable inventories do not offer removal"

for agent in claude crush copilot opencode pi cursor-agent gemini; do
env HOME="$test_home" "$ROOT/bin/omarchy-mise-install" "$agent"
run_agent --check "$agent" || fail "$agent recognizes its generated launcher"
done
for pair in 'antigravity-cli agy' 'github:can1357/oh-my-pi omp' 'npm:@xai-official/grok grok' 'github:OpenRouterLabs/ori-releases ori'; do
read -r package agent <<<"$pair"
env HOME="$test_home" "$ROOT/bin/omarchy-mise-install" "$package" "$agent"
: >"$log"
run_agent --check "$agent" || fail "$agent recognizes its generated launcher"
grep -Fx "ls $package --installed --json" "$log" >/dev/null || fail "$agent queries its backend package"
done
muse_package='http:muse[url=https://api.meta.ai/muse-launcher.sh,bin=muse,version_list_url=https://api.meta.ai/muse-code/channels/muse-stable,version_json_path=.version]'
env HOME="$test_home" "$ROOT/bin/omarchy-mise-install" "$muse_package" muse
run_agent --check muse || fail "Muse recognizes the HTTP-backend launcher"
pass "all generic agents recognize launchers generated by the real installer"

reset_fixture
sed -i '/^export MISE_MINIMUM_RELEASE_AGE=/d' "$test_home/.local/bin/codex"
run_agent --check codex || fail "older generated launchers remain removable"
pass "older generated launchers remain removable"

for kind in custom symlink; do
reset_fixture
if [[ $kind == "custom" ]]; then
echo custom >"$test_home/.local/bin/codex"
else
mv "$test_home/.local/bin/codex" "$test_home/codex-real"
ln -s "$test_home/codex-real" "$test_home/.local/bin/codex"
fi
if run_agent codex >"$test_tmp/output" 2>&1; then fail "$kind launcher cannot be removed"; fi
[[ -e $test_home/.local/bin/codex && ! -s $log ]] || fail "$kind launcher is untouched"
done
pass "custom launchers and symlinks are never removed"

reset_fixture
if OMARCHY_TEST_CANCEL=true run_agent codex; then fail "cancellation stops removal"; fi
[[ -f $test_home/.local/bin/codex ]] || fail "cancellation keeps the launcher"
! grep -q '^rm\|^uninstall' "$log" || fail "cancellation runs no mise mutation"
grep -F 'Remove all mise-managed versions' "$log" >/dev/null || fail "confirmation explains removal scope"
pass "cancellation preserves the installation"

reset_fixture
if OMARCHY_TEST_REPLACE=true run_agent codex; then fail "a replaced launcher stops removal"; fi
! grep -q '^rm\|^uninstall' "$log" || fail "replacement during confirmation prevents mise mutations"
pass "ownership is rechecked after confirmation"

for failure in remove uninstall remaining malformed unavailable; do
reset_fixture
case "$failure" in
remove) result=OMARCHY_TEST_REMOVE_FAIL=true ;;
uninstall) result=OMARCHY_TEST_UNINSTALL_FAIL=true ;;
*) result=OMARCHY_TEST_AFTER=$failure ;;
esac
if (export "$result"; run_agent codex) >"$test_tmp/output" 2>&1; then fail "$failure prevents success"; fi
[[ -f $test_home/.local/bin/codex ]] || fail "$failure retains the launcher"
[[ $(cat "$test_home/.config/omarchy/defaults/agent") == "codex" ]] || fail "$failure retains the default"
done
pass "failed removal and uncertain verification retain the launcher and default"

reset_fixture
mkdir -p "$test_home/.codex" "$test_home/project"
echo credentials >"$test_home/.codex/auth.json"
echo chat >"$test_home/.codex/session.jsonl"
echo project >"$test_home/project/file"
run_agent codex >/dev/null
[[ ! -e $test_home/.local/bin/codex ]] || fail "successful removal deletes the generated launcher"
[[ ! -e $test_home/.config/omarchy/defaults/agent ]] || fail "successful removal clears the matching default"
grep -Fx 'rm -g --no-prune codex' "$log" >/dev/null || fail "removal clears the global request"
grep -Fx 'uninstall --all codex' "$log" >/dev/null || fail "removal uninstalls the selected tool"
[[ $(cat "$test_home/.codex/auth.json") == "credentials" && $(cat "$test_home/.codex/session.jsonl") == "chat" && $(cat "$test_home/project/file") == "project" ]] || fail "user data stays intact"
pass "successful removal clears the launcher and matching default but preserves user data"

reset_fixture
echo claude >"$test_home/.config/omarchy/defaults/agent"
run_agent codex >/dev/null
[[ $(cat "$test_home/.config/omarchy/defaults/agent") == "claude" ]] || fail "another default agent stays selected"
pass "removing one agent preserves a different default"

reset_fixture
printf '#!/bin/bash\n# Written by omarchy-install-hermes-cli.\n' >"$test_home/.local/bin/hermes"
run_agent --check hermes || fail "the standalone Hermes install is visible"
if OMARCHY_TEST_DESKTOP=true run_agent --check hermes; then fail "Hermes Desktop belongs to Remove AI"; fi
mkdir -p "$test_home/.hermes"
echo memory >"$test_home/.hermes/memory"
echo hermes >"$test_home/.config/omarchy/defaults/agent"
run_agent hermes >/dev/null
[[ ! -e $test_home/.local/bin/hermes && ! -e $test_home/.config/omarchy/defaults/agent ]] || fail "Hermes removal clears its launcher and default"
[[ $(cat "$test_home/.hermes/memory") == "memory" ]] || fail "Hermes removal keeps its data"
grep -Fx 'uninstall --all pipx:hermes-agent[extras=all]' "$log" >/dev/null || fail "Hermes delegates to its existing remover"
pass "standalone Hermes uses its existing remover while desktop Hermes is excluded"

: >"$log"
for agent in '../codex' 'codex;touch nope' openclaw; do
if run_agent "$agent" >/dev/null 2>&1; then fail "unsupported names are rejected"; fi
done
if run_agent codex extra >/dev/null 2>&1; then fail "extra arguments are rejected"; fi
[[ ! -s $log ]] || fail "invalid input performs no operation"
pass "invalid names and arguments perform no operation"

run_node_test <<'JS'
const fs = require('fs')
const menu = requireFromRoot('shell/plugins/menu/MenuModel.js')
const entries = menu.parseMenuJsonc(fs.readFileSync(path.join(root, 'default/omarchy/omarchy-menu.jsonc'), 'utf8'))
const byId = Object.fromEntries(entries.map(entry => [entry.id, entry]))
const removers = entries.filter(entry => entry.id.startsWith('remove.agents.'))
assertEqual(removers.length, 14, 'the menu covers current mise agents and legacy Gemini')
for (const entry of removers) {
const agent = entry.id.split('.').at(-1)
assertEqual(entry.when, `omarchy-remove-agent --check ${agent}`, `${agent} visibility uses the remover`)
assertEqual(entry.action, `omarchy-launch-floating-terminal-with-presentation omarchy-remove-agent ${agent}`, `${agent} removal opens a confirmation terminal`)
const source = byId[`setup.default.agent.${agent}`]
if (source) {
assertEqual(entry.icon, source.icon, `${agent} uses its branded glyph`)
assertEqual(entry.iconFont, source.iconFont, `${agent} uses its icon font`)
}
}
assert(!byId['remove.agents.openclaw'], 'package-managed OpenClaw keeps its existing remover')
JS