Start an EC2 instance from Claude Code (and stop it automatically)

13 min read
A quiet home office at dusk: a pushed-back chair, an empty mug and a keyboard on a dark desk, a laptop with its lid half closed and its screen dark. Through the window, a data center glows navy blue with rows of emerald lights and one bright green indicator about to go out.

TL;DR — Add one MCP server to Claude Code, sign in to Idlefy in your browser, then type “start the load-test box for two hours”. Claude lists the machines you may use, asks you to confirm, and calls lease_vm. The instance starts, and when the two hours run out it stops on its own: no cron job, no “remind me”, no GPU box left running until Monday. Idlefy does not create instances for you on this path; it starts machines your organization already connected and tagged. The full reference lives on the MCP server page.

I run Idlefy. Most of what we do is boring on purpose: a machine in AWS or Google Cloud stays stopped until a person leases it for a set time, and it stops again when that time ends. This year the person asking for the machine is increasingly an AI assistant acting for a developer, so we put the same leases behind a remote MCP server. This post is the shortest walkthrough I can write for one client, Claude Code, and one job: get an EC2 instance running for the next couple of hours and never think about turning it off.

What does “start an EC2 instance from Claude Code” actually mean?

It means Claude Code calls a tool that starts an existing, stopped instance for a fixed duration, and the same system stops it when the duration is over. Idlefy does not create a new instance when you lease. An organization owner connects the AWS account once, by creating one CloudFormation stack, Idlefy-Manage, in the AWS console from a link Idlefy gives them (it makes an IAM role Idlefy signs in to with short-lived tokens; no access keys), and tags the instances Idlefy may manage with idlefy=enabled. The IAM policy in that stack lets Idlefy start, stop and reboot only instances tagged idlefy=enabled; beyond that it can read instance details, and it has no access to S3, databases or anything inside a machine. An untagged machine cannot be started or stopped even if someone asks nicely. From then on, every one of those machines sits stopped by default, and a lease is what turns one on.

So the vocabulary for the rest of this post is:

  • Lease (lease_vm): start a connected machine for N minutes. It stops itself when the time runs out. This is the path the title is about.
  • Dev box (create_dev_box): a brand-new personal machine Idlefy creates in the organization’s AWS account, with your SSH key on it. Its lifetime ends by deleting the box, disk included. Available only where the organization has switched Dev Boxes on. Dev Boxes use a second CloudFormation stack, which an owner sets up from the web app, that lets Idlefy create and delete those boxes; the Idlefy-Manage stack alone cannot create anything. Once a dev box exists, you lease it like any other machine.

Keep the two apart and the rest is easy. Mix them up and you will ask Claude to “create an instance for two hours” and get a box that lives for two hours and then disappears, which is not what most people mean.

What do you need before you start?

Four things. If your organization is already connected, only the last one is yours to do.

  1. An Idlefy organization with a connected AWS account. The owner creates the Idlefy-Manage CloudFormation stack in the AWS console from the link Idlefy gives them, and tags the instances. (An owner can drive the Idlefy side of this from Claude Code too; creating the stack and tagging still happen in AWS.)
  2. A machine you may use. As a member you see the instances assigned to you or to one of your teams. If list_vms comes back empty, nothing is broken; your team lead has not assigned you a machine yet.
  3. Any Idlefy plan. The MCP server is included on Free, Basic and Pro. What you can do through it follows your plan and your role, the same as in the web app. Plans are on the pricing page.
  4. Claude Code, signed in, on the laptop you work from. Nothing goes on the EC2 instance itself: there is no agent to install, and Idlefy never reaches inside your machines.

How do you connect Claude Code to Idlefy’s MCP server?

One command in your terminal, then a browser sign-in:

claude mcp add --transport http idlefy https://mcp.idlefy.com/mcp/

That adds the server for the current project only, which is Claude Code’s default scope. To have Idlefy in every project, add it at user scope instead:

claude mcp add --transport http --scope user idlefy https://mcp.idlefy.com/mcp/

(The scopes are described in the Claude Code MCP docs (opens in a new tab).)

Then, inside Claude Code, run /mcp and choose to authenticate the idlefy server. Your browser opens an Idlefy sign-in page; you sign in as yourself, review the access level the assistant is asking for, and approve it. That is the whole setup. There is no API key to create, copy or rotate: sign-in is standard OAuth 2.1, and the token Claude Code receives works only against the Idlefy MCP server, not against the rest of Idlefy and not against AWS.

The access level follows your role in the organization. A member gets the lease tools, Smart Workflows, the waitlist, their own dev boxes and a read-only view of budgets. A team lead also sees spend and the idle audit and can start or stop machines for their team. An owner can connect cloud accounts and change roles. Idlefy re-checks your role on every request, so if it changes, the assistant’s reach changes with it (after a promotion, reconnect to see the new tools).

Claude desktop and Cursor connect to the same address; the MCP server page has the steps for each.

How do you ask Claude for a machine for two hours?

You ask in plain words, Claude asks you to confirm, and then it calls lease_vm. Here is a typical exchange, paraphrased. Example only: the exact phrasing on your side and Claude’s will differ, and what matters is the sequence.

You: start the load-test box for two hours

Claude calls list_vms and finds load-test-1 (stopped, c6i.2xlarge, us-east-1) among your machines. It quotes the machine’s hourly list price from AWS, which comes back with the listing, and asks: this starts a paid machine for two hours, go ahead?

You: yes

Claude calls lease_vm with that VM and 120 minutes, and replies that load-test-1 is starting and names the time it will stop.

Three things in that exchange are by design, and they are why I trust this flow with my own account.

First, list_vms answers with your own machines by default. For an owner or a team lead, who can see more, it also says how many more their role could list, and Claude is told to mention that number and offer to widen the search, not to widen it on its own. A member’s assistant only ever sees the member’s own machines.

Second, the confirmation is part of the rules, not a courtesy. The server tells every assistant to get your yes before anything that costs money, affects colleagues or cannot be undone: starting a machine, leasing, creating or deleting a dev box, ending someone else’s session. If you say “start it for a bit”, Claude is told to ask how long rather than guess.

Third, the end time is set when the lease starts. The machine comes up in about a minute, and it already knows when it stops.

What happens when the two hours run out?

The instance stops; it is not terminated. The EBS volumes stay, and the next lease starts the same machine with everything on it. Before that happens, Idlefy warns you 20 and 5 minutes before the end, in Slack or Telegram if you linked them (with extend buttons) and in an open Idlefy web app tab. The warning goes to you, not to Claude Code; the assistant has no inbox, and it is explicitly told that a reminder is not an extension. If you want more time, you ask for it.

On Pro, the Safety System adds one safety net: if the lease is about to expire while the machine still looks in use and you have not answered the warning, Idlefy grants a single 30-minute grace period and notifies you again. After that one window the machine stops unless you extend. Activity can postpone the stop once; it can never cancel it. Extending the lease is what keeps a machine running, and the full lifecycle is on the how it works page.

Two caveats about a stopped instance. A stopped machine still costs its EBS volumes, and an Elastic IP if you attached one; what you stop paying for is the compute, the big line. Without an Elastic IP the public address usually changes on the next start. And data on local instance-store scratch drives, which many GPU families carry, does not survive a stop. If your training run writes checkpoints to the local NVMe, copy them to the EBS volume or to S3 before the lease ends, exactly as you would before any stop.

How do you extend, shorten or stop early?

Ask Claude, and it calls one of three tools. extend_rental adds minutes to the end. set_rental_remaining sets the time left from now, so “give it 45 more minutes from now” and “cut it to 15” are the same tool; shortening does not stop the machine now, it moves the end time, and the warnings move with it. release_rental ends the lease immediately and stops the machine. For your own lease, that last one is the only way to stop early through the assistant, and Claude calls it only when you ask: the cardinal rule the server gives every assistant is that it never stops, releases or deletes anything on its own initiative, not to save money, not because a machine looks unused, not to tidy up.

Each plan has a maximum lease length, and the assistant is told to tell you the cap rather than silently lease for less. The limits are on the pricing page.

What if the machine is already taken, or does not exist yet?

If a colleague already holds the machine, lease_vm is refused and Claude tells you the machine is taken and offers the waitlist. join_waitlist reserves nothing and starts nothing: Idlefy sends one message when the machine is free, to Slack, Telegram or an open web app tab, and the assistant is told to tell you where that message will arrive. It will not say “I’ll let you know”, because it cannot.

If there is no machine for you at all, you have two options. The usual one is to ask your team lead to assign one. The other, where your organization has switched Dev Boxes on, is to ask Claude for a dev box. That is a different flow and worth knowing on its own:

  • Claude calls list_devbox_accounts and get_devbox_create_options to find the regions, sizes, images and your saved public SSH keys, and chooses them with you. It never accepts or generates a private key.
  • It needs your public IP address for the SSH rule and cannot see it, so it will ask.
  • It asks how long the box should live. A lifetime deletes the box, disk and all, when it ends; without one the box is never deleted automatically, and Claude is told to say so plainly before creating it.
  • create_dev_box answers at once with a box that is being created. A ready box is stopped, and you lease it with lease_vm like any other machine.

A dev box is a machine for weeks or months with leases inside it. A lease is two hours of an existing machine. Every lease stops the machine when it runs out; the box itself is deleted only if you gave it a lifetime. This post is about the lease.

Why not just give Claude AWS credentials and call StartInstances?

Because then nothing stops the machine, and the agent can now do whatever those credentials allow. A generic cloud MCP server or a shell tool with aws ec2 start-instances will happily start a p4d for you at four in the afternoon; what it does not have is an end time. You are back to remembering to stop it, and so is the assistant, which will not be in the conversation when the two hours are up.

Idlefy’s answer is narrow by design. There is no cloud credential anywhere in the chat or in Claude Code’s configuration: Idlefy holds the connection to AWS through the stack, and the assistant signs in to Idlefy. The token it gets is scoped to this one server. On AWS the IAM policy itself limits starting and stopping to tagged instances. Each tool is marked read-only, additive or destructive, so a client knows when to ask first. Every tool call is rate-limited per person, and the costly or destructive ones (creating or deleting a dev box, renting a shared environment, connecting cloud accounts) have hourly caps per person or per organization, so an assistant stuck in a loop runs out of attempts early. And there is no tool that runs a command, opens a shell or reads a file on a machine, because Idlefy itself has no access inside your machines.

I would not call that “safe” in the abstract. An assistant is a new kind of user, and the rules above are the ones the server enforces or tells it to follow; they are on the MCP server page if you want to check them against your own threat model.

Frequently asked questions

Does Idlefy create the EC2 instance? Not on the lease path. A lease starts a stopped instance that an owner already connected and tagged, and ends by stopping it. The one tool that makes a new machine is create_dev_box, for organizations that have switched Dev Boxes on; a dev box’s lifetime ends by deleting it.

Which plan do I need? Any plan, Free included. The MCP server is on every plan; what the assistant may do follows your organization’s plan and your role, as in the web app. Per-plan limits are on the pricing page.

Does Claude Code see my AWS keys? No. The AWS side is an IAM role from the CloudFormation stack, with no static keys anywhere, and Claude Code’s side is an OAuth sign-in to Idlefy in your browser. The assistant never handles a password, a cloud credential or an API key.

Can Claude stop a machine I am using? Not on its own. An assistant acting for an owner, or for a team lead within their team, can end a session, and the server tells it to ask that person first. A member’s assistant cannot end a colleague’s lease, and no assistant stops, releases or deletes anything on its own initiative.

Does this work with Cursor or the Claude desktop app? Yes, against the same address. Cursor takes a few lines in ~/.cursor/mcp.json; Claude adds it as a custom connector. Both steps are on the MCP server page.

Disclosure

I’m the founder of Idlefy, so this is a walkthrough of our own product. Tool names and the assistant rules are taken from the documentation the MCP server serves to assistants; the lease lifecycle matches the how it works page. The transcript is a paraphrase, not a capture of any client’s screen.


Related reading: Dev VMs instead of laptops on running a remote team on leased AWS VMs, and How to audit idle VMs in AWS and GCP if you want to measure what unleased machines cost you first. The RSS feed has more posts in this thread.