# Show available completion shells in command help

- Task: `task_004_core_help_formatt`
- Status: rejected
- Module: src/click/core.py
- Behaviour axis: help_formatting_behaviour
- Interaction partner: src/click/shell_completion.py
- Files changed: src/click/core.py, src/click/shell_completion.py
- Repairs: 2

**Stopped at G5 Every requirement tested:** G5 failed after 2 repairs: uncovered=['AC2']

## Gates

| Gate | Result |
| --- | --- |
| Patch precheck | passed |
| Shape precheck | passed |
| Test hygiene precheck | passed |
| Interface precheck | passed |
| G1 Applies cleanly | passed |
| Base fail ratio | passed |
| G5 Every requirement tested | failed |
| G2 Fail-to-pass | not run |
| G3 No regressions | not run |
| G4 Same result every time | not run |
| G6 Mutation testing | not run |
| Harbor official checks | not run |
| N1 Not already in Click | not run |
| G7 Blind solve | not run |

## requirements.md

Rejected tasks are never packaged, so there is no instruction.md.

# Show available completion shells in command help

## Problem Description

Root command help should show which supported shell-completion backends are currently registered. Help rendering must consult the shell-completion registry each time, so registry changes are visible on the next rendering.

## Acceptance Criteria

- **AC1**: When the base `Command.format_help` implementation renders help for a root context, it appends an `Available shell completions` section after its existing help content. This applies to both commands and groups that use the base implementation.
- **AC2**: Each rendering queries the registry for `bash`, `zsh`, and `fish`. The section lists only registered names, in that order, regardless of registration order. Other registry names are not displayed.
- **AC3**: If none of those three names is registered, the section is omitted and the existing help output is unchanged.
- **AC4**: A context is root when its `parent` is `None`. Help rendered with a context that has a parent remains unchanged, even if that command can also be invoked independently as a root command.
- **AC5**: Registry changes, including registrations, replacements, and removals, are reflected on the next help rendering. Availability is not cached between renderings.
- **AC6**: Direct `format_help` calls and `get_help` calls both produce the section under the same conditions, without duplication. The normal `--help` output reflects the same content.
- **AC7**: Existing help content, ordering, formatter behavior, and subclass hooks remain unchanged apart from the specified section. A subclass that replaces `format_help` without calling the base implementation is not required to produce the section.

## Interface

### Symbols

- `click.core.Command.format_help`
- `click.core.Command.get_help`
- `click.shell_completion.get_completion_class`
- `click.shell_completion.add_completion_class`

### Contract Details

- `Command.format_help(self, ctx: Context, formatter: HelpFormatter) -> None`
  - No parameter has a default. It writes help to `formatter` and returns `None`.
  - For a root context, it queries `get_completion_class` once for each of `bash`, `zsh`, and `fish`, and appends the section when at least one query returns a class.
  - With the default formatter and all three shells registered, the appended section is preceded by a blank line and has the exact text `Available shell completions:\n  bash\n  zsh\n  fish\n`. For a subset, omit the corresponding lines; keep the remaining order.
  - The section uses the formatter's existing indentation and section conventions when those differ from the defaults.

- `Command.get_help(self, ctx: Context) -> str`
  - `ctx` has no default. It returns the formatted help with trailing newline characters removed, as before.
  - For default formatting with all three shells registered, the returned string ends with `\n\nAvailable shell completions:\n  bash\n  zsh\n  fish`.

- `get_completion_class(shell: str) -> type[ShellComplete] | None`
  - `shell` has no default. This existing registry API returns the registered completion class for the name, or `None` if unavailable.

- `add_completion_class(cls: type[ShellComplete], name: str | None = None) -> None`
  - This existing registry API registers a completion class under `name`, or under the class's name when `name` is `None`. Its existing behavior is unchanged.

No new error messages or exception types are introduced. Existing errors from the affected APIs retain their current behavior.

## Compatibility & Out of Scope

- Do not add a new help option or change completion generation, shell detection, or registration semantics.
- Only `bash`, `zsh`, and `fish` are listed, even if other completion classes are registered.
- Preserve startup import behavior: importing `click.core` must not eagerly import the shell-completion module or introduce eager top-level standard-library imports that violate existing startup constraints.
- The entire existing repository test suite must continue to pass with zero regressions.

## Reference patch

````diff
diff --git a/src/click/core.py b/src/click/core.py
index e4b6b57..412c327 100644
--- a/src/click/core.py
+++ b/src/click/core.py
@@ -1275,6 +1275,16 @@ class Command:
         self.format_options(ctx, formatter)
         self.format_epilog(ctx, formatter)
 
+        if ctx.parent is None:
+            from .shell_completion import _available_help_shells
+
+            shells = _available_help_shells()
+
+            if shells:
+                with formatter.section("Available shell completions"):
+                    for shell in shells:
+                        formatter.write_text(shell)
+
     def format_help_text(self, ctx: Context, formatter: HelpFormatter) -> None:
         """Writes the help text to the formatter if it exists."""
         if self.help is not None:
diff --git a/src/click/shell_completion.py b/src/click/shell_completion.py
index 9cf2314..6f3d2f4 100644
--- a/src/click/shell_completion.py
+++ b/src/click/shell_completion.py
@@ -584,6 +584,15 @@ def get_completion_class(shell: t.Literal["fish"]) -> type[FishComplete]: ...
 @t.overload
 def get_completion_class(shell: t.Literal["zsh"]) -> type[ZshComplete]: ...
 @t.overload
+def _available_help_shells() -> list[str]:
+    """Return the registered shells displayed in command help."""
+    return [
+        shell
+        for shell in ("bash", "zsh", "fish")
+        if get_completion_class(shell) is not None
+    ]
+
+
 def get_completion_class(shell: str) -> type[ShellComplete] | None: ...
 def get_completion_class(shell: str) -> type[ShellComplete] | None:
     """Look up a registered :class:`ShellComplete` subclass by the name
````
