The problem
An agent running your CLI starts doing something wrong. Maybe the market tanked and your trading bot is still buying. Maybe a deploy script is pushing to production when it shouldn't. You need to stop everything. Now.
The killswitch block is a binary safety gate. If a file exists at
~/.yourapp/KILLSWITCH, every write operation refuses to execute. Remove
the file, operations resume. One touch command stops the world.
Quickstart
import { assertKillswitchOff, turnKillswitchOn } from "@/cli/safety/killswitch";
const APP_HOME = join(homedir(), ".myapp");
program.command("order").action(async (opts) => {
assertKillswitchOff(APP_HOME);
await placeOrder(opts);
});
program.command("stop").action(() => {
turnKillswitchOn(APP_HOME, "manual emergency stop");
console.log("All writes blocked.");
});How it works
touch ~/.myapp/KILLSWITCH # stop everything
cat ~/.myapp/KILLSWITCH # see reason + timestamp
rm ~/.myapp/KILLSWITCH # resumeOne file. One existsSync call. No database. No network. No race conditions.
API
isKillswitchOn(appHome): boolean // fast, never throws
getKillswitchState(appHome): KillswitchState // includes reason + timestamp
turnKillswitchOn(appHome, reason?): void // idempotent
turnKillswitchOff(appHome): void // idempotent
assertKillswitchOff(appHome): void // throws if activeWhy file-based
- Atomic: file exists or it doesn't. No partial states.
- Cross-process: any terminal, any user, any script can create or remove it.
- Debuggable:
catthe file to see why and when. - Offline: no network, no database.
- Fast:
existsSyncis < 1ms.
The safety stack
killswitch is the simplest piece of cligentic's safety layer. For CLIs
that need more granularity, v0.1 will add trust-ladder, approvals,
intent-token, and safety-middleware.
The killswitch is always checked first. If it's on, nothing else runs.