Skip to main content
WezTerm supports advanced shell integration features that enable enhanced user experiences through special escape sequences. When properly configured, your shell can communicate additional context to WezTerm, enabling features like semantic navigation, smart working directory handling, and custom status information.

What is Shell Integration?

Shell integration uses OSC (Operating System Command) escape sequences to communicate between your shell and WezTerm. These sequences provide metadata about:
  • Current working directory
  • Command prompts vs output
  • User and hostname information
  • Custom shell state
Shell integration is automatically activated on Fedora, Debian, and Arch Linux packages for Bash and Zsh. On other systems, you’ll need to configure it manually.

Key Features

1

Working Directory Tracking

New tabs and panes automatically inherit the current working directory from the active pane.
2

Semantic Navigation

Jump through scrollback to the start of previous commands or select complete command output.
3

User Variables

Track custom shell state and trigger events based on shell activity.
4

Prompt Detection

Distinguish between prompts, input, and output for better copy/paste and navigation.

OSC 7: Working Directory

OSC 7 tells WezTerm the current working directory, enabling smart directory inheritance when spawning new tabs or panes.

How it Works

Your shell emits an escape sequence with the current directory as a URL:
When the working directory is set via OSC 7, spawning a new tab will use the current working directory of the active tab, saving you from manually changing directories.

Bash Configuration

Add to your ~/.bashrc:

Zsh Configuration

Add to your ~/.zshrc:

Windows cmd.exe

Configure in your .wezterm.lua:

PowerShell

Add to your PowerShell profile:

PowerShell with Starship

If using Starship:

OSC 133: Semantic Prompt Markup

OSC 133 marks distinct zones in your terminal output:
  • Prompt - Your shell prompt
  • Input - Commands you type
  • Output - Command results
This enables powerful navigation and selection features.

Benefits

Instantly select all output from a command:

Implementation

The complete OSC 133 specification uses these sequences:
  • OSC 133 ; A ST - Mark start of prompt
  • OSC 133 ; B ST - Mark start of input (command)
  • OSC 133 ; C ST - Mark start of output
  • OSC 133 ; D [; exit_code] ST - Mark end of output
Learn more about OSC 133 Semantic Prompts.

OSC 1337: User Variables

User variables are pane-specific variables (similar to environment variables but scoped to a pane rather than a process).

Built-in Variables

When using WezTerm’s shell integration, these variables are automatically maintained:
If using tmux, you must add set -g allow-passthrough on to your tmux.conf for user vars to work.

Setting Custom Variables

Use the __wezterm_set_user_var function provided by shell integration:

Using Variables in Configuration

User variables trigger events that you can handle in your configuration:

Accessing Variables

Read user variables from Lua:

Complete Shell Integration Setup

WezTerm provides shell integration scripts in the wezterm repository.

Installing for Bash/Zsh

1

Download the integration script

2

Source in your shell config

Add to ~/.bashrc or ~/.zshrc:
3

Restart your shell

System-wide Installation

On most Unix systems, you can install to /etc/profile.d/:

Xonsh Support

For Xonsh users, use the term-integrations plugin:

Advanced Examples

Dynamic Tab Titles with User Vars

Update tab titles based on the current command:

Git Branch in Status Bar

In your shell configuration:
In .wezterm.lua:

Command Duration Tracking

Clink brings bash-style line editing to Windows cmd.exe.

Configuration

Troubleshooting

Verify OSC 7 is being emitted:
Check that WEZTERM_PANE environment variable is set.
Ensure your tmux.conf includes:
Restart tmux after updating the configuration.
Verify the integration script is sourced:
If the function is not found, check that your shell config sources the integration file.

Best Practices

1

Use provided integration scripts

Start with WezTerm’s official shell integration scripts rather than writing your own.
2

Test incrementally

Add features one at a time (OSC 7, then OSC 133, then custom user vars) to isolate issues.
3

Check for conflicts

Some prompt frameworks (like Starship or Oh My Zsh) may conflict. Check their documentation for integration guides.
4

Update regularly

Shell integration improves over time. Periodically update your integration scripts.

Learn More