Terminal login hangs

This is really hard to debug because I cannot reproduce it and often I can't open a new terminal to even try to find out what's going on.

Does anyone have any tips?

Update:

Using iTerm, I was able to get a shell by setting the start command to /bin/bash . In this shell, however, sudo does not work. It hangs (without showing the prompt) and ctrl-C and ctrl-D do no work when it hangs.

Using some other programs also does not work in this shell: node or /usr/local/bin/node both hang. As far as I can tell, it's programs that are in /usr/local/bin .

Update 2:

brew list --full-name results in these packages:

autoconf automake blueutil boost cabal-install cairo cfssl cmake coreutils doxygen editorconfig erlang ffind ffmpeg flow fontconfig fontforge freetype gdbm gettext ghc git glib go gobject-introspection graphicsmagick harfbuzz haskell-stack highlight icu4c influxdb jemalloc jpeg keybase lame libevent libffi libpng libtermkey libtiff libtool libuv libvterm libxml2 lua mongodb msgpack nginx node openssl [email protected] pango pcre pixman pkg-config postgresql protobuf python python3 rabbitmq readline reattach-to-user-namespace redis sqlite the_silver_searcher thefuck tmux unibilium unixodbc wxmac x264 xvid xz yarn z zsh josegonzalez/php/php54 neovim/neovim/neovim 

Update 3:

These points are in correspondence with @Monomeeth's answer:

  1. When it happens, a login item does show up in activity monitor. (Force) Quitting it also closes the Terminal window that was hanging. Closing the window manually does not make the login process go away in the Activity Monitor.
  2. The terminal title is Terminal — login — term big — ttys001 — 89x18 — ⌘1 , where term big is the settings name.
  3. There's no sudo process showing up in the Activity Monitor. I can create a sudo process by opening iTerm.app (which uses bash) and running sudo echo ok there. It can not be Quit, but Force Quit works and kills it: bash-3.2$ sudo echo ok Killed: 9

Update 4:

When it happens, running login from a shell that's still available does work, while the login in newer shells seems to hang.

Update 5:

I recently got a new laptop (MacBook Pro 2017, no Touch Bar) and the problem persists.

I've switched shells as well: I'm now using fish with a pretty vanilla config. I think that rules out the shell as the culprit.

The OS has also been updated to 10.13.3 (17D47) High Sierra.

I've tried to install as little as possible on this machine:

brew list —-full-names coreutils 8.29 dnsmasq 2.78 faac 1.29.9.2 fdk-aac 0.1.5 ffmpeg 3.4.1 fish 2.7.1 freetype 2.9 gdbm 1.14.1_1 gettext 0.19.8.1 git 2.16.1 highlight 3.42 htop 2.0.2_2 icu4c 60.2 imagemagick 7.0.7-22 jemalloc 5.0.1 jpeg 9b lame 3.100 libav 12.2 libogg 1.3.3 libpng 1.6.34 libtermkey 0.20 libtiff 4.0.9_1 libtool 2.4.6_1 libuv 1.19.1 libvorbis 1.3.5_1 libvpx 1.7.0 libvterm 681 libyaml 0.1.7 lua 5.3.4_2 luajit 2.0.5 mongodb 3.6.2 msgpack 2.1.5 neovim 0.2.2 node 9.5.0 openssl 1.0.2n opus 1.2.1 parallel 20180122 pcre 8.41 pcre2 10.30 postgresql 10.2 python 2.7.14_3 python3 3.6.4_2 readline 7.0.3_1 ripgrep 0.7.1 ruby 2.5.0 sqlite 3.22.0 the_silver_searcher 2.1.0 thefuck 3.25_1 unibilium 1.2.1 x264 r2795 xvid 1.3.5 xz 5.2.3 youtube-dl 2018.02.08 

Not sure what this can be now. The only apps which I can think of are Divvy or Apptivate since they both seem outdated. This is the intersection of what was installed on the old vs the new machine:

coreutils ffmpeg freetype gdbm gettext git highlight icu4c jemalloc jpeg lame libpng libtermkey libtiff libtool libuv libvterm lua mongodb msgpack node openssl pcre postgresql python python3 readline sqlite the_silver_searcher thefuck unibilium x264 xvid xz 

Update 6:

screenshot

Also, here's a screenshot:

Update 7:

My env typically looks like this:

Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.k60Nf5UBfq/Render DISPLAY=/private/tmp/com.apple.launchd.6FMoWPSlJI/org.macosforge.xquartz:0 EDITOR=env VIRTUAL_ENV= nvim -u /Users/john-doe/.config/vim/vimrc -p GNUTERM=X11 HOME=/Users/romeo HOMEBREW_NO_EMOJI=1 HOMEBREW_PREFIX=/usr/local LANG=en_GB.UTF-8 LESS=-RI LESSHISTFILE=- LOGNAME=romeo LS_COLORS=di=00;31:ex=00;37:mi=00;41;30:tw=00;33 MANPATH=/usr/local/opt/coreutils/libexec/gnuman PAGER=less PATH=/Users/john-doe/.config/fisherman/re-search:/usr/local/opt/python/libexec/bin:/usr/local/opt/ruby/bin:/usr/local/opt/coreutils/libexec/gnubin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/MacGPG2/bin PWD=/Users/romeo SECURITYSESSIONID=186a8 SHELL=/usr/local/bin/fish SHLVL=1 SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.fQn5sHMuZP/Listeners TERM=xterm-256color TERM_PROGRAM=Apple_Terminal TERM_PROGRAM_VERSION=400 TERM_SESSION_ID=D2AF7A50-8B41-4793-9201-8304A02C9B29 TMPDIR=/var/folders/15/zcyyfw_x7638z7vfg5zd85z40000gn/T/ USER=romeo XDG_CACHE_HOME=/Users/john-doe/.cache XDG_CONFIG_HOME=/Users/john-doe/.config XPC_FLAGS=0x0 XPC_SERVICE_NAME=0