ctunnel
v1.0.3
Published
Expose localhost to the world with API key authentication (Fork of localtunnel)
Readme
ctunnel
ctunnel exposes your localhost to the world for easy testing and sharing! No need to mess with DNS or deploy just to have others test out your changes.
Great for working with browser testing tools like browserling or external api callback services like twilio which require a public url for callbacks.
About ctunnel
ctunnel is a fork of localtunnel, customized for users of claude.ws.
Key differences from upstream localtunnel:
- API Key Authentication: Requires an API key (
ct_live_format) for tunnel creation - Default Server: Uses
https://claude.wsas the default tunnel server - Enhanced Error Handling: Graceful handling of authentication errors (401, 503)
Getting an API Key
The tunnel server requires an API key for authentication. To get your API key:
- Visit https://claude.ws/access to create an account
- Generate your API key from the dashboard
- Use the key with ctunnel
API key format: ct_live_ followed by 32 hex characters.
Quickstart
npx ctunnel --port 8000 --key ct_live_your_api_key_hereInstallation
Globally
npm install -g ctunnelAs a dependency in your project
yarn add ctunnelHomebrew
brew install ctunnelCLI usage
When ctunnel is installed globally, just use the ctunnel command to start the tunnel.
ctunnel --port 8000 --key ct_live_your_api_key_hereThats it! It will connect to the tunnel server, setup the tunnel, and tell you what url to use for your testing. This url will remain active for the duration of your session; so feel free to share it with others for happy fun time!
You can restart your local server all you want, ctunnel is smart enough to detect this and reconnect once it is back.
Arguments
Below are some common arguments. See ctunnel --help for additional arguments
--portor-p(required) Internal HTTP server port--keyor-kAPI key for tunnel server authentication--subdomainor-srequest a named subdomain on the tunnel server (default is random characters)--releaseor-r <subdomain>release/delete a subdomain--local-hostor-lproxy to a hostname other than localhost--hostor-hupstream tunnel server (default: https://claude.ws)--versionor-vshow version number--helpshow help
Usage Examples
With CLI flag:
ctunnel --port 3000 --key ct_live_0123456789abcdef0123456789abcdefWith short flags:
ctunnel -p 3000 -k ct_live_0123456789abcdef0123456789abcdefWith environment variable:
export CTUNNEL_KEY=ct_live_0123456789abcdef0123456789abcdef
ctunnel --port 3000With custom subdomain:
ctunnel -p 3000 -s myapp -k ct_live_0123456789abcdef0123456789abcdefRelease a subdomain:
ctunnel --release myapp --key ct_live_0123456789abcdef0123456789abcdefCheck version:
ctunnel -vEnvironment variables:
You may also specify arguments via env variables. E.x.
PORT=3000 ctunnelAvailable environment variables:
CTUNNEL_KEY- Your API keyCTUNNEL_SERVER- Tunnel server URL (default: https://claude.ws)
API
The ctunnel client is also usable through an API (for test integration, automation, etc)
ctunnel(port [,options][,callback])
Creates a new tunnel to the specified local port. Will return a Promise that resolves once you have been assigned a public url. options can be used to request a specific subdomain. A callback function can be passed, in which case it won't return a Promise. This exists for backwards compatibility with the old Node-style callback API. You may also pass a single options object with port as a property.
const ctunnel = require("ctunnel");
// Set server via environment variable (optional)
// process.env.CTUNNEL_SERVER = 'https://claude.ws';
(async () => {
const tunnel = await ctunnel({
port: 3000,
api_key: 'ct_live_0123456789abcdef0123456789abcdef'
// host: 'https://custom.server.com' // optional, overrides CTUNNEL_SERVER
});
// the assigned public url for your tunnel
tunnel.url;
tunnel.on("close", () => {
// tunnels are closed
});
})();options
port(number) [required] The local port number to expose through the tunnel.api_key(string) API key for tunnel server authentication. Format:ct_live_+ 32 hex characters.subdomain(string) Request a specific subdomain on the proxy server. Note You may not actually receive this name depending on availability.host(string) URL for the upstream proxy server. Defaults toCTUNNEL_SERVERenv var orhttps://claude.ws.local_host(string) Proxy to this hostname instead oflocalhost. This will also cause theHostheader to be re-written to this value in proxied requests.local_https(boolean) Enable tunneling to local HTTPS server.local_cert(string) Path to certificate PEM file for local HTTPS server.local_key(string) Path to certificate key file for local HTTPS server.local_ca(string) Path to certificate authority file for self-signed certificates.allow_invalid_cert(boolean) Disable certificate checks for your local HTTPS server (ignore cert/key/ca options).
Refer to tls.createSecureContext for details on the certificate options.
Tunnel
The tunnel instance returned to your callback emits the following events
| event | args | description | | ------- | ---- | ------------------------------------------------------------------------------------ | | request | info | fires when a request is processed by the tunnel, contains method and path fields | | error | err | fires when an error happens on the tunnel | | close | | fires when the tunnel has closed |
The tunnel instance has the following methods
| method | args | description | | ------ | ---- | ---------------- | | close | | close the tunnel |
Tunnel.release(subdomain, host, apiKey)
Static method to release (delete) a subdomain. This disconnects any active tunnel and releases the subdomain ownership.
const ctunnel = require("ctunnel");
(async () => {
try {
const result = await ctunnel.release(
'myapp',
'https://claude.ws',
'ct_live_0123456789abcdef0123456789abcdef'
);
console.log(result); // { released: true, subdomain: 'myapp' }
} catch (err) {
console.error(err.message);
}
})();Parameters:
subdomain(string) [required] The subdomain to releasehost(string) Tunnel server URL. Defaults toCTUNNEL_SERVERenv var orhttps://claude.wsapiKey(string) API key for authentication
Error responses:
| Error Code | Description |
|------------|-------------|
| 401 | Authentication required |
| 403 | You do not own this subdomain |
| 404 | Subdomain not found |
Error Handling
The client handles authentication errors gracefully:
| Error Code | Description |
|------------|-------------|
| ERR_INVALID_API_KEY | API key is invalid or expired |
| ERR_AUTH_UNAVAILABLE | Authentication service is unavailable |
License
MIT
