I recently switched to zsh (with oh-my-zsh) as my primary shell, but running the shell from emacs results in some strange (for lack of a better word) "residural" characters; however changing to bash removes these characters:

➜  ~  ^[[?2004h bash

Is there any way for me to keep using zsh in emacs without it looking like absolute garbage?


2 Answers 2


The control sequences ^[[?2004h and ^[[?2004l turn bracketed paste mode on and off.

Shell mode doesn't support bracketed paste mode (with these or any other control sequences), so zsh shouldn't try to turn it on. Shell mode correctly advertises that it doesn't support these control sequences by declaring TERM=dumb. It seems that zsh blindly assumes that the terminal either supports or ignores these two control sequences. That's a bug in zsh, which I can reproduce with zsh from git.

As a workaround, disable bracketed paste mode in your .zshrc if the terminal doesn't support escape sequences.

if [[ $TERM = dumb ]]; then
  unset zle_bracketed_paste
  • 1
    Elegant and simple solution that did the trick, thanks! Commented Jan 26, 2016 at 23:37
  • This really helps me, thank you.
    – Hao
    Commented Sep 9, 2020 at 7:53
  • I am having ^[[31m^[[1m^[[31mdoo^[[0m^[[0m^[[0m as red color output of the string, could it be also solved by unset zle_bracketed_paste ?
    – alper
    Commented Nov 9, 2020 at 21:02

This looks like bad color encodings. Try using ansi-color like so http://wikemacs.org/wiki/Shell#More_colors or with M-x ansi-color-for-comint-mode-on.

ps: yes it's possible, I use zsh !


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.