Diff
1diff --git a/plugins/pipenv/README.md b/plugins/pipenv/README.md
2index 429b6f186b38b65bcea477c5c27e37ad69617ec4..544d079977286f3414cfa2cea454a3605d210885 100644
3--- a/plugins/pipenv/README.md
4+++ b/plugins/pipenv/README.md
5@@ -10,7 +10,7 @@ plugins=(... pipenv ...)
6
7 ## Features
8
9-- Adds completion for pipenv
10+- Adds completion for pipenv ([install the `argcomplete` package to get it working with pipenv >= 2026.5.0](https://pipenv.pypa.io/en/latest/shell.html#shell-completion))
11 - Auto activates and deactivates pipenv shell
12 - Adds short aliases for common pipenv commands
13 - `pch` is aliased to `pipenv check`
14@@ -29,6 +29,18 @@ plugins=(... pipenv ...)
15 - `pvenv` is aliased to `pipenv --venv`
16 - `ppy` is aliased to `pipenv --py`
17
18+## Cache
19+
20+This plugin caches the Pipenv version to avoid running `pipenv --version` on every shell startup. The cache is automatically refreshed asynchronously when the plugin is loaded, which is usually when you start a new terminal session.
21+
22+For legacy Pipenv versions, the generated completion script is also cached.
23+
24+The cache is stored at:
25+
26+- `$ZSH_CACHE_DIR/pipenv_version` version of Pipenv, used to choose between argcomplete-based completion and legacy Click-based completion.
27+
28+- `$ZSH_CACHE_DIR/completions/_pipenv` legacy Click-based completion script.
29+
30 ## Configuration
31
32 ### Shell activation
33diff --git a/plugins/pipenv/pipenv.plugin.zsh b/plugins/pipenv/pipenv.plugin.zsh
34index 76d66b301db0557b40636c215feda1338168e31c..802641a0e62aad1677570e9ee64bba567414369b 100644
35--- a/plugins/pipenv/pipenv.plugin.zsh
36+++ b/plugins/pipenv/pipenv.plugin.zsh
37@@ -2,15 +2,49 @@ if (( ! $+commands[pipenv] )); then
38 return
39 fi
40
41-# If the completion file doesn't exist yet, we need to autoload it and
42-# bind it to `pipenv`. Otherwise, compinit will have already done that.
43-if [[ ! -f "$ZSH_CACHE_DIR/completions/_pipenv" ]]; then
44- typeset -g -A _comps
45- autoload -Uz _pipenv
46- _comps[pipenv]=_pipenv
47+# Compatibility note:
48+# pipenv < 2026.5.0 used Click-based shell completion driven by the
49+# _PIPENV_COMPLETE environment variable.
50+#
51+# pipenv >= 2026.5.0 removed this mechanism and switched to argcomplete-based
52+# completion using register-python-argcomplete instead.
53+
54+autoload -Uz is-at-least
55+
56+_pipenv_version_cache="$ZSH_CACHE_DIR/pipenv_version"
57+
58+if [[ -f "$_pipenv_version_cache" ]]; then
59+ _pipenv_version="$(< "$_pipenv_version_cache" 2>/dev/null)"
60+else
61+ _pipenv_version="${$(pipenv --version 2>/dev/null)#pipenv, version }"
62 fi
63
64-_PIPENV_COMPLETE=zsh_source pipenv >| "$ZSH_CACHE_DIR/completions/_pipenv" &|
65+{
66+ _pipenv_fresh_version="${$(pipenv --version 2>/dev/null)#pipenv, version }"
67+ [[ -n "$_pipenv_fresh_version" ]] && print -r -- "$_pipenv_fresh_version" >| "$_pipenv_version_cache"
68+} &|
69+
70+if is-at-least 2026.5.0 "$_pipenv_version"; then
71+ # pipenv >= 2026.5.0: argcomplete-based completion (no legacy fallback)
72+ if (( $+commands[register-python-argcomplete] )); then
73+ autoload -Uz bashcompinit
74+ bashcompinit
75+
76+ eval "$(register-python-argcomplete pipenv)"
77+ fi
78+else
79+ # legacy Click-based completion via _PIPENV_COMPLETE
80+
81+ # If the completion file doesn't exist yet, we need to autoload it and
82+ # bind it to `pipenv`. Otherwise, compinit will have already done that.
83+ if [[ ! -f "$ZSH_CACHE_DIR/completions/_pipenv" ]]; then
84+ typeset -g -A _comps
85+ autoload -Uz _pipenv
86+ _comps[pipenv]=_pipenv
87+ fi
88+
89+ _PIPENV_COMPLETE=zsh_source pipenv >| "$ZSH_CACHE_DIR/completions/_pipenv" &|
90+fi
91
92 if zstyle -T ':omz:plugins:pipenv' auto-shell; then
93 # Automatic pipenv shell activation/deactivation
94@@ -34,6 +68,7 @@ if zstyle -T ':omz:plugins:pipenv' auto-shell; then
95 fi
96 fi
97 }
98+
99 autoload -U add-zsh-hook
100 add-zsh-hook chpwd _togglePipenvShell
101 _togglePipenvShell