Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions bin/lib/driver-owner.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ export function findClaudeAncestorPid() {

// ── Caller identity ─────────────────────────────────────────────
export function resolveCallerIdentity() {
// Kill switch: OPC_DISABLE_OWNERSHIP=1 → pretend caller has no Claude ancestor
// (legacy behavior). Use for test harnesses, batch scripts, and hosts where
// `ps` walks the parent chain to an unrelated Claude process (race / multi-
// session hosts). checkOwnership() also short-circuits on the same env var.
if (process.env.OPC_DISABLE_OWNERSHIP === "1") {
return { claude_pid: null, claude_started_at: null, host: hostname() };
}
const claude_pid = findClaudeAncestorPid();
return {
claude_pid,
Expand Down Expand Up @@ -165,6 +172,13 @@ export function makeOwner(caller, token = generateOwnerToken()) {
export function checkOwnership(state, caller, opts = {}) {
const owner = state && state._owner;

// Kill switch: OPC_DISABLE_OWNERSHIP=1 → legacy behavior (allow all). Use for
// test harnesses, batch scripts, and environments where `ps` walks the parent
// chain to a different, unrelated Claude process (race / multi-session hosts).
if (process.env.OPC_DISABLE_OWNERSHIP === "1") {
return { decision: "OWNER", reason: "ownership check disabled via OPC_DISABLE_OWNERSHIP=1" };
}

// Legacy loop (pre-ownership) — no stamp to enforce.
if (!owner || owner.claude_pid == null) {
return { decision: "OWNER", reason: "no ownership stamp — legacy loop" };
Expand Down