Introducing tmux-rs

richardscollin.github.io

844 points by Jtsummers 3 days ago


starchild3001 - 3 days ago

This is a fantastic write-up of a truly monumental effort. I have huge respect for the author's persistence. The line "Like gardening, but with more segfaults" really resonates. It’s this kind of deep-dive hobby project where you learn the most.

The experience with `c2rust` is particularly interesting. It reminds me of a similar shift I saw years ago with automatic code translators between other languages. They're incredible for getting a project off the ground and proving feasibility, just as the author found, but you often end up with code that's completely "un-idiomatic" for the target language. The decision to throw it all away and do a manual port, while surely gut-wrenching, was the right call. You just can't automatically translate the intent of the original C code into safe, idiomatic Rust.

The "Interesting Bugs" section gave me flashbacks. Bug #2, with the mismatched struct layout due to a missing `*`, is a classic FFI (Foreign Function Interface) nightmare. I once spent the better part of a week debugging a similar issue between C++ and C# where a single change in struct packing alignment was silently corrupting data downstream in very subtle ways. It's one of those bugs that makes you question your sanity. Finding that requires some serious debugging grit, so kudos to the author.

This project is a great case study in the real-world challenges of modernizing critical infrastructure code. The author mentions the next big goal is to convert the codebase from `unsafe` to safe Rust. I'm really curious about the strategy for that.

Refactoring away the raw pointers and complex control flow (like the `goto` patterns) into safe, idiomatic Rust without breaking everything seems like it would be even more challenging than the initial port. Will the approach be to introduce lifetimes and the borrow checker module-by-module? And what's the plan for the intrusive data structures? Replacing them with standard library collections like `BTreeMap` is the obvious choice, but I wonder if that will have performance implications that the original intrusive design was meant to avoid.

In any case, amazing work. Thanks for sharing the journey in such detail. I'll be following this project on GitHub for sure.

ethagnawl - 3 days ago

This announcement has my attention.

I've been working on a Rust-based tmux session manager called rmuxinator (i.e. tmuxinator clone) for a few years now. It (mostly) works and been slow going because ... life but I've recently picked it back up to fix some bugs. One of the last new features I'd added was the ability to use rmuxinator as a library in other Rust programs. I'd like to try forking tmux-rs, adding rmuxinator as a dependency and seeing if it would ... just work as a way to start sessions using per-project config files. I'm definitely not advocating for adding rmuxinator upstream but it would be very nice to have this sort of session templating baked into the "terminal multiplexer" itself.

The other interesting possibility I could foresee is doing things the other way around and having rmuxinator use tmux-rs as a library in order to setup and manage sessions instead of just dumping out shell commands -- which is fraught with edge cases. (Not sure if this is currently possible with tmux-rs, though.)

Once I wrap up the bugfixes I'm currently working on, I may fork this project and give one or both of the above a try.

Regardless, nice work by richardscollin!

mbreese - 3 days ago

> You might be asking: why did you rewrite tmux in Rust? And yeah, I don’t really have a good reason. It’s a hobby project. Like gardening, but with more segfaults.

I love this attitude. We don’t necessarily need a reason to build new things. Who knows what will come out of a hobby project. Thanks to the author for the great write up!

Also, my gardening is full of segfaults, coding a new project is definitely safer to my yard.

tekawade - 3 days ago

I love this. I also want to dabble into loving things to rust!

Here I want to call out zellij. Zellij is rust based terminal multiplexer.

I am user not creator. I love everything rust and finding and migrating to rust based solutions where feasible.

m3at - 3 days ago

Very much a side note, but:

> my feeling is that I’d still reach for it if my hands are really physically hurting, and I need to keep working. Usually once I reach the point where I’ve got blisters on my fingers I think it’s better to just take a break

I'm dumbfounded, and impressed in an unhealthy way. Do some of you regularly type so much that you develop blisters?

gmoque - 3 days ago

I love the attitude on this project and most of the comments are supportive. While rewriting a mature application to another language always sounds like a bad idea, there are so many learnings along the way. It's not about the end it's about the process.

Given the traction you got here and the advancements in AI, I'm sure this can become a very attractive hobby project for Rust beginners, there's probably a lot of easy bugs to fix. Fixing bugs, adding new features, and optimizing the code is all you need.

Here's an idea to get the ball rolling: Create a scratch buffer for Gemini CLI (or your favorite LLM) and enable it to interact with the various windows and panes of the tmux session.

Here's my use case, I use synchronized panes to send the commands into multiple servers, but some commands sometimes fail for various reasons. What if I can just ask the AI to send a series of commands and react based on the output and adjust along the way. It's like a dynamically generated custom shell script on the fly.

tialaramex - 3 days ago

Coincidentally I was just watching this, "Oxidise Your Command Line"

https://www.youtube.com/watch?v=rWMQ-g2QDsI

Some of that video is about stuff you have no use for if you're not a Rust developer, but, some of it is things that would be just as useful to anybody who is comfortable with, as it says, a command line interface.

pizlonator - 3 days ago

I just ported tmux to Fil-C in less than an hour (that included porting libevent and gettings its test suite to pass).

Works great and it's totally memory safe

usrbinbash - 3 days ago

> the code base is now 100% (unsafe) Rust

So the primary (or rather: only) reason for using Rust over C (memory safety) is out the window.

> I’d like to share the process of porting the original codebase from ~67,000 lines of C code to ~81,000 lines of Rust

And the codebase got bigger.

So yeah, as the author explains, hobby project, and kudos to that, but nothing that I will install on any box of mine any time soon.

Besides, applications like tmux would much rather be prime candidates for a rewrite in a garbage collected systems language (aka.; Go) than in Rust. tmux spends 99% of its time waiting for the user to hit a key, there is nothing performance critical in such an app that wouldn't be 100% adequately served by Go.

someperson - 3 days ago

Surely improvements be made to c2rust to reduce the cited information loss with constant naming, to reduce the initial conversion burden?

rthnbgrredf - 3 days ago

This seems like an excellent future use case for a fully automated process by a large language model that translates a non-trivial C codebase to Safe Rust in under an hour with high accuracy. However, as the author noted, even after some attempts with Cursor at the end of development, the tool wasn't able to accelerate the translation effectively (in mid-2025). So while the potential is promising, it appears we're still some way off.

Stranger_X - 2 days ago

Just launched StrangerMeet, a simple platform to chat anonymously with strangers via text — no signup needed. Inspired by the old-school internet randomness (think Omegle, but cleaner and focused on meaningful or just fun conversations). Would love your feedback — especially on performance, UX, and privacy concerns. It's super new (just 8 days live), so things might be a bit rough, but I'm improving it daily!

xvilka - 3 days ago

Nice, hope it will become cleaner code in time. I tried zellij multiple times but despite years of development it still misses many things tmux provides. Inability to show/hide status bar[1] is the most annoying.

[1] https://github.com/zellij-org/zellij/issues/694

teekert - 3 days ago

Nice, I like tmux, I use it daily, I live in it. I hope this version makes it easier to just scroll with the scroll wheel or ctrl-page-up/down, or ctrl tab through your panes, or just show the whole unconcatenated title in the bottom left ;)

Sorry I know this is not the place to complain, but it would be so nice!

df0b9f169d54 - 3 days ago

tmux has been used a lot of memory on my system, especially when scrolling buffer is large enough (I often have > 10k lines of things ).

I have often executed `pkill -9 tmux` and saved my day. I hope the rust version can help a bit here?

wiz21c - 3 days ago

> the code base is now 100% (unsafe) Rust > ... It’s a hobby project. Like gardening, but with more segfaults.

From now on, it's like gardening, but in hell :-)

sriku - 3 days ago

In "Interesting bugs / Bug 1",

  I walked through the code again. Inside of the Rust function (*c).bar has a valid address, like 0x60302764, but out the function, the value received from the calling C code was 0x2764.

  ...

  That’s right, the C code was using the implicit declaration which is:
   
  int get_addr();
  
  That explains why the value was incorrect! The C compiler was thinking a 4 byte int was returned not an 8 byte pointer. So the top 4 bytes were being truncated or ignored.
That's weird as an explanation. 0x60302764 is 4 bytes and 0x2764 is 2 bytes. Why would an address get truncated to 2 bytes? Is int 2-bytes according to any intermediate compilation stage? (Been at least 25 years since I saw int be 2 bytes, if ever).
submeta - 3 days ago

Tmux is a gamechanger for me. Being able to start a dozen different projects with one line (using tmuxinator): the server, tailing logfiles, activating venvs, running the docker container, all within one line of code: Awesome. Hadn’t worked with it for years, just started again two days ago as I migrated from iTerm to Ghostty. And am loving the setup. Plus nvim. Pure awesomeness.

Looking forward to check out tmux-rs.

seyz - 3 days ago

> I don’t really have a good reason. It’s a hobby project. Like gardening, but with more segfaults.

Love it. You definitively deserve your +350 points!

bakugo - 3 days ago

https://github.com/richardscollin/tmux-rs/issues/9

120 comments and nobody has mentioned the use-after-free triggered by closing a window. Rust truly is the safest language.

sunshine-o - 3 days ago

> I’d like to share the process of porting the original codebase from ~67,000 lines of C

I was surprised to learn tmux had such a "large" codebase, where does the complexity come from?

devy - 3 days ago

Wonder if anyone has tried these over flourishing AI code assist tools to supercharge the speed these porting projects? If so, what's the experience has been?

jimrandomh - 3 days ago

The author doesn't claim it, but worth stating explicitly: tmux is a security-critical piece of software that doesn't get the attention it deserves.

osigurdson - 3 days ago

I don't understand mouse support in tmux. tmux works great, then when you need to enable mouse support, it takes over everything works horribly.

alberth - 3 days ago

Slightly OT: it didn’t dawn on me until recently that terminal multiplier (like tmux) is a terminal itself.

And as a result, you could be running the greatest / fastest / most feature rich desktop terminal … but if your multiplier doesn’t support something - it hinders your fancy desktop terminal.

Short 3 min video explained by Ghostty creator

https://youtu.be/o-qtso47ECk

zoobab - 3 days ago

I was searching the other day for a Tmux/Screen replacement in python, anyone?

philosophty - 3 days ago

"Despite the generated code working, it was basically unmaintainable and 3x larger than the original C."

Which makes C2Rust seem pretty useless?

"I’ve recently reached a big milestone: the code base is now 100% (unsafe) Rust. I’d like to share the process of porting the original codebase from ~67,000 lines of C code to ~81,000 lines of Rust (excluding comments and empty lines)."

And yet somehow a hand-ported (and still unsafe) rewrite of a C program in Rust is still almost 20% larger?

If I recall, the Go gc compiler was automatically converted from 80K lines of C to 80K lines of Go. A hand-ported version would have been much smaller.

meindnoch - 3 days ago

Tmux is only 67k lines of C? That's surprisingly small.

sanity - 3 days ago

How do people feel about tmux vs zellij?

aldousd666 - 3 days ago

Great way to learn a new language!

- 3 days ago
[deleted]
a-dub - 3 days ago

the one thing i wish tmux supported was remote connections to several backend instances.

- 3 days ago
[deleted]
hyvan - 2 days ago

Hi

qwertywert_ - 3 days ago

You weren't really lying when you said "100% (unsafe) Rust" eh..

stephenlf - 3 days ago

Fun!

bitbeq - 3 days ago

wfd

cchance - 3 days ago

Next step slowly porting unsafe code to safe rust? lol

a-a-ron_b - 3 days ago

> Usually once I reach the point where I’ve got blisters on my fingers I think it’s better to just take a break.

What a legend.

denysvitali - 3 days ago

I like the initiative, but all this effort for ... unsafe Rust? I know it's a hot topic, and I hope the end goal is to have a memory-safe (and faster) tmux. I just hope the author doesn't stop here :)

Edit: As pointed out below, I'm stupid, it's stated in the article and I didn't read that part

uecker - 3 days ago

I like this post, one can learn a lot.

It seems automatically translating Rust to C is not a very good idea: "I threw away all of the C2Rust output and decided I would translate all of the files into Rust manually from C.". Neither seems doing it manually: "I introduced many bugs while translating the code. I’d like to share the process of discovering and fixing a couple." Or using AI: "That’s because when using cursor to translate the code it would still occasionally insert bugs, just like me. So, I spent as much time reviewing the generated code as it would have taken me to write it myself."

As a hobby project, all power to you. But otherwise, maybe better not rewrite working code....

- 3 days ago
[deleted]
lolive - 3 days ago

[flagged]

ConanRus - 3 days ago

[flagged]

deadbabe - 3 days ago

[flagged]

johnisgood - 3 days ago

[flagged]

malithmcr - 3 days ago

Rust is king

alexvitkov - 3 days ago

I'll take a rust tmux if it runs on Windows. I'm currently kind of stuck on Windows and I didn't realize how much tmux means to me until Bill took it away :(

blibble - 3 days ago

what is it with these re-implementations by different authors pinching the name of the original project?

you want to re-implement a well known project, fine

call it something else

lolive - 3 days ago

D.mn!

I was hoping for the announcement of a brand new bulletproof tmux-resurrect.

But no, it is (just) tmux-(recodedIn)rust.

z3ratul163071 - 3 days ago

rewriting old code in new language is the killer application for AI. should have used that instead of transpiler.

dangoodmanUT - 3 days ago

I love this, but the examples they show of their snippets are really, really not rust idiomatic.

Like they’ve basically thrown away all the rust patterns and just wrote a c program in rust (eg all the raw pointers)

londons_explore - 3 days ago

LLM's are really good at translating one programming language into another.

In fact, I sometimes port code to another language and back just as a way to do code cleanup (or at least give ideas for things that could be cleaned up)

I wonder why OP didn't start from that as a starting point?

echelon - 3 days ago

I wonder if the tmux maintainers would be interested in switching to this?

Transitioning more software from C to Rust is a great idea.

parhamn - 3 days ago

Interesting, this article and the comments make no mention of LLMs for the initial translation. Really surprising given that would be the first thing I'd reach for for a translation/porting task (though verification could get tricky).

Now I really wonder how a good model like Sonnet 4 would have performed.