Skip to main content

Shell integration

With integration, every spawned bash, zsh, and fish - and PowerShell on Windows - reports three facts the terminal otherwise has to guess at: when a prompt is showing (and when a command is running), what a finished command's exit code was, and where the shell's working directory is. The rich input overlays then show at every prompt, including the exotic, themed, and multiline ones the grid-read cannot decide. Exit codes reach the command chip on every shell with no configuration, and the directory chip follows cd through the shell's own report.

Nothing is installed into your rc files: the scripts are DropTerm's own, embedded in the binary and materialized under ~/.cache/dropterm/shell-integration/ (rewritten only when their bytes change). The spawn hands them to the shell through argv and environment alone.

The wire​

The emitters speak two public sequences, the same ones third-party integrations use:

  • OSC 133 - the semantic prompt zones: A (the prompt is about to print), C (the command is running), D;<code> (the command finished, carrying its exit code). A is also when the rich input overlays read the prompt itself, so a prompt that changed while nothing ran - cd under a prompt that shows the directory - is picked up at its own prompt.
  • OSC 7 - the working directory as a file:// URL, re-reported at every prompt so cd moves the path seat.

A command's cycle on an integrated shell: Enter → C → the command runs → D;<code> → A before the next prompt prints. The session's first prompt reports A directly, so the boot prompt is integrated, never guessed at.

What integrates, and how​

The decision runs at spawn and consults the program the PTY execs - its basename, never a running-process guess:

ShellThe mechanism
bashSpawned with --rcfile pointing at the wrapper; the wrapper sources your ~/.bashrc whole, then chains the hooks around whatever it set (PROMPT_COMMAND runs yours behind the report; PS0 prints the C mark before the command runs).
zshSpawned with ZDOTDIR pointing at a bootstrap directory; the bootstrap's .zshenv/.zprofile/.zlogin/.zshrc each source your originals (from your real ZDOTDIR, defaulting $HOME), and .zshrc appends the hooks to your own precmd/preexec arrays.
fishSpawned with -C sourcing the emitter after fish's own config; the emitter installs fish's own fish_prompt/fish_preexec/fish_postexec event hooks.
PowerShell (Windows)Spawned with -NoLogo -NoExit -Command dot-sourcing the emitter from the seat under %LOCALAPPDATA%\dropterm\shell-integration\ - after your profiles ran, because -NoProfile is never passed. The add-on calls your own prompt function and your PSConsoleHostReadLine when you defined one, then prints the marks around them.

WSL (Windows)​

Every installed WSL distribution is a shell: the dropdown lists them as WSL: <name>, read once per open and once at startup. A machine without WSL lists none and says nothing. Picking one runs that distribution's default shell with the same add-on as its Linux twin - wsl.exe -d <name> --exec bash --rcfile …, or the zsh and fish shapes - reading the scripts from the Windows seat through the distribution's own /mnt mount. The tab's working folder rides the line's --cd: cd /tmp, open a new tab, and /tmp again, inside the same distribution. The PTY gets no Windows directory.

The integration's rules carry over: the kill switch skips the add-on (the folder still works, on the bare line); a distribution whose default shell is none of bash, zsh, or fish runs bare - the shell you installed, no marks.

A distribution whose name carries spaces lists no row: the configured value spells the distribution in words (wsl.exe -d <name>), and a spaced name cannot be told apart from extra words. If you name distributions without spaces, they list (known issues).

A profile tab (a ssh web preset, a htop one-shot-then-shell) integrates its interactive tail only: the wrap's exec <shell> line becomes the integrated spawn, so the preamble command runs bare - no marks, no timing, no verdicts.

What stays untouched​

  • Other shells and programs - sh (the default fallback), nu, dash, bash.exe (Git Bash's own file name matches no shell), cmd.exe, and any --cmd program spawn byte-identical. cmd and Git Bash start without the extras - PowerShell and WSL carry them. A --cmd line carries its own arguments and never inherits.
  • Your own file choices - a configured args carrying --rcfile, fish's init flag, PowerShell's -NoProfile, -Command, or -c (exact, or joined to its value with a colon), or a profile env's ZDOTDIR suppresses injection for that spawn (one warn in the log).
  • The fallback - no integration means the fallback: the grid-read decides the prompt (an unsure prompt hides the overlays); exit codes and cwd arrive only if your own shell config emits them. The fallback stands beside integration, never under it.
  • ssh remotes - the integration is local to the spawned shell; a remote shell over ssh runs whatever the remote has, degrades to the fallback cleanly, and the local prompt re-arms on exit.
  • Foreign integrations - a shell-integration script you already run (ble.sh, a terminal's own, a hand-rolled one) is consumed as-is: the parsed marks read optional truth, nothing keys on who sent them.

The kill switch​

shell_integration (default true, the Terminal page of the Settings) skips the whole path when false: no scripts materialized, no argv or environment change, byte-identical spawns. The key is read once per spawn - a flip governs the shells spawned after it; a running shell keeps the integration it was spawned with until it exits.

The emitters are written from the public OSC 133/7 specifications. The design survey and the rejected alternative (the 2026-10-02 no-injection ruling this feature reverses) are in the research log.

By your own rc files​

DropTerm's own integration emits the D mark and OSC 7 for the shells it wraps, nothing else. Your own rc files are the other channel: for a shell DropTerm does not wrap, for hooks you would rather own, and for the two reports DropTerm keeps but no core chip shows - OSC 9;4 and OSC 7501.

A command's exit code: the D mark​

The verdict has one source: the shell reporting OSC 133 ; D ; <code> - the "command finished" mark of the semantic prompt zones, the FinalTerm/contour shell-integration standard. DropTerm reads only this D mark and ignores the prompt/output boundary marks (A/B/C) other terminals build on, so any integration that emits D works as-is. The command chip shows the verdict: a failed exit wears the attention class, and the chip's click copies the code.

  • fish 4.0 and later need nothing: fish marks its prompts natively (A, C and D from 4.0.0). set -Ua fish_features no-mark-prompt (fish 4.0.6+) turns fish's own marks off - unset it and the chip returns.

  • zsh - two hooks in ~/.zshrc, contour's own integration reduced to the one mark DropTerm reads: $? is captured before anything can clobber it, and the report is sent only once a command has actually run (an unconditional report would verdict the shell's startup line):

    _dropterm_preexec() { _dropterm_ran=1 }
    _dropterm_precmd() {
    local exit_status=$? # first line: nothing may clobber the status
    if [[ -n ${_dropterm_ran:-} ]]; then
    print -n "\e]133;D;${exit_status}\e\\"
    unset _dropterm_ran
    fi
    }
    autoload -Uz add-zsh-hook
    add-zsh-hook preexec _dropterm_preexec
    add-zsh-hook precmd _dropterm_precmd
  • bash has no prompt hook of its own; bash-preexec supplies the same pair (at the end of ~/.bashrc):

    preexec() { _dropterm_ran=1; }
    precmd() {
    local exit_status=$?
    if [[ -n ${_dropterm_ran:-} ]]; then
    printf '\e]133;D;%s\e\\' "$exit_status"
    unset _dropterm_ran
    fi
    }

    contour's shipped integration scripts (they vendor bash-preexec and emit the full A/B/C/D set) work as-is if you already run them. Sequence reference: contour's OSC 133 shell-integration documentation; its shipped hooks are the source these snippets are reduced from.

The working directory: OSC 7​

OSC 7 ; file://host/path is the shell reporting its own working directory (WezTerm/iTerm2/VTE semantics; Fedora's bash and zsh already emit it by default through the sourced vte.sh). A standing report outranks the working directory DropTerm derives itself - what the directory chip otherwise reads - so an SSH tab whose remote shell reports shows the true remote path, rendered host:path and never ~-collapsed (no remote home is known). A report naming this machine renders bare and collapses like a local one, case-insensitively (the DNS rule).

The report stands until a newer one replaces it; a tab's respawn starts clean - the peer lifetime (WezTerm and kitty take the last report the same way). An integration that reports at every prompt self-corrects the moment it can.

One emitter rule: percent-encode at least % in the path (% → %25, as vte.sh does). A bare % makes the report malformed; DropTerm drops it whole rather than display a wrong path.

  • fish - one line inside the prompt function:

    function fish_prompt
    printf '\e]7;file://%s%s\e\\' (hostname) (string replace --all '%' '%25' -- $PWD)
    # ... the prompt itself
    end
  • zsh - a precmd hook in ~/.zshrc (composes with the D-mark hook above; both ride precmd):

    _dropterm_osc7() { print -n "\e]7;file://${HOST}${PWD//\%/%25}\e\\" }
    autoload -Uz add-zsh-hook
    add-zsh-hook precmd _dropterm_osc7
  • bash - add the same report to the precmd hook above, before the D-mark printf:

    printf '\e]7;file://%s%s\e\\' "$HOSTNAME" "${PWD//\%/%25}"

A command's progress: OSC 9;4​

OSC 9 ; 4 ; <state> [; <percent>] is the ConEmu-family progress report (Windows Terminal, kitty, and Ghostty 1.2+ read the same sequence; reference: Ghostty's ConEmu-style progress documentation). A standing report is handed to every band view as ctx.progress: state is in_progress, error, indeterminate, or paused; value is the percent when the report carries one. No core chip shows it - the old status bar's progress chip is gone - and a plugin's chip can rebuild it from the mirror (the band view's ctx). A report omitting its percent keeps the standing one (the protocol's leave-unchanged rule, states 2-4).

A standing number meets three deaths: the protocol's own state 0 clears it, the command's finish ends it (the foreground handoff the duration timer already observes), and it expires 15 s after its last refresh (Ghostty's own hardcoding, inherited).

To see each state from a shell by hand:

printf '\e]9;4;1;42\e\\' # in progress, 42%
printf '\e]9;4;1;84\e\\' # in progress, 84% - the value moves with each report
printf '\e]9;4;3\e\\' # indeterminate, no value
printf '\e]9;4;2;42\e\\' # error, 42%
printf '\e]9;4;4;42\e\\' # paused, 42%
printf '\e]9;4;0\e\\' # gone - the protocol's own clear
printf '\e]9;4;2\e\\' # error with no standing value
printf '\e]9;4;0\e\\' # gone - the protocol's own clear

A real integration emits from inside the long-running command, not from rc files. Anything already speaking ConEmu progress (tooling built for Windows Terminal, kitty, or Ghostty) works as-is.

A program's own status: OSC 7501​

OSC 7501 ; key=value[:key=value...] is Hashimoto's Program Status Protocol (libghostty and kitty read it; reference: the specification). The report's one required key is state - idle, working, done, blocked, or error - with an optional progress 0-100. The protocol's grammar holds exactly: unknown keys are ignored, malformed pairs are skipped, a repeated key's last value wins, and an unrecognized state discards the whole report. A standing record is handed to every band view as ctx.program_status: state, and progress the percent when the report carries one. No core chip shows it - the old status bar's tinted disc and side-by-side percent are gone - and a plugin's chip can rebuild them from the mirror.

The lifetime rides DropTerm's own observed edges, stronger than the protocol's prompt-mark proxies. The foreground handoff drops working/blocked (the program ended), and done/error persist until a newer report replaces them. state=clear clears, a full terminal reset clears everything, and a tab's respawn starts clean. One record is kept - the root report, the program's own summary. Child records (reports carrying an id) and the app, title, msg, and kind keys are ignored by design: title and msg are the protocol's text channels, and DropTerm renders no text channel. DropTerm answers nothing to the feature probe (OSC 7501 ; ?): a probing program gets silence and sends unconditionally.

To see each state from a shell by hand:

printf '\e]7501;state=working:progress=40\e\\' # working, progress 40
printf '\e]7501;state=blocked:kind=question\e\\' # blocked, kind question
printf '\e]7501;state=error:progress=70\e\\' # error, progress 70
printf '\e]7501;state=done\e\\' # done
printf '\e]7501;state=idle\e\\' # idle
printf '\e]7501;state=clear\e\\' # clear - gone, the protocol's own clear

A real emitter reports from inside the program. Terraform and claude-code already speak it (the protocol's own early adopters), and anything built for libghostty's or kitty's 7501 support works as-is.

What stands without them​

Without a D mark, DropTerm never guesses a verdict: a bell is not failure, a title is not a status. Without an OSC 7 report the directory chip reads the working directory DropTerm derives itself. Without an OSC 9;4 or an OSC 7501 report nothing stands for a plugin to read.