#compdef remuda

autoload -U is-at-least

_remuda() {
    typeset -A opt_args
    typeset -a _arguments_options
    local ret=1

    if is-at-least 5.2; then
        _arguments_options=(-s -S -C)
    else
        _arguments_options=(-s -C)
    fi

    local context curcontext="$curcontext" state line
    _arguments "${_arguments_options[@]}" : \
'(--check-update)--update[Replace this binary with the latest release]' \
'--check-update[Only report whether a newer release exists]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
":: :_remuda_commands" \
"*::: :->remuda" \
&& ret=0
    case $state in
    (remuda)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:remuda-command-$line[1]:"
        case $line[1] in
            (list)
_arguments "${_arguments_options[@]}" : \
'--json[]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(import)
_arguments "${_arguments_options[@]}" : \
'-p+[]:PROVIDER:(claude codex copilot cursor deepseek glm grok kimi minimax opencode openrouter)' \
'--provider=[]:PROVIDER:(claude codex copilot cursor deepseek glm grok kimi minimax opencode openrouter)' \
'--force[Replace a stored credential of the same name]' \
'-h[Print help]' \
'--help[Print help]' \
':name:_default' \
&& ret=0
;;
(login)
_arguments "${_arguments_options[@]}" : \
'-p+[]:PROVIDER:(claude codex copilot cursor deepseek glm grok kimi minimax opencode openrouter)' \
'--provider=[]:PROVIDER:(claude codex copilot cursor deepseek glm grok kimi minimax opencode openrouter)' \
'--browser=[The browser to open it in, overriding \`\[login\] browser\`]:BROWSER:(brave brave-beta brave-nightly chrome chrome-beta chrome-unstable chromium vivaldi vivaldi-snapshot edge edge-beta edge-dev firefox firefox-esr firefox-developer-edition librewolf)' \
'--window=[A private window, the login'\''s own profile, or a normal window, overriding \`\[login\] window\`]:WINDOW:_default' \
'--force[]' \
'--no-browser[Only print the link; never offer to open it here]' \
'--paste[Sign in from a browser on another machine instead of through a callback here\: Claude Code ends with a code to paste back, Codex with a device code to type in. The default over SSH, or with no display]' \
'(--paste)--no-paste[Be called back even over SSH, or with \`\[login\] paste = true\`]' \
'-h[Print help]' \
'--help[Print help]' \
':name:_default' \
&& ret=0
;;
(export)
_arguments "${_arguments_options[@]}" : \
'*--move=[Carry this login'\''s tokens and drop it here once sent, for a machine being retired. NAME or PROVIDER/NAME, repeatable]:NAME:_default' \
'--passphrase-file=[Read the passphrase from this file'\''s first line]:FILE:_files' \
'--without-s3-keys[Leave TokenGauge'\''s S3 keys out of the fleet it carries]' \
'-h[Print help]' \
'--help[Print help]' \
'::file -- Seal it into this file instead of sending it:_files' \
&& ret=0
;;
(restore)
_arguments "${_arguments_options[@]}" : \
'--passphrase-file=[Read the passphrase from this file'\''s first line]:FILE:_files' \
'--force[Replace logins, config.toml, the proxy'\''s settings and the fleet already here]' \
'--no-sign-in[List the logins to sign in again instead of starting them]' \
'--paste[Sign in again from a browser on another machine, as \`remuda login --paste\` does. The default over SSH or, on Linux, with no display]' \
'(--paste)--no-paste[Be called back even over SSH, or with \`\[login\] paste = true\`]' \
'-h[Print help]' \
'--help[Print help]' \
'::file -- Open this sealed file instead of receiving it:_files' \
&& ret=0
;;
(use)
_arguments "${_arguments_options[@]}" : \
'--discard[Switch even when the live login is not in the store, dropping it]' \
'-h[Print help]' \
'--help[Print help]' \
':name:_default' \
&& ret=0
;;
(signout)
_arguments "${_arguments_options[@]}" : \
'--discard[Sign out even when the live login is not in the store, dropping it]' \
'-h[Print help]' \
'--help[Print help]' \
':provider:(claude codex copilot cursor deepseek glm grok kimi minimax opencode openrouter)' \
&& ret=0
;;
(refresh)
_arguments "${_arguments_options[@]}" : \
'--within=[Refresh anything expiring within this many minutes]:WITHIN:_default' \
'--force[Refresh even when the access token is still fresh]' \
'--scheduled[Run as the refresh timer\: stop where the directories differ from the ones the last interactive command used]' \
'-h[Print help]' \
'--help[Print help]' \
'::name:_default' \
&& ret=0
;;
(label)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
':name:_default' \
'::text:_default' \
&& ret=0
;;
(env)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
':name:_default' \
&& ret=0
;;
(rename)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
':name:_default' \
':new_name:_default' \
&& ret=0
;;
(remove)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
':name:_default' \
&& ret=0
;;
(auto)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(doctor)
_arguments "${_arguments_options[@]}" : \
'--json[Print the vitals as JSON]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(run)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
':name:_default' \
'*::args:_default' \
&& ret=0
;;
(pin)
_arguments "${_arguments_options[@]}" : \
'()--remove=[Unpin this CLI from ./.remuda.toml instead]:CLI:_default' \
'(--remove)--allow[Trust the nearest .remuda.toml as it is now\: one written by anything but \`remuda pin\`, a clone'\''s for one, is not read until allowed]' \
'-h[Print help]' \
'--help[Print help]' \
'::name:_default' \
&& ret=0
;;
(shell-init)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
':shell:_default' \
&& ret=0
;;
(log)
_arguments "${_arguments_options[@]}" : \
'-n+[How many of the latest events to show]:LINES:_default' \
'--lines=[How many of the latest events to show]:LINES:_default' \
'--json[Print the events as JSON]' \
'-h[Print help]' \
'--help[Print help]' \
'::name -- A provider (claude), a login (claude/work) or a bare name:_default' \
&& ret=0
;;
(serve)
_arguments "${_arguments_options[@]}" : \
'--port=[]:PORT:_default' \
'--no-browser[Print the URL instead of opening it]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(open)
_arguments "${_arguments_options[@]}" : \
'--no-browser[Print the URL instead of opening it]' \
'--add[Land on the sheet that adds an account]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(completions)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
':shell:(bash elvish fish powershell zsh)' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
'*::topic:_default' \
&& ret=0
;;
(hook)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
':what:_default' \
&& ret=0
;;
(sync-units)
_arguments "${_arguments_options[@]}" : \
'*--install=[]:INSTALL:_default' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
        esac
    ;;
esac
}

(( $+functions[_remuda_commands] )) ||
_remuda_commands() {
    local commands; commands=(
'list:List stored credentials and which one each CLI is using' \
'import:Store the login a CLI is signed into right now' \
'login:Sign a new account in through the browser and store it, without touching the CLI' \
'export:Send this machine'\''s logins and settings to another one, through wyrmyon or magic-wormhole when installed, or sealed into FILE under a passphrase' \
'restore:Set this machine up from what \`remuda export\` sent, then sign in again the logins that cannot be copied' \
'use:Make a stored credential the one its CLI uses. NAME or PROVIDER/NAME' \
'signout:Take the login out of a CLI'\''s own files, keeping it in the store' \
'refresh:Refresh the tokens of the inactive credentials that are close to expiring' \
'label:Set the label shown beside a credential, or clear it. NAME or PROVIDER/NAME' \
'env:Print the shell line that makes a CLI reading its key from the environment use a stored one\: \`eval "\$(remuda env glm/work)"\`' \
'rename:Rename a stored credential. NAME or PROVIDER/NAME' \
'remove:Delete a stored credential. NAME or PROVIDER/NAME' \
'auto:Say which login auto mode puts each CLI on now, and why, without switching' \
'doctor:Check what remuda relies on\: the service, the refresh timer, TokenGauge, the stored and live logins, the CLIs'\'' versions' \
'run:Start a CLI on a stored login without switching the one every other session uses\: NAME, PROVIDER/NAME, or a provider alone for the login \`.remuda.toml\` pins here, else the one it uses now. Anything after \`--\` goes to the CLI' \
'pin:Pin a login for this directory and below in ./.remuda.toml, so \`remuda run <cli>\` starts it there; with no NAME, show the pins in force' \
'shell-init:Print shell functions that start \`claude\` and \`codex\` through \`remuda run\`, for the login pinned where they start\: \`eval "\$(remuda shell-init zsh)"\`' \
'log:Show what remuda did\: switches and who made them, refreshes, auto mode, keep-warm, the proxy. PROVIDER, NAME or PROVIDER/NAME narrows it' \
'serve:Serve a local page to list, switch and sign in credentials from the browser' \
'open:Open the page a running \`remuda serve\` shows, starting remuda-serve.service when it is installed' \
'completions:Print a completion script for a shell' \
'help:Show the help of a command, or a topic\: skill (a SKILL.md that tells Claude Code sessions how to live with remuda, and the artifact hook)' \
'hook:Run by Claude Code'\''s hooks on its artifact tools\: \`remuda hook artifact\` reads the event on stdin and switches to the login that published the artifact for the call. Never fails the call' \
'sync-units:Run by \`--update\` as the new binary\: bring the installed units up to date. On macOS install.sh asks it for the agents with \`--install\`' \
    )
    _describe -t commands 'remuda commands' commands "$@"
}
(( $+functions[_remuda__subcmd__auto_commands] )) ||
_remuda__subcmd__auto_commands() {
    local commands; commands=()
    _describe -t commands 'remuda auto commands' commands "$@"
}
(( $+functions[_remuda__subcmd__completions_commands] )) ||
_remuda__subcmd__completions_commands() {
    local commands; commands=()
    _describe -t commands 'remuda completions commands' commands "$@"
}
(( $+functions[_remuda__subcmd__doctor_commands] )) ||
_remuda__subcmd__doctor_commands() {
    local commands; commands=()
    _describe -t commands 'remuda doctor commands' commands "$@"
}
(( $+functions[_remuda__subcmd__env_commands] )) ||
_remuda__subcmd__env_commands() {
    local commands; commands=()
    _describe -t commands 'remuda env commands' commands "$@"
}
(( $+functions[_remuda__subcmd__export_commands] )) ||
_remuda__subcmd__export_commands() {
    local commands; commands=()
    _describe -t commands 'remuda export commands' commands "$@"
}
(( $+functions[_remuda__subcmd__help_commands] )) ||
_remuda__subcmd__help_commands() {
    local commands; commands=()
    _describe -t commands 'remuda help commands' commands "$@"
}
(( $+functions[_remuda__subcmd__hook_commands] )) ||
_remuda__subcmd__hook_commands() {
    local commands; commands=()
    _describe -t commands 'remuda hook commands' commands "$@"
}
(( $+functions[_remuda__subcmd__import_commands] )) ||
_remuda__subcmd__import_commands() {
    local commands; commands=()
    _describe -t commands 'remuda import commands' commands "$@"
}
(( $+functions[_remuda__subcmd__label_commands] )) ||
_remuda__subcmd__label_commands() {
    local commands; commands=()
    _describe -t commands 'remuda label commands' commands "$@"
}
(( $+functions[_remuda__subcmd__list_commands] )) ||
_remuda__subcmd__list_commands() {
    local commands; commands=()
    _describe -t commands 'remuda list commands' commands "$@"
}
(( $+functions[_remuda__subcmd__log_commands] )) ||
_remuda__subcmd__log_commands() {
    local commands; commands=()
    _describe -t commands 'remuda log commands' commands "$@"
}
(( $+functions[_remuda__subcmd__login_commands] )) ||
_remuda__subcmd__login_commands() {
    local commands; commands=()
    _describe -t commands 'remuda login commands' commands "$@"
}
(( $+functions[_remuda__subcmd__open_commands] )) ||
_remuda__subcmd__open_commands() {
    local commands; commands=()
    _describe -t commands 'remuda open commands' commands "$@"
}
(( $+functions[_remuda__subcmd__pin_commands] )) ||
_remuda__subcmd__pin_commands() {
    local commands; commands=()
    _describe -t commands 'remuda pin commands' commands "$@"
}
(( $+functions[_remuda__subcmd__refresh_commands] )) ||
_remuda__subcmd__refresh_commands() {
    local commands; commands=()
    _describe -t commands 'remuda refresh commands' commands "$@"
}
(( $+functions[_remuda__subcmd__remove_commands] )) ||
_remuda__subcmd__remove_commands() {
    local commands; commands=()
    _describe -t commands 'remuda remove commands' commands "$@"
}
(( $+functions[_remuda__subcmd__rename_commands] )) ||
_remuda__subcmd__rename_commands() {
    local commands; commands=()
    _describe -t commands 'remuda rename commands' commands "$@"
}
(( $+functions[_remuda__subcmd__restore_commands] )) ||
_remuda__subcmd__restore_commands() {
    local commands; commands=()
    _describe -t commands 'remuda restore commands' commands "$@"
}
(( $+functions[_remuda__subcmd__run_commands] )) ||
_remuda__subcmd__run_commands() {
    local commands; commands=()
    _describe -t commands 'remuda run commands' commands "$@"
}
(( $+functions[_remuda__subcmd__serve_commands] )) ||
_remuda__subcmd__serve_commands() {
    local commands; commands=()
    _describe -t commands 'remuda serve commands' commands "$@"
}
(( $+functions[_remuda__subcmd__shell-init_commands] )) ||
_remuda__subcmd__shell-init_commands() {
    local commands; commands=()
    _describe -t commands 'remuda shell-init commands' commands "$@"
}
(( $+functions[_remuda__subcmd__signout_commands] )) ||
_remuda__subcmd__signout_commands() {
    local commands; commands=()
    _describe -t commands 'remuda signout commands' commands "$@"
}
(( $+functions[_remuda__subcmd__sync-units_commands] )) ||
_remuda__subcmd__sync-units_commands() {
    local commands; commands=()
    _describe -t commands 'remuda sync-units commands' commands "$@"
}
(( $+functions[_remuda__subcmd__use_commands] )) ||
_remuda__subcmd__use_commands() {
    local commands; commands=()
    _describe -t commands 'remuda use commands' commands "$@"
}

if [ "$funcstack[1]" = "_remuda" ]; then
    _remuda "$@"
else
    compdef _remuda remuda
fi
