Skip to main content
The set-working-directory command emits an OSC 7 escape sequence to advise the terminal of the current working directory.

Synopsis

Description

This command emits an OSC 7 (Operating System Command 7) escape sequence that informs the terminal emulator about the current working directory. This is useful for:
  • Enabling semantic terminal features based on directory context
  • Allowing new tabs/panes to open in the same directory
  • Integration with shell prompts and directory-aware tools
  • Working with remote sessions over SSH
Many shells can be configured to automatically emit this sequence, but this command provides manual control when needed.

Arguments

path
The directory to specify.If omitted, will use the current directory of the process itself (equivalent to $PWD or $(pwd)).Example:
string
The hostname to use in the constructed file:// URL.If omitted, the system hostname will be used. This is particularly useful when working on remote systems via SSH.Example:

Options

enum
How to manage passing the escape sequence through to tmux.Possible values:
  • disable - Don’t use tmux passthrough
  • enable - Always use tmux passthrough
  • detect - Automatically detect if running in tmux (default)
When running inside tmux, the OSC 7 sequence needs special handling to pass through tmux to the outer terminal.Example:

Examples

Set to current directory

This uses the current working directory ($PWD).

Set to specific directory

Set with custom hostname

This creates a URL like: file://production-server/var/www

Use in shell prompt

Add to your .bashrc or .zshrc:

Use in fish shell

Add to your config.fish:

Inside tmux

With directory change

Integration with Shells

Bash

Add to ~/.bashrc:

Zsh

Add to ~/.zshrc:

Fish

Add to ~/.config/fish/config.fish:

PowerShell

Add to your PowerShell profile:

OSC 7 Sequence Format

The OSC 7 sequence has the format:
For example:
WezTerm automatically:
  1. Converts the provided path to an absolute path
  2. URL-encodes special characters
  3. Constructs the proper file:// URL
  4. Emits the OSC 7 sequence

Use Cases

New tabs inherit directory

When you open a new tab in WezTerm, it can automatically use the current working directory of the active pane:
With OSC 7 properly set, new tabs will open in the actual current directory.

SSH sessions

When working on a remote server via SSH:
Now WezTerm knows you’re in /var/log on remote-server.

Directory-aware features

Some WezTerm features use the current directory:
  • File path completion
  • Quick file opening
  • Status bar showing current directory

Semantic zones

WezTerm can use directory information for semantic zones, allowing you to:
  • Navigate between command outputs
  • Select entire commands with their output
  • Copy commands without the output

Troubleshooting

OSC 7 not working in tmux

Make sure to use:
Or configure tmux to pass through escape sequences:

Directory not updating in new tabs

  1. Check that your shell is calling set-working-directory
  2. Verify the escape sequence is being emitted:
  3. Check your WezTerm configuration

Spaces in directory names

The command handles spaces automatically:

Manual OSC 7 Emission

If you prefer not to use the wezterm command, you can emit OSC 7 directly:
However, using wezterm set-working-directory is recommended as it handles:
  • URL encoding
  • Hostname detection
  • Tmux passthrough
  • Path normalization
  • wezterm start - Start terminal with specific directory
  • wezterm imgcat - Display images in terminal
  • WezTerm Shell Integration Documentation