{"id":9586,"library":"click-completion","title":"Click Completion","description":"click-completion is a Click extension that provides shell completion for Fish, Bash, Zsh, and PowerShell. It helps users get tab-completion for their Click-based command-line interfaces. The current version is 0.5.2, and as a `click-contrib` library, it typically maintains an active but often lower-cadence release cycle, with updates often aligning with Click's own evolution.","status":"active","version":"0.5.2","language":"en","source_language":"en","source_url":"https://github.com/click-contrib/click-completion","tags":["click","cli","completion","shell","bash","zsh","fish","powershell"],"install":[{"cmd":"pip install click-completion","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Core dependency for building command-line interfaces that click-completion enhances.","package":"click","optional":false}],"imports":[{"note":"`init` is exported directly to the top-level `click_completion` module for convenience.","wrong":"from click_completion.core import init","symbol":"init","correct":"from click_completion import init"},{"symbol":"BashCompletion","correct":"from click_completion.core import BashCompletion"}],"quickstart":{"code":"import click\nimport click_completion\n\n# Initialize click-completion. This must be called BEFORE defining your commands\n# if you want options like --show-completion to be available.\nclick_completion.init()\n\n@click.group()\ndef cli():\n    \"\"\"A simple CLI demonstrating completion.\"\"\"\n    pass\n\n@cli.command()\n@click.option('--name', default='World', help='The name to greet.')\ndef hello(name):\n    \"\"\"Greets the given name.\"\"\"\n    click.echo(f\"Hello, {name}!\")\n\n@cli.command()\ndef goodbye():\n    \"\"\"Says goodbye.\"\"\"\n    click.echo(\"Goodbye!\")\n\nif __name__ == '__main__':\n    cli()","lang":"python","description":"This quickstart demonstrates a minimal Click application integrated with `click-completion`. It defines a root group `cli` with two commands, `hello` and `goodbye`. Calling `click_completion.init()` at the start enables the completion functionality for the CLI. To activate completion, you would typically run `python your_app.py --show-completion <shell_type>` and source the output in your shell configuration."},"warnings":[{"fix":"Remove any calls to `click_completion.extra.install()` or similar legacy installation methods. Update your shell's configuration (`.bashrc`, `.zshrc`, etc.) to explicitly source the completion script generated by `your_cli_app --show-completion <shell_type>`.","message":"Starting with version 0.5.0, `click-completion` no longer attempts to automatically install completion scripts. Users must manually generate and source the completion script for their shell.","severity":"breaking","affected_versions":">=0.5.0"},{"fix":"These functions have no direct replacement. The intended way to use completion is to call `click_completion.init()` in your app and then have users manually generate and source the completion script using the `--show-completion` argument provided by `click-completion`.","message":"The `click_completion.extra` module and its functions, such as `install()` and `shell_paths()`, were removed in version 0.5.0.","severity":"deprecated","affected_versions":">=0.5.0"},{"fix":"Ensure `click_completion.init()` is called early in your Click app's lifecycle. Instruct users to add `source <(your_cli_app --show-completion bash)` (or similar for their shell) to their shell configuration file (e.g., `~/.bashrc`).","message":"For completion to work correctly, `click_completion.init()` must be called within your Click application, and the generated completion script must be sourced in the user's shell environment.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Remove all calls to `click_completion.extra` functions. `click-completion` 0.5.0 and later requires manual generation and sourcing of completion scripts.","cause":"Attempting to use `click_completion.extra.install()` or other functions from the `extra` module, which were removed in version 0.5.0.","error":"AttributeError: module 'click_completion.extra' has no attribute 'install'"},{"fix":"Review calls to `click_completion.core.startswith`. Ensure you are passing the `prefix` argument as required by the current version's API.","cause":"The signature of `click_completion.core.startswith` changed in version 0.5.0, adding a required `prefix` argument. Code written for older versions might be calling it incorrectly.","error":"TypeError: startswith() missing 1 required positional argument: 'prefix'"},{"fix":"1. Verify `click_completion.init()` is called in your Click application. 2. Ensure the user has added the correct sourcing command to their shell configuration file (e.g., `echo 'source <(my-cli-app --show-completion bash)' >> ~/.bashrc && source ~/.bashrc`).","cause":"This is a common issue often caused by one of two things: `click_completion.init()` was not called in the Python application, or the generated shell completion script has not been correctly sourced in the user's shell.","error":"Command 'my-cli-app' tab-completion is not working, or only completes basic commands, not options/arguments."}]}