Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

fix(swarm): trust the folder the desktop's New Swarm makes for its PM, so the PM is not stuck at Claude Code's trust question

bitcoinbuilder69ac68f69d01
diff --git a/cli/src/core/agents/create.spec.ts b/cli/src/core/agents/create.spec.ts
index 115f510ff..1aa5d48e2 100644
--- a/cli/src/core/agents/create.spec.ts
+++ b/cli/src/core/agents/create.spec.ts
@@ -24,12 +24,14 @@ import { opencodeMajorVersion } from '../../engines/launchControl.js'
import { installOpencodePlugin } from '../../engines/nativeHooks.js'
import type { NativeLaunch } from '../../engines/nativeLaunch.js'
import { projectsRoot } from '../../lib/projectFolder.js'
+import { harnessMadeWorktree } from '../../lib/gitProject.js'
import { NativeFiles } from '../../engines/kit/nativeFiles.js'
import { agentLaunchArgs } from '../../lib/agentAttribution.js'
import { WindowsBatchLaunchRefused } from '../../lib/windows/launch.js'
import { swarmGitHubLaunch } from '../../lib/swarmGitHub.js'
import { SWARM_LAUNCH } from '../../superTabs/inCore/launch.js'
+vi.mock('../../lib/gitProject.js', async (real) => ({ ...await real<object>(), harnessMadeWorktree: vi.fn(async () => false) }))
vi.mock('../../lib/projectFolder.js', async real => {
const actual = await real<typeof import('../../lib/projectFolder.js')>()
return { ...actual, projectsRoot: vi.fn(actual.projectsRoot) }
@@ -353,6 +355,37 @@ describe('creating an agent', () => {
if (expected) expect(preTrustCodexProject).toHaveBeenCalledWith(cwd, mode === 'legacy' ? null : '/fixture/selected')
})
+ // 2026-10-30: a Cmd+S Swarm's PM, in a clone or worktree the desktop made and sent as a plain cwd, sat at Claude Code's
+ // trust question, which no Swarm view shows.
+ it('trusts a local Claude Swarm agent in full mode in a clone in the projects root or a worktree Harness made', async () => {
+ vi.mocked(projectsRoot).mockReturnValue(root)
+ try {
+ const clone = folder(), plain = folder(['README.md']), worktree = join(folder(), 'worktree')
+ mkdirSync(join(clone, '.git'))
+ mkdirSync(worktree)
+ vi.mocked(harnessMadeWorktree).mockImplementation(async path => path === worktree)
+ const authority = { id: 'fixture', label: 'harness-claude-fixture', current: () => true, hold: () => {} }
+ const prepare = (over: Record<string, unknown>, local = true) =>
+ setup().create.prepare(request({ swarmRole: 'lead', permissionMode: 'full', bypassPermission: true, ...over }), authority, { local })
+ expect((await prepare({ cwd: clone })).ok).toBe(true)
+ expect(preTrustClaudeProject).toHaveBeenCalledWith(clone)
+ await prepare({ cwd: worktree })
+ expect(preTrustClaudeProject).toHaveBeenLastCalledWith(worktree)
+ expect(harnessMadeWorktree).toHaveBeenCalledWith(worktree, root)
+ // Not the person's own folder, not relayed, not outside a Swarm or full mode, not for Codex.
+ await prepare({ cwd: plain })
+ await prepare({ cwd: clone }, false)
+ await prepare({ cwd: clone, swarmRole: null })
+ await prepare({ cwd: clone, permissionMode: 'auto', bypassPermission: false })
+ await prepare({ cwd: clone, engine: 'codex' })
+ expect(preTrustClaudeProject).toHaveBeenCalledTimes(2)
+ expect(preTrustCodexProject).not.toHaveBeenCalled()
+ } finally {
+ vi.mocked(projectsRoot).mockReset()
+ vi.mocked(harnessMadeWorktree).mockReset().mockResolvedValue(false)
+ }
+ })
+
it.each(['folder inspection', 'tmux capabilities', 'config publication'] as const)('holds a create revoked during %s before launch side effects', async stage => {
let current = true
vi.mocked(installedDsh).mockReturnValue(installed() as never)
diff --git a/cli/src/core/agents/create.ts b/cli/src/core/agents/create.ts
index decf2d90e..beb88b052 100644
--- a/cli/src/core/agents/create.ts
+++ b/cli/src/core/agents/create.ts
@@ -8,7 +8,7 @@ import type { NativeLaunch, NativeLaunchResult, NativeLaunchSource } from '../..
* Moved verbatim out of `runForeground` (the core boundary, step 11: docs/design/2026-10-03-harnessd.md).
*/
import { realpathSync, statSync } from 'node:fs'
-import { readdir } from 'node:fs/promises'
+import { readdir, stat } from 'node:fs/promises'
import { dirname, join } from 'node:path'
import type { BackendSocket } from '../../backendSocket.js'
import type { ModelsPort, SwarmLaunch } from '../api.js'
@@ -42,6 +42,7 @@ import { nativeHookLocations } from '../../engines/kit/nativeLocations.js'
import { engineHooks } from '../../engines/hooks.js'
import { acceptFullMode, folderTrust } from '../../engines/launchPrep.js'
import { projectsRoot } from '../../lib/projectFolder.js'
+import { harnessMadeWorktree } from '../../lib/gitProject.js'
import { NativeFiles } from '../../engines/kit/nativeFiles.js'
import type { registry, RegisteredSession } from '../../lib/registry.js'
import type { TerminalBackend } from '../../lib/terminalBackend.js'
@@ -103,6 +104,13 @@ export interface CreateAgentDeps {
swarmLaunch?: SwarmLaunch
}
+/** A Git checkout directly in the projects root (a clone the desktop made there), or a worktree Harness made. */
+async function swarmFolder(cwd: string): Promise<boolean> {
+ const root = projectsRoot()
+ if (dirname(cwd) === root) return stat(join(cwd, '.git')).then(info => info.isDirectory(), () => false)
+ return harnessMadeWorktree(cwd, root)
+}
+
export function createAgentCreator({
native: inspectNative, publishConfig, createBackend: initialBackend, recoverBackend, noBackendCode = 'TMUX_UNAVAILABLE', registry, externalResume, watchNewPane, announceSession, attachDsh,
prepareApiTools, hookPort, hooksDisabled, installOpencodePlugin, gridLaunchMachine, buildGridLaunch, terminalHintMachineName, blocksFolder,
@@ -133,6 +141,15 @@ export function createAgentCreator({
// preparation writes, but grant trust only after its dependencies are ready.
const trustEmptyProject = context?.local === true && !dsh && dirname(cwd) === projectsRoot()
&& await readdir(cwd).then(names => names.length === 0, () => false)
+ // A Swarm agent's folder has content: the desktop's New Swarm clones a GitHub project into the projects root, or makes
+ // a worktree of a local repository, itself, and sends the folder as a plain cwd. 2026-10-30: a Cmd+S Swarm's PM sat
+ // at Claude Code's "do you trust this folder?", which no Swarm view shows; it read Idle and every message to it was
+ // withheld. The person chose that repository and full mode for the Swarm in this window, so a Claude Code Swarm agent
+ // in full mode is trusted in a Git checkout directly in the projects root or a worktree Harness made, read from disk.
+ // Never from a relayed request, which could name any repository here. Codex's trust also sets defaults for the
+ // person's own sessions in that folder, so it stays theirs to give.
+ const trustSwarmFolder = !trustEmptyProject && context?.local === true && !dsh && engine === 'claude' && !!input.swarmRole
+ && permissionMode === 'full' && await swarmFolder(cwd)
if (!authority.current()) return stale()
// A harness can pin its permission mode (`dshPinnedPermissionMode`): the Grid harness starts model
// servers, which Codex's sandbox would start without a GPU. Pinned before anything reads the mode,
@@ -304,14 +321,14 @@ export function createAgentCreator({
try { acceptFullMode(engine, native ? { ...native.environment, ...gridLaunch?.env, ...dshEnv } : undefined) }
catch (error) { console.warn(`[agent] full mode acceptance · ${error instanceof Error ? error.message : error}`) }
}
- if (trustEmptyProject) {
+ if (trustEmptyProject || trustSwarmFolder) {
try {
// A clone or user edit can arrive while dependencies are being prepared.
- // Trust only the same physical workspace, still empty at the write boundary.
+ // Trust only the same physical workspace, still empty at the write boundary (a Swarm agent's, still the same).
const files = new NativeFiles()
const empty = files.entries(cwd).length === 0
if (!current()) return stale()
- if (empty && workspaceIdentity() === originalWorkspace) {
+ if ((empty || trustSwarmFolder) && workspaceIdentity() === originalWorkspace) {
files.verify()
const environment = native ? { ...native.environment, ...gridLaunch?.env, ...dshEnv } : undefined
const profile = engine === 'codex' && environment ? nativeHookLocations(environment).CODEX_HOME : codexHome
diff --git a/cli/src/lib/gitProject.spec.ts b/cli/src/lib/gitProject.spec.ts
index 1da23d383..dd8eada7b 100644
--- a/cli/src/lib/gitProject.spec.ts
+++ b/cli/src/lib/gitProject.spec.ts
@@ -7,7 +7,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { encryptDownFrame, encryptRpcResult } from './e2ee/applicationFrames.js'
import { placeholderBranch, sessionBranchNames, worktreeFolderName } from './agentNames.js'
import { nameBranchAfterSession } from './branchNaming.js'
-import { fetchDefaultBranch, prepareGitProject, readGitProject, validGitPath } from './gitProject.js'
+import { fetchDefaultBranch, harnessMadeWorktree, prepareGitProject, readGitProject, validGitPath } from './gitProject.js'
import { parseProjectFolder, prepareProjectFolder } from './projectFolder.js'
import { engineSessionTitle, namingTitle } from './sessionTitle.js'
@@ -47,6 +47,19 @@ describe('launch Git preparation', { timeout: 30_000 }, () => {
const worktrees = () => join(root, 'harnesses', 'worktrees', 'project with spaces')
const current = async (path: string) => (await exec('git', ['-C', path, 'branch', '--show-current'])).stdout.trim()
+ // 2026-10-30: the desktop's New Swarm makes its PM's worktree itself; the daemon trusts it for Claude Code only on this.
+ it('knows a worktree Harness made from the person\'s own checkout and worktrees', async () => {
+ const harnesses = join(root, 'harnesses')
+ const made = await prepareGitProject(repo, { root: harnesses, worktree: true, branchName: 'tidy-badger' })
+ expect(await harnessMadeWorktree(made, harnesses)).toBe(true)
+ const own = join(harnesses, 'worktrees', 'own')
+ await git('worktree', 'add', '-b', 'mine', own)
+ expect(await harnessMadeWorktree(own, harnesses)).toBe(false)
+ expect(await harnessMadeWorktree(repo, harnesses)).toBe(false)
+ expect(await harnessMadeWorktree(join(harnesses, 'worktrees'), harnesses)).toBe(false)
+ expect(await harnessMadeWorktree(join(root, 'missing'), harnesses)).toBe(false)
+ })
+
it('encrypts Git metadata requests and replies', () => {
expect(encryptDownFrame('git_project_info')).toBe(true)
expect(encryptRpcResult('git_project_info_result')).toBe(true)
diff --git a/cli/src/lib/gitProject.ts b/cli/src/lib/gitProject.ts
index 574d654aa..75cc90df2 100644
--- a/cli/src/lib/gitProject.ts
+++ b/cli/src/lib/gitProject.ts
@@ -1,7 +1,7 @@
import { execFile, spawn } from 'node:child_process'
import { cp, lstat, mkdir, readdir, readFile, realpath, rm, stat, writeFile } from 'node:fs/promises'
import { homedir } from 'node:os'
-import { basename, dirname, isAbsolute, join, normalize } from 'node:path'
+import { basename, dirname, isAbsolute, join, normalize, sep } from 'node:path'
import { promisify } from 'node:util'
import { placeholderBranch, plausibleBranchName, worktreeFolderName } from './agentNames.js'
import { redactSecretsInText } from './logBundle.js'
@@ -56,6 +56,17 @@ function parseWorktrees(output: string): Worktree[] {
}]
})
}
+/** Whether `path` is a worktree Harness made in `root`'s worktrees folder: a linked worktree there whose branch carries
+ * Harness's `branch.<name>.harness` mark. A person's own checkout or worktree, anywhere, is not. */
+export async function harnessMadeWorktree(path: string, root: string): Promise<boolean> {
+ try {
+ const [here, home] = await Promise.all([realpath(path), realpath(join(root, 'worktrees'))])
+ if (dirname(here) === here || !here.startsWith(`${home}${sep}`) || !(await lstat(join(here, '.git'))).isFile()) return false
+ const branch = (await git(here, ['branch', '--show-current'])).trim()
+ return !!branch && (await git(here, ['config', '--get', `branch.${branch}.${HARNESS_BRANCH_KEY}`])).trim() !== ''
+ } catch { return false }
+}
+
/** `branch.<name>.harness` in the repository's config marks a branch Harness made: `placeholder` while
* its name waits for the session's, `created` once it has one or was named at Start. */
export const HARNESS_BRANCH_KEY = 'harness'