Line Wrap Not Working Correctly with Tmux and Mosh

Abstract: Fix tmux line wrap failures over mosh by setting default-terminal to xterm-256color, updating environment variables, and enabling aggressive-resize.

Created: 2026-07-28 by
Line wrap failures in tmux over mosh typically stem from mismatched terminal width settings or missing escape sequences. The most effective fix involves ensuring the remote shell correctly reports its dimensions to tmux by setting the TERM environment variable to xterm-256color and configuring tmux to update this status dynamically. This aligns the client's rendering engine with the server's expectations, preventing text from spilling off-screen or breaking awkwardly.

Understanding the Root Cause

The issue arises because mosh acts as a wrapper around ssh, but it handles terminal resizing differently than standard ssh sessions. When you connect via mosh, the initial connection might establish a specific window size. However, if your local terminal emulator resizes, mosh notifies the server, but tmux might not immediately reflect this change in its internal state. Consequently, tmux continues to render output based on an outdated width, causing lines to wrap prematurely or not at all. Furthermore, the TERM variable plays a critical role. If tmux is set to a generic terminal type that does not support advanced wrapping features, or if mosh overrides it incorrectly, the rendering logic fails. Mosh clients often send specific escape codes to adjust the terminal properties, but tmux needs to be explicitly told to trust and propagate these changes to the applications running inside it.

Configuring Terminal Emulator Settings

Before diving into tmux configurations, ensure your local terminal emulator (such as iTerm2, Terminal.app, or GNOME Terminal) is sending the correct information to mosh. Most modern terminals allow you to specify the TERM type in their preferences. You should set this to xterm-256color. This setting ensures that both the local side and the remote side agree on the capabilities of the terminal, including line wrapping behavior. If you are using a custom shell configuration, verify that you are not overriding the COLUMNS or LINES environment variables in your .bashrc or .zshrc. Hardcoding these values can prevent dynamic resizing from taking effect. Remove any static assignments for these variables to allow the system to calculate them automatically based on the actual window size. Quitting Mosh Inside Tmux: A Tech Support Solution discusses related session management issues, which often overlap with configuration problems like incorrect terminal types. Ensuring your session environment is clean of hardcoded dimensions is a prerequisite for fixing wrap issues.

Tmux Configuration Adjustments

To resolve the line wrap problem within tmux, you need to adjust how tmux detects and updates the terminal size. Add the following lines to your ~/.tmux.conf file:
set -g default-terminal "xterm-256color"
set -g update-environment "TERM COLUMNS LINES"
setw -g aggressive-resize on
The default-terminal option tells tmux what kind of terminal it is emulating. Setting it to xterm-256color ensures compatibility with most modern tools. The update-environment directive is crucial; it instructs tmux to sync the TERM, COLUMNS, and LINES variables from the outer shell into the inner tmux environment whenever they change. Without this, tmux ignores the resize events sent by mosh. The aggressive-resize option forces tmux to attempt resizing even if some applications do not respond quickly to the SIGWINCH signal. This is particularly helpful in unstable network conditions where mosh might delay resize notifications.

Verifying the Fix

After updating your configuration, restart tmux completely to apply the changes. Detach from any existing sessions (Ctrl-b d) and kill the server process, then start a new one. Connect via mosh again and open a pane or window. Resize your local terminal window significantly wider and narrower. Observe whether the text wraps cleanly at the edge of the pane without cutting off mid-word or leaving excessive whitespace. You can also check the current column count by running echo $COLUMNS inside tmux. Compare this value with the actual width of your terminal. If they match, the environment variables are being synced correctly. If they do not match, review your update-environment setting and ensure no shell scripts are overriding COLUMNS after tmux has started. For users experiencing other input-related glitches during these transitions, understanding how to manage keystrokes is vital. See How to Increase Timeout for Chain Commands and Keystrokes in Tmux for insights on command latency that might mimic wrap errors.

Frequently Asked Questions

Why does line wrap work in SSH but fail in Mosh?

Mosh uses a different protocol for handling terminal state updates compared to SSH, which can lead to timing discrepancies in how resize signals are processed. While SSH sends immediate updates, mosh may buffer them slightly differently, requiring tmux to be more aggressively configured to catch these changes.

Can I fix this without editing .tmux.conf?

No permanent fix requires configuration changes because the default tmux settings do not always sync environment variables reliably over mosh connections. However, you can temporarily test the fix by manually exporting COLUMNS and LINES before starting tmux, though this is not scalable for regular use.

Does changing the terminal theme affect line wrap?

Changing themes does not directly impact the logical wrapping of text, but certain color schemes might make visual artifacts appear more pronounced. The core issue is always dimensional calculation, not aesthetic rendering, so focus on TERM settings rather than colors.

What if my application still breaks lines incorrectly?

If tmux itself is wrapping correctly but your application (like vim or less) is not, the issue lies within that application's terminal detection. Ensure the application is aware of the correct TERM variable and consider restarting it after tmux has fully initialized to pick up the new environment.

Is there a performance cost to enabling aggressive-resize?

The performance cost is negligible on modern systems. Aggressive-resize primarily affects how quickly tmux responds to window size changes, ensuring smooth user experience during rapid resizing events without adding noticeable CPU overhead.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More