---
title: "Ship shell completion generated from the · Agent Wranglers"
url: https://agentwranglers.se/playbook/developer-tools/help-completion-and-updates/shell-completion
id: DEV-16
level: Recommended
updated: 2026-10-27
build: a2a6bdfed830
tokens: 936
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Ship shell completion generated from the command definitions

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Help, completion and updates](https://agentwranglers.se/playbook/developer-tools/help-completion-and-updates.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers.md). Updated 2026-10-27.

- ID: DEV-16
- Level: Recommended
- Chapter: [Help, completion and updates](https://agentwranglers.se/playbook/developer-tools/help-completion-and-updates.md)
- Rule: Offer completion scripts for bash, zsh, fish and PowerShell through a command such as `example completion zsh`. Generate them from the same definitions that parse the flags.
- Check: A test lists every command and flag from the parser and finds each one in the generated bash and zsh scripts. `bash -n` and `zsh -n` parse the scripts without error. `example completion fish` and `example completion powershell` exit 0 with a non-empty script.
- How: A completion script written by hand falls behind the flags within a few releases. Argument libraries generate them from the command tree, such as cobra in Go and clap_complete in Rust. click in Python covers bash, zsh and fish. Print the script to standard output, so the user or a package manager installs it with one redirect. Complete dynamic values, such as project or service names, by calling the tool itself, with a time limit of 1 second. Each command's flags come from the same place as its help text in [Give every command help with an example and a version flag](https://agentwranglers.se/playbook/developer-tools/help-completion-and-updates/cli-help.md).

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### Go example

```go
rootCmd := &cobra.Command{Use: "example"}
deployCmd := &cobra.Command{
	Use: "deploy [service]",
	ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
		return listServices(cmd.Context()), cobra.ShellCompDirectiveNoFileComp
	},
}
rootCmd.AddCommand(deployCmd)
// cobra adds "example completion bash|zsh|fish|powershell" to the root command.
```

### Python example

```python
import os, subprocess, sys
import click

@click.group()
def cli():
    pass

@cli.command()
@click.argument("shell", type=click.Choice(["bash", "zsh", "fish"]))
def completion(shell):
    env = {**os.environ, "_EXAMPLE_COMPLETE": f"{shell}_source"}
    subprocess.run([sys.argv[0]], env=env, check=True)
```

## Related rules

- DEV-8 [Give every command help with an example and a version flag](https://agentwranglers.se/playbook/developer-tools/help-completion-and-updates/cli-help.md) in Developer tools, SDKs and CLIs

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/developer-tools/help-completion-and-updates/shell-completion">Agent Wranglers developer tools, SDKs and CLIs playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Give every command help with an example and a version flag](https://agentwranglers.se/playbook/developer-tools/help-completion-and-updates/cli-help.md)
- Next: [Check for new versions at most once a day and never in scripts](https://agentwranglers.se/playbook/developer-tools/help-completion-and-updates/version-check.md)
- [Help, completion and updates](https://agentwranglers.se/playbook/developer-tools/help-completion-and-updates.md)
