Skip to content

Sanitize prompt before starship init#4269

Merged
dhh merged 1 commit intobasecamp:devfrom
foucist:patch-1
Feb 1, 2026
Merged

Sanitize prompt before starship init#4269
dhh merged 1 commit intobasecamp:devfrom
foucist:patch-1

Conversation

@foucist
Copy link
Contributor

@foucist foucist commented Jan 15, 2026

Summary

Adds prompt sanitization to clear stale terminal line state after abnormal exits, preventing prompt artifacts.

In some cases, exiting a program abruptly can leave residual output on the current terminal line, causing the next prompt to render incorrectly. This change ensures the prompt is always drawn on a clean line.


Example

iex
# press Ctrl-\

Exiting iex with Ctrl-\ sends SIGQUIT, which terminates the process without restoring terminal display state. When control returns to the shell, leftover output may remain on the line.

This behavior is not specific to IEx; any program that exits without cleaning up the terminal line can trigger it.


Fix

Starship assumes a clean terminal line when rendering the prompt and does not perform line hygiene itself. Before rendering the prompt, the shell now resets the cursor position and clears the current line, preventing prompt corruption regardless of how the previous process exited.

Add prompt sanitization to clear stale terminal line state after abnormal exits, preventing prompt artifacts.
@dhh dhh changed the base branch from master to dev February 1, 2026 16:49
@dhh dhh merged commit 49a2941 into basecamp:dev Feb 1, 2026
severin-richner pushed a commit to severin-richner/omarchy that referenced this pull request Feb 11, 2026
Add prompt sanitization to clear stale terminal line state after abnormal exits, preventing prompt artifacts.
antonovch pushed a commit to antonovch/omarchy that referenced this pull request Feb 13, 2026
Add prompt sanitization to clear stale terminal line state after abnormal exits, preventing prompt artifacts.
antonovch pushed a commit to antonovch/omarchy that referenced this pull request Feb 13, 2026
Add prompt sanitization to clear stale terminal line state after abnormal exits, preventing prompt artifacts.
@foucist foucist deleted the patch-1 branch February 21, 2026 08:31
@dhh
Copy link
Member

dhh commented Feb 27, 2026

This has a worse side effect: #4783. Reverting.

dhh added a commit that referenced this pull request Feb 27, 2026
dhh added a commit that referenced this pull request Feb 27, 2026
@foucist
Copy link
Contributor Author

foucist commented Feb 28, 2026

My bad! As it turns out, there’s a good reason for Starship’s default add_newline = true, which always prints a newline before the prompt.

With PS1-style prompts in bash and zsh, the line editor (Readline / ZLE) owns the line state and effectively “sanitizes” it, so there’s no need for an extra newline. I was trying to make Starship feel more like that, but since it just writes to stdout without access to the internal line state, that led me to a hacky workaround that only made things worse.

Sorry about that!

It seems the only reliable way to guarantee a clean prompt is to accept the newline default (or switch back to PS1).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants