Skip to content

Instantly share code, notes, and snippets.

@Choumingzhao
Created July 1, 2025 07:24
Show Gist options
  • Select an option

  • Save Choumingzhao/7528df29ccb993c38b309bd31b4380d2 to your computer and use it in GitHub Desktop.

Select an option

Save Choumingzhao/7528df29ccb993c38b309bd31b4380d2 to your computer and use it in GitHub Desktop.
How to fix duplicate conda venv names in zsh prompt?

πŸ“› Title:

Avoid Conda (base) in Zsh but Keep It in Bash (Oh My Zsh + Conda Prompt Fix)


πŸ“„ Description:

How to prevent Conda from prepending (base) to your Zsh prompt while keeping it in Bash. This is useful when using a custom prompt like Oh My Zsh that already shows Conda/venv info, avoiding redundant display like (base) 🐍 base.


🐍 Problem:

When using Oh My Zsh + Conda, you may see duplicated environment names in your prompt, like:

(base) 🐍 base user@host ~/project

This happens because:

  • conda automatically prepends (base) to your shell prompt.
  • Your Zsh theme (e.g. agnoster) already includes the environment name via prompt_virtualenv().

βœ… Goal:

  • Disable Conda’s (base) prompt injection in Zsh
  • Keep it active in Bash
  • Allow your Oh My Zsh theme to manage the prompt cleanly

πŸ› οΈ Solution

Step 1: Add this to your ~/.zshrc:

# Prevent conda from modifying the prompt in zsh
export CONDA_CHANGEPS1=false

This disables Conda’s prompt injection only for Zsh. Bash will still show (base) as usual.


Step 2 (Optional): Customize your theme’s prompt_virtualenv()

If you're using a theme like agnoster, you can edit ~/.oh-my-zsh/themes/agnoster.zsh-theme and adjust the function that displays environment names:

prompt_virtualenv() {
  if [ -n "$CONDA_DEFAULT_ENV" ]; then
    prompt_segment magenta $CURRENT_FG "🐍 $CONDA_DEFAULT_ENV"
  elif [[ -n "$VIRTUAL_ENV" && -n "$VIRTUAL_ENV_DISABLE_PROMPT" ]]; then
    prompt_segment "$AGNOSTER_VENV_BG" "$AGNOSTER_VENV_FG" "(${VIRTUAL_ENV:t:gs/%/%%})"
  fi
}

This:

  • Prefers conda env if both VIRTUAL_ENV and CONDA_DEFAULT_ENV are set
  • Avoids (env) [🐍 env] duplication

πŸ” Troubleshooting

  • Still seeing (base)? Run:

    echo $PROMPT

    If you see (base) in the raw prompt string, it’s injected by Conda.

  • Want to re-enable globally? Run:

    conda config --set changeps1 True

πŸ“Œ Keywords (SEO):

zsh conda base prompt, oh-my-zsh conda duplicate prompt, disable conda base zsh, conda PS1, prompt_virtualenv, CONDA_CHANGEPS1, ohmyzsh conda, zsh bash conda environment, zsh remove (base), conda venv zsh prompt



Note:

Above content is generated by ChatGPT after LLM and I fix this problem together.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment