ZSH: Hide computer name in terminal

How would I hide the computer name in the prompt while using the terminal?

At the moment it shows both username and computer name like so:

iTerm screenshot of user prompt

It would save some space by removing anwarchoukah@anwars-mbp, seeing as I actually know who I am:)


try to add export DEFAULT_USER="$(whoami)" to your .zshrc file


  1. step 1. one your .zshrc file by vim .zshrc

  2. step 2. go to end of your file.

  3. Paste this code:

careful indent again your code

prompt_context() {
  if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
    prompt_segment black default "%(!.%{%F{yellow}%}.)$USER"
  fi
}

EDIT - explaining what this does

This will remove the machine@user name from the prompt IF: - you are not logged in as the default user - you are not in an ssh client shell

For most people, not needed, but if you regularly ssh to other machines and have multiple terminals open (eg remote sys admin type work) then this is extremely useful so when you look at your terminal you know which machine and user you are logged in as inside that terminal.

If you don't need/manage that type of complexity then use one of the other answers to just modify your export PROMPT/PS1 value.

* WARNING *

If you are using a custom shell or theme, this might not work and although the prompt will no longer show your computer and username it will keep throwing the error:

prompt_context:2: command not found: prompt_segment

For example, you can see with this (very popular) powerlevel9k it does not work. This is because the Powerlevel9k theme uses it's own magic and you simply add commands to your ~/.zshrc file to get the same result, eg:

POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context)

More info on that here.


On MacOS 10.15 Catalina:

  1. Open the file /private/etc/zshrc in a text editor
  2. Locate the comment: # Default prompt
  3. Modify the line that looks like this: PS1="%n@%m~ %& # "
  4. Save the file. You will be prompted to enter a password to save it.
  5. Load a new Terminal window.

For example, you can:

  • Remove "%n@%m" to get rid of both the username and computer name
  • Remove "%n" to get rid of the user name
  • Remove "%m" to get rid of the machine name

Open up .zshrc, find the line reading export PS1 or maybe export PROMPT.

Remove the variable that is used for the hostname, could be %m or %M.

Zsh on Archlinux wiki

You can use colors and also have a prompt (or some information) on the right side.