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:
tmuxttydcloudflared, only for--cf-tunnel
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 |
--base-path PATH |
none | Serve under a URL path, e.g. /terminal (passed as ttyd -b) |
-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; authentication is optional |
--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.
For example, cf-share-tmux work:2 --base-path /terminal serves the terminal
at http://127.0.0.1:7681/terminal. The path must start with /; trailing
slashes are removed. Local and public URLs (including --json) include the
path. The -b option still selects the bind address.
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
- The target is resolved to a stable window ID.
- Unless
--foregroundis 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. - A temporary session
serve-tmux-<port>-<random>is created and the window is linked into it, so the browser starts on that window only. - ttyd serves
tmux attach-sessionto that session. - 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. - Once in the background, the process no longer writes anywhere; later errors are not shown.
- 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. - 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-onlyunless 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
psshows it, even when it comes fromTTYD_CREDENTIAL. - Authentication is optional, including through the tunnel. Without
-corTTYD_CREDENTIAL, anyone with the public URL can access the terminal. Set a long random password to require authentication. - Without
--cf-tunnel,-b 0.0.0.0without-cexposes 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.1).
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.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cf_share_tmux-0.1.1.tar.gz | 12.9 kB | Without provenance | Details for cf_share_tmux-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cf_share_tmux-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for cf_share_tmux-0.1.1-py3-none-any.whl |
Total release size: 22.6 kB
Security for cf-share-tmux 0.1.1
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.