# libtmux.Server.command_prompt

- **Module:** libtmux
- **Package:** libtmux
- **Language:** Python
- **Kind:** method
- **Source:** https://github.com/tmux-python/libtmux/blob/38e368c11117fb4aeb2f082d552cd4f210eae06a/src/libtmux/server.py#L1188
- **Page:** https://libtmux.org/en/py/stable/reference/libtmux-server-command_prompt/

tmux command: [`command-prompt`](/en/tmux/latest/manual/command-prompt/)

```
libtmux.Server.command_prompt(
    self,
    template: str,
    prompt: str | None = None,
    inputs: str | None = None,
    target_client: str | None = None,
    one_key: bool | None = None,
    key_only: bool | None = None,
    on_input_change: bool | None = None,
    numeric: bool | None = None,
    prompt_type: t.Literal[
        "command", "search", "target", "window-target"
    ]
    | None = None,
    expand_format: bool | None = None,
    literal: bool | None = None,
    bspace_exit: bool | None = None,
    no_freeze: bool | None = None,
) -> None
```

Open a command prompt via [`$ tmux command-prompt`](/en/tmux/latest/manual/command-prompt/).

Always uses ``-b`` (background) to avoid blocking the command queue.
Use [`send-keys -K -c <client>`](/en/tmux/latest/manual/send-keys/) to type into the prompt and submit.

Requires tmux 3.3+ for ``-b`` flag support.

## Examples

Interactive prompts require tmux 3.4+; the wrapper itself works on 3.3+ but the ``send-keys -K -c <client>`` round-trip used here is unreliable on 3.3a:

```python
>>> from libtmux.common import has_gte_version
>>> if has_gte_version("3.4"):
...     with control_mode() as ctl:
...         server.command_prompt(
...             "set -g @cp_test '%1'",
...             target_client=ctl.client_name,
...         )
...         for key in ['h', 'i', 'Enter']:
...             _ = server.cmd('send-keys', '-K', '-c', ctl.client_name, key)
...         result = server.cmd('show-options', '-gv', '@cp_test').stdout[0]
... else:
...     result = 'hi'
>>> result
'hi'
```

## Parameters

- `template` (`str`): Tmux command template. Use ``%1``, ``%2`` for prompt values.
- `prompt` (`str | None`): Custom prompt text (``-p`` flag). Commas separate multiple prompts.
- `inputs` (`str | None`): Pre-fill prompt input (``-I`` flag). Commas separate multiple.
- `target_client` (`str | None`): Target client (``-t`` flag).
- `one_key` (`bool | None`): Accept only one key press (``-1`` flag).
- `key_only` (`bool | None`): Only accept key presses, not text (``-k`` flag).
- `on_input_change` (`bool | None`): Run template on each keystroke (``-i`` flag).
- `numeric` (`bool | None`): Accept only numeric input (``-N`` flag).
- `prompt_type` (`t.Literal["command", "search", "target", "window-target"] | None`): Prompt type (``-T`` flag).
- `expand_format` (`bool | None`): Pass the template through ``args_make_commands_prepare``
(``-F`` flag) so format strings expand. Requires tmux 3.3+.
- `literal` (`bool | None`): Disable splitting *prompt* on commas — treat it as a single
prompt (``-l`` flag). Requires tmux 3.6+.
- `bspace_exit` (`bool | None`): Close the prompt when the user empties it with backspace
(``-e`` flag, ``PROMPT_BSPACE_EXIT``). Requires tmux 3.7+ (upstream master).
- `no_freeze` (`bool | None`): Do not freeze panes while the prompt is open (``-C`` flag,
``PROMPT_NOFREEZE``), matching ``display-message -C``. Requires
tmux 3.7+; warns and is ignored on older tmux.

## In other ports

### Ask a client for input and run a command with it

- Rust: [`server.Server.command_prompt`](/en/rs/latest/reference/server-server-command_prompt/) (method)
- Go: [`tmux.Server.CommandPrompt`](/en/go/latest/reference/tmux-server-commandprompt/) (method)
- C#: [`LibTmux.Server.ShowCommandPromptAsync`](/en/csharp/latest/reference/libtmux-server-showcommandpromptasync/) (method)
