Welcome! Type "help" for available commands.
$
Loading terminal interface...
Back to Blog

How to automatically use Warp Terminal's Subshells with "Warpify"

December 31, 2024
William Callahan

Software engineer and founder with a background in finance and tech. Currently building aVenture.vc, a platform for researching private companies. Based in San Francisco.

How to automatically use Warp Terminal's Subshells with "Warpify"

Warp Terminal has a useful feature called subshells - isolated terminal environments for different contexts. This post shows how to automate subshells using a custom configuration I call "Warpify".

What are Warp Subshells?

Warp subshells provide isolated environments where you can run commands without affecting your main terminal session. They work well for ssh'ing to a server, or looking inside a docker container (e.g., docker exec), each with their own environment variables and working directories.

How to auto Warpify Subshells

Add the snippet at the end of the appropriate RC file in the target environment, after other shell setup. For SSH or containers, place it on the host you're connecting to; for local nested shells, keep it in your local RC file so those inner shells are warpified automatically.

Important: Configure this on the host you're connecting to

To Warpify SSH or container sessions, add the snippet in the target environment — the machine you're connecting to (for example: a Docker container, a remote SSH server, or a VM). Place it in that user's shell startup file (~/.bashrc or ~/.bash_profile for bash, ~/.zshrc for zsh).

  • SSH: edit the remote user's RC file on the server you SSH into.

  • Docker: edit the container image or the running container's RC file.

  • Local nested shells: add it to your local RC if you want local subshells warpified.

Bash reads ~/.bashrc for interactive non-login shells; login shells read a login profile such as ~/.bash_profile or ~/.profile. If your login profile already sources ~/.bashrc, keep the hook there rather than duplicating it.

Local nested shells: examples

“Local nested shells” are interactive shells that you launch inside the current Warp session on the same machine (not SSH, not a container). If you want these inner shells to be warpified without a prompt, add the snippet to your local RC file.

  • Switching shells locally
    • From zsh → bash: bash, bash -l
    • From bash → zsh: zsh, zsh -l
  • Elevating or switching users locally
    • sudo -s, sudo -i
    • su - otheruser, su -l otheruser
  • Dev tools that spawn subshells
    • poetry shell, pipenv shell
    • nix-shell, nix develop
  • Multiplexers that launch a fresh shell in new panes or windows
    • tmux new -s work, screen

What do not count as local nested shells (configure the environment you jump into instead):

  • docker exec -it <container> /bin/bash → put the snippet in the container user's RC file.
  • ssh user@host (even ssh localhost) → put the snippet on the target machine.

For local nested shells, this guard keeps the hook scoped to Warp and to interactive shells only. Use the remote variant below for SSH or containers:

bash
# zsh (~/.zshrc)
if [[ $- == *i* && $TERM_PROGRAM == "WarpTerminal" ]]; then
  printf '\eP$f{"hook":"SourcedRcFileForWarp","value":{"shell":"zsh"}}\x9c'
fi
bash
# bash (~/.bashrc or ~/.bash_profile)
if [[ $- == *i* && $TERM_PROGRAM == "WarpTerminal" ]]; then
  printf '\eP$f{"hook":"SourcedRcFileForWarp","value":{"shell":"bash"}}\x9c'
fi

Quick add (local-only, guarded) helpers:

bash
# zsh (local ~/.zshrc)
cat <<'EOF' >> ~/.zshrc

# Auto-Warpify (Warp) — only in Warp and interactive zsh
if [[ $- == *i* && $TERM_PROGRAM == "WarpTerminal" ]]; then
  printf '\eP$f{"hook":"SourcedRcFileForWarp","value":{"shell":"zsh"}}\x9c'
fi
EOF
bash
# bash (local ~/.bashrc)
cat <<'EOF' >> ~/.bashrc

# Auto-Warpify (Warp) — only in Warp and interactive bash
if [[ $- == *i* && $TERM_PROGRAM == "WarpTerminal" ]]; then
  printf '\eP$f{"hook":"SourcedRcFileForWarp","value":{"shell":"bash"}}\x9c'
fi
EOF

For Linux hosts you're connecting to (remote server or container), use an interactive-only guard rather than the local TERM_PROGRAM check: SSH does not normally forward TERM_PROGRAM. Put this at the end of the remote user's ~/.bashrc (or the login profile as described above):

bash
# Warpify interactive bash subshells in the remote environment
if [[ $- == *i* ]]; then
  printf '\eP$f{"hook": "SourcedRcFileForWarp", "value": { "shell": "bash" }}\x9c'
fi

See the official docs for further details: Warpify Subshells.