← All posts
·7 min read

Control Your Tesla from the Terminal for Free (Step-by-Step)

Tesla's Fleet API lets you lock doors, control climate, manage charging, and more — all from a terminal or script. The catch: before your app can send signed commands to the car, Tesla requires you to serve your public key at a publicly reachable HTTPS URL. Most tutorials tell you to spin up GitHub Pages or a VPS.

AgentGen's origin hosting eliminates that entirely. It's a free endpoint that provisions a permanent subdomain for you and serves your Tesla public key at the exact path Tesla expects. The teslacli tool wires everything together in a single interactive wizard.

This guide walks you through the full installation and setup — from zero to locking your car from the terminal.

What you'll need

  • A free AgentGen account (no credit card, no tokens required for key hosting)
  • A Tesla Developer account — you'll register the OAuth app mid-setup, once the wizard gives you your origin URL
  • macOS or Linux (x86_64 or ARM64)

Step 1: Create a free AgentGen account

Go to agent-gen.com, sign up, and copy your API key from the dashboard. Origin hosting — the feature that serves your Tesla public key — is completely free and doesn't consume any tokens.

Step 2: Install teslacli

Run the one-line installer. It detects your OS and CPU architecture automatically, downloads the latest release from GitHub, installs it to /usr/local/bin, and immediately launches the setup wizard:

curl -fsSL https://raw.githubusercontent.com/Agent-Gen-com/tesla-cli/main/install.sh | sh

If you prefer to build from source (requires Rust 1.70+):

git clone https://github.com/Agent-Gen-com/tesla-cli.git
cd tesla-cli
cargo install --path .

Step 3: Follow the teslacli setup wizard

The installer launches the setup wizard automatically. If you need to run it manually:

teslacli setup

Just follow the prompts — the wizard tells you exactly what to do at each step. Here's what to expect:

Step 3.1 — Choose setup mode

Select User flow if you're on the machine where you'll approve the Tesla OAuth login in a browser. Select Agent flow if you're on a headless or remote machine — it prints shareable URLs instead of opening a browser.

Step 3.2 — Connect AgentGen

Paste your AgentGen API key. The CLI provisions a subdomain like abc123.agent-gen.com and shows it to you on screen. Keep this URL handy — you'll need it in the next step when registering your Tesla Developer app.

Step 3.3 — Register your Tesla Developer app

Now that you have your AgentGen origin URL, go to developer.tesla.com and create an OAuth app:

  1. Create a new application and set your AgentGen subdomain (e.g. abc123.agent-gen.com) as the allowed origin/domain
  2. Set the OAuth redirect URI to http://localhost:13227/callback
  3. Copy your client_id, client_secret, and note your region (na / eu / cn)

Enter those values back in the wizard when it prompts for them.

Step 3.4 — Generate and enroll your key

The CLI generates a P-256 key pair and saves it to ~/.config/teslacli/keys/. It uploads the public key to AgentGen (served at https://abc123.agent-gen.com/.well-known/appspecific/com.tesla.3p.public-key.pem) and opens the Tesla enrollment URL:

https://tesla.com/_ak/abc123.agent-gen.com

Open this URL on your phone and tap Add key in the Tesla app. This approves your virtual key on the vehicle. You only do this once.

Step 3.5 — Partner registration

The CLI automatically registers your app with the Tesla Fleet API using your client credentials. Nothing to do here — just wait a moment.

Step 3.6 — OAuth login

In User flow, a browser opens to the Tesla OAuth page. Log in with your Tesla account. In Agent flow, the CLI prints the OAuth URL — open it on any device, log in, and paste the resulting callback URL back into the terminal.

Tokens are saved to ~/.config/teslacli/token.json and refreshed automatically.

Step 4: Control your Tesla

Once setup is complete, you're ready. Try listing your vehicles first:

teslacli vehicle list

Then try a command. Wake the car first if it's sleeping:

teslacli vehicle wake

Lock and unlock:

teslacli vehicle lock
teslacli vehicle unlock

Climate control:

teslacli climate start
teslacli climate set-temp -t 22.5   # 22.5 °C
teslacli climate stop

Charging:

teslacli charge set-limit -l 80     # charge to 80%
teslacli charge start
teslacli charge stop

If you have multiple vehicles, specify a VIN:

teslacli --vin 5YJ3E1EA... vehicle unlock

Or set it once as an environment variable:

export TESLA_VIN=5YJ3E1EA...
teslacli vehicle unlock

How AgentGen's origin hosting works

When you ran teslacli setup, it made two free API calls to AgentGen:

  1. POST /v1/origin — provisions your subdomain
  2. POST /v1/origin/{id}/public-key — uploads your PEM key so it's served at the Tesla-expected path

That's it. The subdomain is permanent and the key is served indefinitely. No GitHub Pages configuration, no domain setup, no server to maintain.

Common issues

"Key not enrolled on vehicle" — You skipped or didn't complete the approval step in the Tesla app. Re-run teslacli setup and make sure to tap Add key in the Tesla app when the enrollment URL opens.

"Handshake HTTP 408" — The vehicle subsystem timed out. Usually it just woke up. Run teslacli vehicle wake, wait 5 seconds, and retry.

"Token expired" — Tesla refresh tokens expire after ~45 days of inactivity. Re-run teslacli setup to reauthenticate.

What's next

Now that you have a working CLI, you can script it. A cron job to pre-condition the car before your commute, a shell alias to lock it from anywhere, or a full automation triggered from a home assistant — the Fleet API supports it all.

Create your free AgentGen account and get started in under 10 minutes.

Ready to start generating?

Create a free account and generate your first PDF or image in minutes.

Get started free