Repository navigation
Description
Problem
When Codev is initialized in a project that already had a Claude Code session running (claude binary already alive somewhere on the machine), the main architect launched by codev adopt (or by Tower's launchInstance on first workspace touch) does not spawn a fresh session — it appears to hijack / attach to an existing, unrelated Claude Code session as its starting point.
Reproduction:
- Open a project directory in VS Code (or any terminal). Do NOT initialize Codev in it.
- In some other context (a different terminal, a different project's session), Claude Code has an active session (persisted state on disk, potentially a running process).
- In the target project, run
codev adopt(or trigger auto-adopt via VS Code opening the folder withcodev.autoStartTower). - Tower's
launchInstancefires, creates the main architect terminal. - Observe: the main architect's opening state is not a fresh session. It picks up prior conversation context / role state from an unrelated Claude Code session, effectively hijacking it.
Impact
- Architect boots in a context inherited from a different project — protocols, mental model, and any prior "you are the main architect for X" instructions bleed in.
- New workspaces don't start clean. The workspace's
codev/state/main.md(per-architect notebook) and porch project state are correctly scoped, but the conversation state inside the Claude terminal is contaminated. - Undermines the trust that "add-architect / adopt → fresh, purpose-scoped architect."
Root cause hypothesis
Two candidate sites in the launch path:
packages/codev/src/agent-farm/servers/tower-instances.ts:392—launchInstance. Spawns the main architect PTY. Investigate whether the launch options passed to shellper / Claude include a--resume,--continue, or session-id argument that reaches for the most-recent Claude session on the machine.packages/codev/src/agent-farm/utils/harness.ts— the Claude harness config. Look forbuildResume/sessionIdbehavior that defaults to "most recent" when no explicit id is provided.
Specifically: Claude Code CLI has a --resume flag that reattaches to the most-recent conversation on the machine by default. If the launch command builds a --resume argument without validating that the session is scoped to this workspace, it'll grab whichever conversation Claude last touched globally.
Note the pattern documented at packages/codev/src/agent-farm/utils/harness.ts:87: "no stored session id yet (codex/gemini omit it → no stale-jsonl crash-loop)." Something equivalent for Claude on fresh workspaces would prevent the hijack.
Fix sketch
Two surgical changes:
-
Detect fresh vs resume-worthy state at launch time. For a workspace that has never registered an architect terminal before, launch Claude WITHOUT
--resume(or with an explicit "new session" invocation). Only resume when there's a scoped architect row inglobal.db.architectswith a persisted session id owned by this workspace. -
Verify session ownership before attach. If a session id is passed, cross-check that the session file's project-scope tag matches this workspace path. Refuse to attach to a session that references a different project directory.
Scope
packages/codev/src/agent-farm/servers/tower-instances.ts(launchInstance, main architect spawn)packages/codev/src/agent-farm/utils/harness.ts(Claude harness resume logic)- Coverage: fresh
codev adoptin a new workspace + concurrent Claude session elsewhere → main architect boots clean
Related
packages/codev/src/agent-farm/utils/harness.ts:87— existing comment about codex/gemini omitting session id "to avoid stale-jsonl crash-loop." Same concern class; different remediation for Claude.- Post-Consolidate state.db tables into global.db (single user-global database) to eliminate the cwd-dependent fragmentation that causes "missing architect state after restart" #1118 architect state lives in the shared user-global
~/.agent-farm/global.db. Any per-workspace hydration check must key onworkspace_path.
Activity
amrmelsayed commentedon Jul 8, 2026
On it! Working on this with the PIR protocol (plan + dev-approval gates before PR).
[PIR #1145] Plan draft
[PIR #1145] Plan revised: drop architect discovery fallback entirely
[PIR #1145] Verify Claude session ownership before any resume
[PIR #1145] Remove architect jsonl-discovery fallback in launchInstance
[PIR #1145] Update tests: ownership verification, fresh-boot regression
[PIR #1145] Thread: implement phase notes
[PIR #1145] Make the cwd scan streaming: semantic, not byte-offset-bound
[PIR #1145] Narrow ownership verification to file existence; drop con…
[PIR #1145] Comment: point at sibling resumption via the reconcile loop
[PIR #1145] Review + retrospective
[PIR #1145] Address consultation: fix lessons merge, plan frontmatter…
[PIR #1145] Thread: review phase notes
Merge pull request #1160 from cluesmith/builder/pir-1145
changelog: codev adopt / main architect no longer hijacks unrelated C…
[PIR #1150] Plan rechecked post-rebase: reuse #1145 ownership-verific…
[PIR #1149] Plan revised: rebase on main, account for merged #1145/#1150
[Bugfix #1224] Fix: skip resume when a live process holds the archite…