Rerender scrollback after terminal resize
What feature would you like to see?
Summary
Running Codex inside narrow terminals causes conversation history to be inserted into the scrollback already wrapped to the small width. When the user later widens the terminal (e.g., reconnecting from desktop, or making it full-screen), previously emitted lines remain hard wrapped, so reading old messages is painful
Reproduction
- Start Codex in a very narrow terminal (just make it small, or use tmux over mobile SSH works well).
- Send/receive a few messages so history is printed into the scrollback.
<img width="200" height="296" alt="Image" src="https://github.com/user-attachments/assets/5c5c0085-aa5a-4101-b6e3-fad8593a0738" />
- Resize the terminal wider (or reconnect to tmux from a PC).
- Scroll up: older lines keep the original narrow wrapping while new frames render at the new width
<img width="501" height="300" alt="Image" src="https://github.com/user-attachments/assets/34eaa400-82f2-4514-8ebe-8fd02dc32ffc" />
Requested Feature
Add some way of redrawing history on resize. May be chat-command, or automatic resize with ~100ms waiting time after resizing is done to not produce flickering.
In my current implementation I've sticked with command one because it's more controllable, but this may be inconvenient to end user. I've already tried automatic resizing, but didn't push the code yet.
Example (using same setup as in reproduction):
<img width="250" height="128" alt="Image" src="https://github.com/user-attachments/assets/bc6c9637-ddf0-4d42-8d24-4228d058f12f" />
<img width="300" height="58" alt="Image" src="https://github.com/user-attachments/assets/2dedb084-5d89-46e6-9ced-30c1081cdc04" />
<img width="592" height="300" alt="Image" src="https://github.com/user-attachments/assets/37eece0d-8a43-4114-8c19-f32ecc27a8ed" />
Banner about successful resize lives for one second before switching off on any redraw.
Additional information
I don't know if it's really a bug, or missing feature, but i'll be glad to provide PR for any of the implementations.
11 Comments
+1 I get this pretty consistently using when using a terminal multiplexer (zellij) resizing terminal panes
This ticket looks to be related.
https://github.com/openai/codex/issues/3464
Can we label this a bug? The terminal should be redrawing when geometry changes/when it's foregrounded
@Nintorac, you may be interested in this thread. It's not clear that we will be able to address this particular issue. There are many difficult tradeoffs here.
Low-tech solution that solves the problem: close codex and run codex resume, it rerenders correctly!
This resolves the terminal corruption reported in a dozen other issues, and the problem is easily fixable. I use this patch every day, can't live without it.
The solution given here works elegantly and perfectly, and doesn't mess up the terminal in any way, works on OSX, Windows, every terminal I've tried it in. Sure, it fills your scrollback, but it resolves the immediate visual artifacts and all the actual grievances raised are moot.
It's not feasible to restart codex every time you resize your terminal. I resize my terminals often.
https://github.com/user-attachments/assets/b2e8a367-7bca-4091-9901-43931b55f7c4
I offered this patch before but was rejected because I need to be invited to do a PR. So invite me, tag me, or have someone with better contacts push it.
The claimed desired behavior is for Codex to function like a terminal app. But then it fails to rewrite the input area properly if the window resizes. Sure, rerendering the whole scrollback is excessive, but its a clean and simple patch that I don't foresee anyone complaining about, because they won't notice - because if they log all output to a file, which would be a dumb way to track Codex's work, they're extremely unlikely to resize the window while doing it.
At worst this stays in place and at best this buys time for someone to accommodate all the hundreds of terminal quirks when it comes to cursor movement.
The only people who will notice are the thousands who actually resize their windows and thinks less of OpenAI for not being able to maintain basic terminal hygiene... seeing a messed up terminal really does not inspire confidence in the rest of the codebase.
Running into this consistently when using Codex inside tmux panes. Resizing panes causes history content to disappear — the input area redraws correctly but everything above it gets corrupted.
Traced the root cause to
pending_viewport_area()incodex-rs/tui/src/tui.rs(~line 525). When terminal width changes, the terminal emulator reflows scrollback content independently, but the viewport Y position is only adjusted when cursor Y moves. In tmux, the cursor often stays put on width-only resize, so the viewport remains at its stale Y position and overwrites reflowed history.A minimal fix would be to reposition the viewport to the bottom of the screen on width change:
But the real fix (as proposed in this issue) is re-rendering the full transcript at the new width, since the history lines were hard-wrapped at the old width and can't reflow.
Both PRs that attempted to fix this (#11896, #12826) were closed due to the contribution policy. Would be great to see the team pick this up — it affects every terminal multiplexer user (tmux, Zellij, tiling WMs).
Can we please get this fixed? I'm facing this issue 24/7 an I'm unable to read codex's replies without always having to hit ctrl+t first to switch to transcript mode which is very annoying to scroll through and shows full transcripts of files read/edited)
I'm getting very bad text corruption with lots of missing lines while using Codex very normally in VS code's terminal:
In normal mode (missing tons of text whle working on a session)
<img height="300" alt="Image" src="https://github.com/user-attachments/assets/54268ace-f345-4b41-948a-fe9a39f89554" />
In transcript (virtual scroll mode) the text is shown fine.
<img height="300" alt="Image" src="https://github.com/user-attachments/assets/1ddba236-84c9-4a83-bf7b-393816599a1b" />
@maddada I can't remember seeing any lines disappear spontaneously, recently. If the lines disappear because of terminal size changes, the scrollback rendering will resolve it.
Would love this fixed upstream, I've fixed it for personal use in my own copy. Every other coding agent I've used implements this.
same issue here, since using superset and using a few clis at once, any kind of resizing, or adding new one to the grid messes them up :(
This feature will be included in the next release.