Moth runs a user-owned local proxy on macOS with the external Xray engine. Install Xray 26.11.9 on your PATH and build with cargo build --locked. Run target/debug/moth to open the terminal interface. The examples below assume the built binary is on your PATH.
| Command | Purpose |
|---|---|
moth |
Open the profile list. |
moth edit |
Add, rename, change or delete profiles in an editor. |
moth up [NAME] |
Connect, switch, or choose a saved profile inline. |
moth down |
Disconnect and wait for cleanup. |
moth ping [NAME] |
Verify a saved profile, choosing interactively when the name is omitted. |
moth logs [NAME] |
Read the latest attempt or retained attempts under a historical name. |
moth status [--json] |
Inspect the current daemon session. |
Run moth edit in a terminal. Moth opens a private TOML draft using VISUAL, then EDITOR, with vi as the fallback. Use one field per named table. File references are relative to the Moth profile directory or absolute, and require owner-only regular JSON files.
[profiles.office]
url = "trojan://[email protected]:443"
[profiles.home]
file = "home.json"Save and close the editor to validate the entire document. Invalid changes can be corrected in the same editor transaction. Reopening after another writer saved starts from the latest publication. moth up office connects or switches through the daemon and prints the verified endpoint. In a terminal, run moth up to choose beneath the command. Use ↑/↓ to move or / to filter by name. Enter applies the filter, then Enter on the highlighted row confirms it. The > marks your selection and [active] marks the connected revision. Esc or Ctrl-C cancels. Use moth up PROFILE in scripts or with redirected streams. Editing a table or deleting it leaves the running session intact. To reconnect after changing a profile, run moth up NAME explicitly.
On first edit with a legacy catalog, review the generated static JSON references before saving. Source URLs stay in the old catalog. A previously configured default link can be copied into a named table manually. The default data directory is ~/Library/Application Support/Moth. It holds plaintext credentials in owner-only files. Keep the original catalog and settings for rollback. An ungraceful editor or client termination can leave a private draft or staged JSON directory there. Inspect it before removing anything. The accepted configuration may still reference imported JSON files. To return to the previous binary, disconnect explicitly, shut down the daemon, then use the preserved catalog. Subsequent named-profile edits live in the separate private snapshot.
Move with the arrows or j/k. Press / to search, Enter to finish typing, then Enter to connect. The highlight follows the cursor. The active badge stays with the running session. Press e to edit, p to verify, l to open logs, d to disconnect and q to close. In search and log views Ctrl-D disconnects. Escape backs out of those views or cancels a verification initiated by this interface. Closing the interface leaves the daemon serving the current session.
The daemon starts on demand, checks local listener ownership and reports its actual endpoint. Selecting an unchanged active profile keeps its session. Confirming another profile preflights it before draining the old session. A startup failure after the old session has drained can leave the proxy disconnected. Read the attempt log for the failing stage.
moth ping office sends one TLS-verified HTTPS HEAD through office to https://connectivitycheck.gstatic.com/generate_204. A 2xx response proves that request reached the destination. Redirects and certificate failures fail verification. Allow 10 seconds for the request, up to 30 seconds including isolated startup, and a separate cleanup deadline. An inactive profile receives a temporary loopback port. One verification runs at a time. The result records elapsed time and completion for the exact revision tested. Repeat the command for a fresh observation. For a batch, invoke ping once per name and collect each exit status.
Inspect moth logs office after a failed start or disconnect, even after the daemon exits. Private local history retains up to 32 attempts, 64 events per attempt and 1 MiB total. Stages include local validation, readiness, verification and release. Safe classifications from Xray appear alongside lifecycle events. Credentials and raw engine output stay out of the journal.
Scripts should pass names explicitly. Piping the interactive editor, selector or dashboard gives usage guidance and exits 2. Successful results use stdout, progress and errors use stderr. Operational failures exit 1. Interrupting a CLI connect or disconnect stops waiting and leaves accepted daemon work running. Inspect status before retrying. Interrupting ping requests cancellation and waits for cleanup. SIGINT and SIGTERM during those waits exit 130 and 143 respectively when cleanup succeeds. Losing the client leaves accepted work bounded by daemon deadlines.
moth status --json returns one versioned object. Read phase, name, profile (captured ID and revision), generation, endpoint and ready_at_unix_ms for the session. An optional verification contains its attempt, measured revision, completion time, elapsed milliseconds and outcome or failure. A successful status read exits zero even when the session phase is failed. An unreachable daemon reports a diagnostic on stderr.
If the control socket is unreachable, Moth cannot report the proxy state. Inspect the private runtime directory, using the configured MOTH_RUNTIME_DIR when set.
runtime_dir=${MOTH_RUNTIME_DIR:-"$(getconf DARWIN_USER_TEMP_DIR)moth"}
ls -ld "$runtime_dir" "$runtime_dir/control.sock"
lsof -nP -a -U -- "$runtime_dir/control.sock"Check the directory and socket types, owners and permissions. Compare any live socket holder with the Moth daemon you started or with the service owner's records. A filename, executable name, PID or free advisory lock alone cannot establish ownership. If evidence remains inconclusive, leave the entry in place and contact the operator responsible for the service. Once that operator resolves the verified conflict, explicitly retry the original moth up command.
If startup reports an occupied proxy port or cannot verify its listener, inspect TCP listeners on the configured port. Substitute your local inbound port for 1080.
lsof -nP -a -iTCP:1080 -sTCP:LISTENCompare the loopback address and port with your inbound configuration and confirm which service owns the listener. If ownership is unclear, leave it running and consult the responsible operator. After the owner resolves the conflict, run moth up NAME again. From a second shell, run moth status --json and confirm that phase is connected and ready_at_unix_ms has a value.
Use one explicit unauthenticated loopback TCP inbound (SOCKS5 or HTTP) and one outbound. For VLESS and Trojan, supported transports include raw TCP, WebSocket, HTTPUpgrade, gRPC, XHTTP and mKCP. The share-link compatibility table below lists the validated combinations. Import a regular JSON file up to 1 MiB. It supports flat server settings and the single-server Xray forms vnext/users and servers. The supported stream settings include inline TLS or REALITY client parameters. The schema rejects unknown fields, external file references, custom routing, UDP on the local listener and additional listeners.
This synthetic Trojan configuration exercises local readiness. Replace the outbound values with your server configuration for actual use.
{
"inbounds": [
{"protocol": "socks", "listen": "127.0.0.1", "port": 1080, "settings": {"auth": "noauth"}}
],
"outbounds": [
{
"protocol": "trojan",
"settings": {"address": "example.invalid", "port": 443, "password": "synthetic"},
"streamSettings": {"network": "raw", "security": "tls", "tlsSettings": {"serverName": "example.invalid"}}
}
]
}For VLESS, use protocol vless with server settings such as {"address":"example.invalid","port":443,"id":"f39b56aa-a622-4a84-8ef0-05d857928227","encryption":"none"}. Validation and launch use the same private copy of the original bytes and the input file's parent directory. Moth removes the copy during shutdown.
Moth accepts the following combinations on Xray 26.11.9. Trojan defaults to raw TCP and TLS. VLESS requires an explicit security value. To use plaintext, specify security=none explicitly. Plaintext exposes Trojan authentication material to observers on the path. Field mappings, synthetic examples and verification evidence
| Transport | Security for VLESS and Trojan | Share-link options |
|---|---|---|
raw, tcp (default) |
TLS, REALITY, none | Optional HTTP header with host and path lists. VLESS Vision and Vision -udp443 require TLS or REALITY. |
ws, websocket |
TLS, none | Host, path, optional early-data length and the standard WebSocket subprotocol header. |
httpupgrade |
TLS, none | Host and path. |
grpc, gun |
TLS, REALITY, none | Optional service name (empty by default), optional authority, gun (default) or multi mode. |
xhttp, splithttp |
TLS, REALITY, none | Host, path, auto (default), packet-up, stream-up or stream-one. Inline options include headers, padding, upload limits, multiplexing and split download settings. |
kcp, mkcp |
TLS, none | UDP transport to the peer, optional MTU and interval. The local listener serves TCP. |
VLESS accepts UUIDs, custom IDs and client encryption strings. Trojan passwords are percent-decoded once. TLS options include SNI, fingerprints, ALPN, SHA-256 pins, certificate names and inline ECH. REALITY supports public keys, short IDs, spider paths and optional ML-DSA verification. The fixture exercises paired inline FinalMask settings. Unsupported settings and conflicting aliases reject the edit and preserve the last accepted revision.
Update the CLI and daemon together before using mKCP. Session identity in moth status --json reports transport: "kcp" for mKCP. Older clients with a closed transport enum cannot decode that value.
Run cargo fmt --check, cargo build --locked, cargo test --locked and python3 scripts/check-workspace.py. The routine tests use synthetic configurations, loopback services and a pseudo-terminal. On macOS, run cargo test --locked -- --ignored with Xray, OpenSSL, Node.js, Python 3.11+, curl and local port 1080 available. The installed-engine tests exercise the share-link matrix and named terminal workflows, including HTTPS delivery through two independent peers, cancellation, retained logs and listener cleanup.
The project pins its development toolchain in mise.toml. The product baseline, architectural decisions and platform research describe the supported scope and the evidence for recovery behavior. Product baseline · Decision records · Research plan