Skip to main content

cf-share-tmux

Share one tmux window in the browser with ttyd, locally or publicly through a Cloudflare quick tunnel.

cf-share-tmux work:2 --cf-tunnel -c 'alice:long-random-password'

prints the local and the public https://….trycloudflare.com URL and the PID, then returns to the shell while sharing continues in the background. Stop it with kill <PID>; it also stops by itself when you close the shared window.

Requirements

Linux, Python 3.10 or newer (standard library only) and these executables on your PATH:

Installing this package does not install any of them.

Installation

uv tool install cf-share-tmux

Requires uv. uvx cf-share-tmux --help runs it without installing. You can also run the single file directly: python3 cf_share_tmux.py --help.

Usage

cf-share-tmux TARGET [options]

TARGET is a tmux window, for example work:2 or work:editor.

Option Default Meaning
-p, --port 7681 Local HTTP port for ttyd
-b, --bind 127.0.0.1 Address ttyd listens on
-c, --credential USER:PASSWORD none HTTP Basic Auth; also read from TTYD_CREDENTIAL
--read-only off Viewers cannot type
--check-origin off Make ttyd reject WebSocket connections from other origins
--cf-tunnel off Also publish through a Cloudflare quick tunnel; needs -c
--json off Print only {"url": "<public URL>", "pid": <PID>} on stdout; needs --cf-tunnel
--foreground off Stay in the foreground until Ctrl+C instead of going to the background
--version Print the version

Without --json, stdout shows the window, the temporary session, the local URL, whether auth is enabled, the PID and, with --cf-tunnel, Public: <URL>. With --json, stdout gets that single JSON line and nothing else; errors still go to stderr.

The command returns as soon as the share is ready: with --cf-tunnel when the public URL is known, without it once ttyd has been running for a second. Its exit status is 0 then, or the error status if something failed before that, so scripts can simply do:

url=$(cf-share-tmux work:2 --cf-tunnel --json --read-only -c "$CRED" | jq -r .url)

How it works

  1. The target is resolved to a stable window ID.
  2. Unless --foreground is given, the process forks: the child detaches from the terminal and does the work, the parent waits until the child reports that it is ready and then exits.
  3. A temporary session serve-tmux-<port>-<random> is created and the window is linked into it, so the browser starts on that window only.
  4. ttyd serves tmux attach-session to that session.
  5. With --cf-tunnel, cloudflared publishes ttyd. Its log is hidden; the public URL is taken from it. If cloudflared exits without a URL, the last 20 lines of its log go to stderr.
  6. Once in the background, the process no longer writes anywhere; later errors are not shown.
  7. It stops on SIGTERM (kill <PID>), on Ctrl+C or SIGHUP in the foreground, when ttyd or cloudflared exits, or when the shared window is closed. Then ttyd and cloudflared are stopped and the temporary session is removed. The window itself stays in its original session.
  8. ttyd and cloudflared are started with the Linux parent-death signal, so they are terminated even if the process is killed with kill -9; only the temporary tmux session is left behind in that case.

Security

Read this before sharing anything.

  • Input is enabled by default. Anyone who can open the page can type into your shell, with your user's permissions. Use --read-only unless you mean to hand over a shell.
  • The temporary session is not a sandbox. With input enabled, a viewer can use tmux key bindings to switch to any of your other sessions and windows.
  • Use --check-origin. Without it, any web page open in your browser can connect to the local ttyd WebSocket; browsers also send saved Basic Auth credentials with such connections.
  • The password is visible to local users. It is passed to ttyd on the command line, so ps shows it, even when it comes from TTYD_CREDENTIAL.
  • Through the tunnel, the password is the only protection. Anyone who learns the URL can try to guess it; use a long random one.
  • Without --cf-tunnel, -b 0.0.0.0 without -c exposes your shell to the whole local network over plain HTTP.

Development

uv run python -m unittest discover -s tests -v
uvx --from build pyproject-build
uvx twine check --strict dist/*

The tests need tmux for the end-to-end part (skipped otherwise). They run their own tmux server and fake ttyd and cloudflared, so they do not touch your sessions or the network.

Publishing

The version lives in __version__ in cf_share_tmux.py (currently 0.1.0). Build from a clean checkout using the commands above, ensuring dist/ contains only the current release, then upload:

uvx twine upload dist/*

Use an API token when Twine prompts for credentials. Never commit credentials. For subsequent releases, bump __version__ and build fresh artifacts; PyPI does not allow replacing an existing release file. GitHub Actions runs tests and validates distributions; publishing is manual.

License

MIT; see LICENSE.

Metadata

Release files for cf-share-tmux 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cf-share-tmux 0.1.0
File Size Uploaded Provenance Actions
cf_share_tmux-0.1.0.tar.gz 12.3 kB Without provenance Details for cf_share_tmux-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cf-share-tmux 0.1.0
File Interpreter ABI Platform Actions
cf_share_tmux-0.1.0-py3-none-any.whl Python 3 none any Details for cf_share_tmux-0.1.0-py3-none-any.whl

Total release size: 21.8 kB

Release files / cf_share_tmux-0.1.0.tar.gz

Download URL cf_share_tmux-0.1.0.tar.gz
Size 12.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b72cb0b6f37624ddf9895df19afc825d834a9fdb91b6dbe4bbcb7a733a34b3fc
BLAKE2b-256 checksum
How to use checksums
c216f6d1a66bfafadd0e3e06ff9cc14f269659071fe523f3515afa1777cbd155
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Release files / cf_share_tmux-0.1.0-py3-none-any.whl

Download URL cf_share_tmux-0.1.0-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
52761c7ebfd05b4f1037c49df463cbb7fdf1b329c0a447a878307ba799f79674
BLAKE2b-256 checksum
How to use checksums
5e6a0f74706338526698c101ec31291353812872628682bfe05698b447c160ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Security for cf-share-tmux 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page