
Rentctl
io.github.Michael-Drake由 GitHub 账号 Michael-Drake 发布v1.2.0更新于 Oct 24, 2026
Leased dev environments — every server dies when its AI session ends.
概览
Rentctl 为 AI 编程会话租用一次性开发环境,让助手启动、续租、列出和停止本地开发服务器,并由代码强制执行清理。
- 可以做什么
- 为已登记项目启动或续租开发环境,返回 URL、端口和租约到期时间,可指定租约时长和停止等待时间(env_up、env_down)。停止环境,默认只释放当前会话的占用,也可强制为所有会话停止。列出本机环境及其状态、健康状况和共享占用,并核对清理已过期或已失效的租约。报告非预期的终止,使其与对应事件记录匹配。
- 适用场景
- 当 AI 编程会话需要运行项目的开发服务器,并希望该服务器在会话结束、租约到期或你主动要求时可靠退出,而不是滞留在被遗忘的端口上时使用。适用于已登记项目的开发机,不适用于对外提供服务的生产主机。
- 运行要求
- 以 uvx 运行的本地进程(也可用 uv tool、pipx 或 pip 安装);需要 Python 3.12+;仅支持 macOS 和 Linux,不支持 Windows。每个项目需在仓库根目录有 rentctl.toml,并通过 rent init 登记,登记时会展示命令并请求批准。会话结束自动清理需要客户端插件或 rent init 安装的钩子,且 rent 命令行需在 PATH 中。
安装
在 SourceWeft 中
- 打开 控制台中的 Rentctl,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
rentctl
A dev server should never outlive the work that needed it.
rentctl rents dev environments to your AI coding sessions. Every environment is a
lease: it dies when the session ends, when the lease expires, or when you say so —
whichever comes first. Cleanup is owned by code, not by an agent remembering to clean up.
Ships as both a CLI (rent) and an MCP server, so an agent can start and stop
environments through tools instead of shelling out to a raw npm run dev it will forget
about.
Why
An AI coding session starts a dev server. Then the session ends — crashes, is closed, or just moves on — and the server keeps running. By Friday there are six of them, three are on ports you've forgotten, and one is quietly serving stale code that makes a bug look unreproducible.
Telling the agent to clean up doesn't fix this, because the failure mode is the agent
not doing what it was told. rentctl makes the cleanup structural: the environment has an
expiry, and something other than the agent enforces it.
Install
Requires Python 3.12+. macOS and Linux. There is no Windows support and no Windows claim — POSIX sessions are the safety-critical mechanism here, and they have no tested Windows equivalent yet.
Upgrading from 1.0.x? Drain first. Run rent down --all in each project before you
upgrade, then restart your agent sessions so their MCP servers load the new version.
Skipping it is safe but degraded: a 1.0.x environment keeps working under 1.1 — rent up renews it, and rent down and rent sweep stop it by its whole session — but a
1.0.x watchdog still running from before the upgrade enforces its expiry with the old
code, which can miss a child that outlived its shell.
First run
A framework-free server, so nothing but Python is involved. In a scratch repo:
init shows you exactly what it will run and waits for an explicit yes:
Your block will differ — blocks are drawn from 5100 upward, lowest free first. Then:
(Output trimmed where marked ….) That last step is the whole product: in an enrolled
Claude Code or Gemini CLI session you never type rent down — the session ending does.
The hook doesn't wait for the server to die; it asks, and the environment's supervisor
finishes the job (see How cleanup actually happens).
rent down hello, typed by hand, waits and answers "stopped": true.
rent events --summary afterwards shows the teardown and which cleanup layer did it.
If something doesn't behave, see Troubleshooting.
Enroll a project
A project describes itself in a rentctl.toml at its repo root (a devctl.toml
left over from before the rename is still read, so nothing needs renaming to keep
working):
Then, from the repo:
init shows you the exact command it will run, asks you to approve it, claims a block of
ports for the project, registers the MCP server, installs the cleanup hooks (unless the
Claude Code plugin already supplies them), and adds a short rule to CLAUDE.md /
GEMINI.md telling agents to start servers through rentctl rather than by hand. Nobody
else has to edit anything.
There is no port field. Ports are drawn when a server starts, not written down in a tracked file — so two checkouts of the same repo get different ports instead of fighting, and a config file can't hand out a number the allocator never heard of. Each project owns a contiguous block of 10 ports.
Use
report-kill exists because rentctl cannot tell, on its own, whether a teardown
was unwanted — a kill you asked for and a kill you regret look identical from the
inside. The report lands in the same append-only log as everything else and is
matched to the teardown it disputes, so an unwanted kill becomes a fact on the
record rather than an anecdote.
Leases default to 120 minutes and are capped at 480. rent up on a live lease
renews it rather than starting a second server.
Which clients get automatic cleanup
"Expiry and sweep only" still guarantees the server dies — just at the end of its lease (120 minutes by default), not when you close the window.
Plugin-only installs need the CLI too. The plugin (Claude Code or Codex) calls the rent and
rent-mcp you installed with uv tool install rentctl; it does not bundle them, and it
deliberately does not fetch its own copy — a second, different rentctl acting on the same
leases is worse than none. Without rent on PATH, session-end cleanup is off: every
session then starts with a warning saying so and naming the install command. Install the
package first, then run rent doctor, which reports whether each project's hooks come
from the plugin, from settings.local.json, or from both.
From the MCP Registry, a client runs uvx rentctl@<version>: the rentctl
executable is the MCP server, the same as rent-mcp (typed in a terminal it waits for a
client on stdin). That gives you the tools with expiry-and-sweep cleanup only — the
hooks come from the plugin or rent init. rent --version says which version you are
running.
How cleanup actually happens
Every environment has its own supervisor: a small rentctl process that starts your command inside a POSIX session it owns and stays until that whole session — the command, its children, and anything they spawned — has been checked and found empty. The lease is written before the command starts, so there is no moment when something is running that rentctl has no record of.
Every stop, whatever asked for it, is the same: SIGTERM to every process in the
session, SIGTERM to anything forked while it shuts down, SIGKILL to each process
still there after 10 s, then a final scan. A child that ignores SIGTERM, or that
outlived the shell that launched it, is stopped with the rest.
Four independent layers decide when, so no single failure leaves an orphan:
- You ask —
rent down. - The session ends — a
SessionEndhook releases that session's claim on everything leased to that directory. The server stops if no other session still holds a claim. - The lease expires — the supervisor starts the stop within about a second of the lease running out, even if the session died without running its hook.
- The next sweep —
rent sweep(which the hooks also run at session start) andrent lsclean up what the first three missed, including an environment whose supervisor was killed.
What rent down tells you is what the lease says, in one of three shapes:
"stopped": true— the session was scanned empty and the lease removed."stopped": false, "state": "cleanup_incomplete", "survivors": [...]— something could not be stopped (a child that switched user withsudo, say). The lease is kept, so the survivors stay named and the port stays out of the draw; the supervisor keeps retrying (5 s, 15 s, 60 s, then every minute),rent downretries at once, andrent uprefuses withCLEANUP_INCOMPLETEuntil it clears."stopped": null, "pending": true— the stop was accepted and is still running;rent lsshows how it ended. This is"ok": true: the supervisor finishes regardless.
rent down waits up to 15 s for the first two (--wait SECONDS; --wait 0 returns
at once). The MCP tool env_down takes the same wait as wait_s — 15 s by default,
60 s at most.
Session end returns fast; cleanup finishes in the background. Claude Code gives a
plugin's SessionEnd hook about 1.5 s. So the hook's rent down --all --reason session-end doesn't wait: it records a stop for every lease that no other session still
holds, wakes each supervisor, and returns pending. The supervisors don't need the session to finish. A lease with no
living supervisor is handed to a detached recovery process rather than stopped halfway.
A crashed session is cleaned up by layers 3 and 4, not 2. If the session dies
without firing its hook, its server keeps running until the lease expires — up to the
full lease length. Shorter leases (rent up myapp --lease-minutes 30) shorten that
window. A sweep does not stop a live, unexpired lease; it cannot tell a crashed session
from one that is still working.
If a supervisor is killed, recovery waits for the next command. The server keeps
serving. The next rent ls, sweep, up or down notices, marks the lease
unsupervised, and records supervisor_lost; it is not killed early. At its expiry the
next of those commands stops it, and rent down stops it now. Nothing notices at the
moment the supervisor dies, because nothing else is running to notice.
There is no daemon. There is one supervisor per live environment, and it exits once its environment is verified gone. State lives on disk and the OS process table is the source of truth, so there is no background service to babysit, and nothing to resurrect after a reboot.
What supervision covers, per platform
macOS. Every process that stays in the environment's session is found and stopped:
orphans of a launch shell that exited, processes that ignore SIGTERM, processes that
move into their own process group, children forked during shutdown. A process that calls
setsid() — which is what daemonizing (double-fork plus setsid) does — leaves the
session and is outside supervision. rentctl never signals it; if it holds the lease's
port, the teardown reports it. When a command daemonizes during startup — its own
session empties while a process outside it answers the port — rent up fails with
UNSUPERVISABLE instead of reporting a start it cannot own. Run such servers in the
foreground.
Linux. Each supervisor also makes itself a child subreaper
(prctl(PR_SET_CHILD_SUBREAPER), no privileges needed), so orphaned descendants are
reparented to it instead of to init. Every descendant of your command is captured,
including a daemon that double-forks and calls setsid(). Signals to single processes
go through a pidfd where the kernel has them. What still escapes is work that is not
your command's descendant — handed to another manager such as systemd-run, a
container runtime, an already-running tmux server, or at/cron — and the orphaned
children of a process placed in another PID namespace with setns(2) (which needs
CAP_SYS_ADMIN over that namespace): they go to that namespace's init. The capture also
ends if the supervisor itself is killed. Where the subreaper is refused (some
restricted containers), Linux gets the macOS guarantee.
rent doctor reports which one is in effect: supervision: session or
supervision: session+subreaper. Neither is a sandbox — a command that sets out to
escape supervision can.
Several sessions in one checkout share one server
A lease belongs to a (project, directory) pair, so two agent sessions in the same
checkout share one server and one port. Each session that runs rent up holds its own
expiring claim on it, and the lease lasts as long as its latest claim. A session's
up renews only its own claim. rent ls and the up result list the claims, and
shared_with names the other sessions.
When a session ends, its SessionEnd hook releases that session's claim. The server
stops only when no other session still holds one. A session that never leased the
server changes nothing when it ends. The MCP tool env_down also releases by default:
it answers "stopped": false with held_by while others hold the server, and
force: true stops it for everyone. rent down typed by a person always stops, and
lists any other sessions' claims it overrode in overrode_claims.
This depends on knowing which session is asking. Claude Code hooks send the session id
on stdin, and rentctl also reads DEVCTL_SESSION_ID, CLAUDE_CODE_SESSION_ID and
GEMINI_SESSION_ID. rent doctor says which one it found. A caller with none of them is
unknown, and every unknown caller shares one claim. A release can never remove
another session's claim, so an unidentified session end leaves the server running until
it expires. It never stops a server another session is using.
Separate git worktrees still give each session its own server, port and lease.
Where rentctl has to run: somewhere it can see processes
Supervision works by reading the process table: every process in a workload's session is found by its session id, and a stop is only reported as verified once that session is provably empty. So rentctl must run where it can list processes and read their session ids.
- Works: the MCP server launched by your agent host (Claude Code, for example), and
renttyped in an ordinary terminal. - Does not work:
rentinvoked from inside an agent's command sandbox that blocks process inspection. Codex's macOS sandbox is one (Operation not permitted (originated from sysctl())).
Where inspection is denied, rent up refuses with UNSUPPORTED_ENVIRONMENT and starts
nothing. If inspection is lost after a server started, rentctl treats ownership as
unknown: it keeps the lease, signals nothing, and never reports cleanup as verified.
The record shows cleanup_incomplete with identity_ambiguous until a later attempt
can see the session again. Denied inspection never reads as "no processes". The fix is
to run rentctl from the host side, not to grant the sandbox wider privileges.
It won't kill things it doesn't own
Every lease records its supervisor's PID and start time, and the supervisor's PID is
the environment's session id (a lease from 1.0.x uses its server's instead). A process is the environment's only if it is in that
session (or, on Linux, descends from the supervisor), and each one's identity is
re-checked immediately before it is signalled. If the session's PID has been recycled
onto some unrelated process, nothing under it can be proved ours: the lease is kept,
marked identity_ambiguous, and nothing is signalled — a stale lease can't get your
database killed.
A listener inside an enrolled project's port block with no lease behind it is a squatter. What happens to it depends on the machine's enforcement mode:
- advisory (the default, and the only mode any command sets) —
rent uproutes around it, andrent ls/rent sweepreport it. It is never signalled. - strict —
rent sweepsends each squatterSIGTERM, and reports what it killed. Since the session-start hook runsrent sweep, under strict that happens at every session start. Strict is set by theenforcementfield in rentctl's machine-local registry; nothing turns it on for you. See Development machines only before you do.
When it genuinely cannot tell whether a port is in use — no usable probe on the host — it says so, rather than reporting the port as free. "No squatters found" means something looked.
What it can see is limited to what you can see. The port probe (lsof, or psutil
on Linux) runs as your user, and an unprivileged probe can miss sockets owned by other
users. So "free" means free as far as this user can see. A real collision still surfaces:
the server's own bind() fails, and rent up reports the failed start (with the log
tail) instead of writing a lease.
Security: what you are trusting
Read this part. rentctl runs a command out of a config file in your repo.
That is arbitrary code execution, and no tool can make it not be. If you can run
npm run dev, you can run anything. What rentctl guarantees is narrower and more
useful: it adds no silent path to it.
- The command from
rentctl.tomlis shown to you and approved once, explicitly, atrent init. - On approval it is copied into
rentctl's own registry along with a hash of the execution-determining fields:runner,cmd,cwdandport_env. - If the repo's
rentctl.tomllater changes any of them, the next start stops (CMD_CHANGED) and shows you a diff of approved-versus-current. It does not run the new command. You re-approve withrent syncor you don't.
The hash deliberately covers only the fields that determine execution, not the whole file — hashing everything trains you to click through re-approvals for comment edits, which defeats the point.
Approval pins the command, not the code it runs. npm run dev is the same string
whatever package.json says dev means. An edit to a package.json script, a Makefile,
or the application code itself changes what actually executes without tripping
CMD_CHANGED. The pin stops a changed rentctl.toml from quietly running something new;
it is not a review of the repo. Treat pulling someone else's branch the way you already
would before running its dev server by hand.
Consequences worth being explicit about:
git pullcannot change the approved command. It can change the file, and it can change the code that command runs; it cannot change which commandrentctlruns.- A repo cannot walk
rentctlout of its own directory.cwdis repo-relative and rejected if it is absolute, contains.., or symlinks outside the repo. Project names are filename-safe or refused. - Non-interactive enrollment is explicit. CI passes
--trust-repo, which is recorded as trust-on-first-use rather than being the quiet default. rentctlonly manages what you enrolled. Test-framework servers (pytest fixtures, Playwright'swebServer) own their own lifecycle and use ephemeral ports;rentctlnever touches them.
To report a vulnerability, see SECURITY.md.
Development machines only
Install this on machines where dev servers are meant to be disposable. Not on a host running anything you would mind losing.
A default install is safe: enforcement is advisory, and rentctl only scans the
port blocks of projects you enrolled. Nothing else on the machine is examined and nothing
unenrolled is ever signalled.
But rentctl's whole job is killing processes that outlive a session, and strict
enforcement exists to make that unavoidable. A tool built to reap servers you forgot
about is the wrong tool to arm on a host serving traffic — there, the servers outliving
their session are supposed to. Keep it on development machines.
Troubleshooting
Agent-client problems (missing tools, hooks, approval, cleanup that did not happen): docs/troubleshooting.md. Which clients and surfaces were tested, and how: docs/integrations.md.
rent doctorchecks that therentshim runs, the registry loads, and each enrolled project's hooks are wired, and says which supervision level this host gets and where it found this session's id (session-identity). Ifrentitself is missing, the same check runs aspython3 -m rentctl.doctor.- Server logs are in
~/.local/state/devctl/logs/<project>-<timestamp>.log(under$XDG_STATE_HOMEif set). A failedrent upincludes the log's tail in its output. - What happened, and why:
rent eventslists every start and teardown with the layer that did it; the raw log is~/.local/state/devctl/events.jsonl. A teardown'sdownevent says whether the stop was verified and whether it neededSIGKILL("escalated": true).stop_requestedmeans a stop was asked for (for example by the session-end hook) and is not itself a teardown. Neither isclaim_released: a session let go of a server that others still hold. rent lsshows each lease'sstateand whether its supervisor is alive:stoppingor"pending": true— a stop is under way; look again in a few seconds.unsupervised— its supervisor died. The server is still yours and still serving; it is stopped at expiry by the nextls/sweep/up/down, or now byrent down.rent upwill not renew it. (A lease started by 1.0.x also readsunsupervised, with"legacy": true;rent updoes renew that one.)cleanup_incompletewithsurvivors— those PIDs would not die. Find out why (a different user? stuck in the kernel?) before reusing the port;rent downretries.
UNSUPERVISABLEfromrent up— the command daemonized, so its server left the session rentctl supervises. Run it in the foreground. The stray server is left alone; stop it yourself.- The supervisor notes what it did in the server's log, on lines prefixed
[rentctl supervisor <pid>]. - The registry of enrolled projects and approved commands is
~/.config/devctl/registry.json. It is rentctl's own record — change it withrent init/rent sync, not by hand.
(The directories say devctl, the project's former name. That is deliberate — renaming
them would orphan every live lease.)
Known gaps
Stated plainly, because a tool making safety claims should be honest about its edges:
- The approval pin covers the command, not the code — see Security.
- Sessions in one checkout share one server — see above. A session that rentctl cannot identify releases nothing when it ends, so its server lives until the lease expires.
- Crash cleanup waits for expiry — a session that dies without its hook leaves its server up until the lease runs out.
- Recovery waits for the next command — if a supervisor is killed, nothing acts
until the next
rent ls/sweep/up/down. - Daemonizing commands are not supervised on macOS, and on Linux work handed to another process manager is not — see What supervision covers.
- Only Claude Code, Codex (with its hooks trusted) and Gemini CLI get session-end hooks. Other clients get expiry and sweep. Cloud agent sessions (claude.ai/code cloud, Codex Cloud) are not supported: they cannot reach your machine's processes.
runner = "compose"is designed but not implemented. Asking for it fails with a clear error rather than doing nothing.- The only environment beyond the port is
port_env. Anything else a server needs has to ride insidecmdtoday. - Windows: see Install. Not supported, not claimed.
Contributing
See CONTRIBUTING.md.
A note on the comments in the source
The source cites its own design decisions — ADR-0008, WI-0040, spec §10. Those
refer to this project's design log, which is kept privately; the reasoning around each
citation is written out where it is cited, so nothing is missing if you can't follow the
pointer.
License
Apache License 2.0 — see LICENSE and NOTICE.
Copyright 2026 Michael Drake.
来源:README.md,提交 a64f6a1
工具
0版本历史
4- v1.2.0最新Sep 30, 2026
- v1.1.0Sep 29, 2026
- v1.0.2Sep 29, 2026
- v1.0.1Sep 16, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分