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
Arguments
The directory to specify.If omitted, will use the current directory of the process itself (equivalent to
$PWD or $(pwd)).Example: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
How to manage passing the escape sequence through to tmux.Possible values:
disable- Don’t use tmux passthroughenable- Always use tmux passthroughdetect- Automatically detect if running in tmux (default)
Examples
Set to current directory
$PWD).
Set to specific directory
Set with custom hostname
file://production-server/var/www
Use in shell prompt
Add to your.bashrc or .zshrc:
Use in fish shell
Add to yourconfig.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:- Converts the provided path to an absolute path
- URL-encodes special characters
- Constructs the proper
file://URL - 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:SSH sessions
When working on a remote server via SSH:/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:Directory not updating in new tabs
- Check that your shell is calling
set-working-directory - Verify the escape sequence is being emitted:
- Check your WezTerm configuration
Spaces in directory names
The command handles spaces automatically:Manual OSC 7 Emission
If you prefer not to use thewezterm command, you can emit OSC 7 directly:
wezterm set-working-directory is recommended as it handles:
- URL encoding
- Hostname detection
- Tmux passthrough
- Path normalization
Related
- wezterm start - Start terminal with specific directory
- wezterm imgcat - Display images in terminal
- WezTerm Shell Integration Documentation