Skip to content
8 changes: 6 additions & 2 deletions .agents/skills/harness-adapters/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,13 @@ The shared symptom is a healthy-looking pane with no work in progress, so each a
| Interrupt | single Escape |
| Skill invocation | `/<skill>` (e.g. `/no-mistakes`) |

First launch in a fresh worktree, or first ever on a machine, may show a trust or bypass-permissions confirmation.
The per-folder workspace-trust confirmation ("Is this a project you created or one you trust?") is pre-accepted by `bin/fm-spawn.sh` before every claude launch, so it cannot appear in a successfully launched firstmate-spawned worktree.
[`docs/configuration.md`](../../../docs/configuration.md#harness-support) owns the trust-store location, scope, and fail-closed behavior.
Captured incident evidence showed that `--dangerously-skip-permissions` did not suppress this dialog, but a fresh-directory attempt on Claude Code 2.1.231 did not reproduce it; the pre-accept remains defense in depth against version or account differences.
A separate bypass-permissions mode warning ("WARNING: Claude Code running in Bypass Permissions mode") is a distinct, later dialog that this pre-accept step does not address; see issue #2325 for its two-dialog sequencing and the destructive default on its second option.
First ever launch on a machine may still show its own onboarding confirmation.
After every spawn, peek the pane within about 20 seconds.
If such a dialog is showing, accept it from an active firstmate session using `FM_HOME=<this-firstmate-home> bin/fm-send.sh <window> --key Enter`, or the choice the dialog requires, unless `FM_HOME` is already set to the active firstmate home; verify the brief started processing.
If a dialog is showing, read it before sending any key: accept it from an active firstmate session using `FM_HOME=<this-firstmate-home> bin/fm-send.sh <window> --key Enter`, or the exact choice the dialog requires, unless `FM_HOME` is already set to the active firstmate home; verify the brief started processing.

Claude renders a predicted-next-prompt suggestion as dim/faint text inside an otherwise-empty composer after a turn completes.
A plain `tmux capture-pane` cannot tell that ghost text apart from typed text.
Expand Down
2 changes: 1 addition & 1 deletion bin/fm-bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ missing_tool_diagnostic() {
# fm_backend_required_tools (bin/fm-backend.sh). So a herdr/zellij/cmux home is
# never told tmux is missing, and only orca drops treehouse. A backend value with
# no verified dependency set is reported before the universal checks continue.
COMMON_TOOLS="node git gh no-mistakes gh-axi chrome-devtools-axi lavish-axi tasks-axi quota-axi"
COMMON_TOOLS="node git gh jq no-mistakes gh-axi chrome-devtools-axi lavish-axi tasks-axi quota-axi"
BACKEND=$(fm_backend_name)
BACKEND_VALID=1
if ! BACKEND_TOOLS=$(fm_backend_required_tools "$BACKEND"); then
Expand Down
197 changes: 197 additions & 0 deletions bin/fm-claude-trust-lib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
# shellcheck shell=bash
# Pre-accepts Claude Code's per-folder workspace-trust dialog for a worktree
# before launch, so a claude crewmate/secondmate never hangs on the "Is this
# a project you created or one you trust?" prompt on a brand-new worktree.
# Captured incident evidence showed that --dangerously-skip-permissions did
# not suppress this dialog. A fresh-directory attempt on Claude Code 2.1.231
# did not reproduce it, so this pre-accept is defense in depth against version
# or account differences.
#
# Claude Code persists per-folder trust in <config-dir>/.claude.json under
# projects["<abs-worktree-path>"].hasTrustDialogAccepted (verified against
# real trusted entries in ~/.claude.json, 2026-08-13, Claude Code 2.1.231).
# <config-dir> is $CLAUDE_CONFIG_DIR when set, else $HOME - the same variable
# bin/fm-spawn.sh already forwards onto the claude launch command, so the file
# this writes is the exact file the launched process reads.
#
# Concurrency: multiple crews spawn claude workers in parallel, and every
# running claude process itself reads and rewrites this same file. This
# library serializes firstmate's own writers against each other at a lock path
# the caller acquires with fm_claude_trust_lock_acquire (sourced separately;
# not sourced here to avoid a second copy of that lock owner). A bounded
# compare-and-retry detects a live claude process changing the file during
# composition and retries from its new content. Claude's internal lock is not
# available here, so this shrinks but cannot eliminate the final race window
# between the last identity check and atomic rename. Atomic rename still keeps
# every installed file complete.
#
# Usage: . bin/fm-claude-trust-lib.sh (no FM_* setup required)

# fm_claude_trust_json_path: absolute path to the .claude.json this worktree's
# claude launch will read.
fm_claude_trust_json_path() {
printf '%s/.claude.json\n' "${CLAUDE_CONFIG_DIR:-$HOME}"
}

# fm_claude_trust_lock_path: the lock path callers pass to
# fm_claude_trust_lock_acquire/fm_lock_release around fm_claude_pretrust_worktree.
fm_claude_trust_lock_path() {
printf '%s.fm-spawn-lock\n' "$(fm_claude_trust_json_path)"
}

# fm_claude_trust_ensure_dir: creates the config directory holding .claude.json
# if missing. The caller MUST run this before fm_claude_trust_lock_acquire on the
# trust lock: the lock's own owner-dir machinery resolves its path by `cd`ing
# into the lock's parent directory, so acquiring the lock against a directory
# that does not exist yet loops forever instead of failing - this call is what
# turns a not-yet-onboarded CLAUDE_CONFIG_DIR into a normal first use instead
# of a silent hang.
fm_claude_trust_ensure_dir() {
local dir probe
dir=$(dirname "$(fm_claude_trust_json_path)") || return 1
(umask 077; mkdir -p "$dir") || return 1
probe=$(umask 077; mktemp "$dir/.fm-claude-trust-write-test.XXXXXX") || return 1
rm -f "$probe"
}

fm_claude_trust_lock_acquire() {
local lock=$1 attempts=0
while [ "$attempts" -lt 100 ]; do
if [ -e "$lock" ] && [ ! -d "$lock" ] && [ ! -L "$lock" ]; then
return 1
fi
fm_lock_try_acquire "$lock" && return 0
attempts=$((attempts + 1))
sleep 0.1
done
return 1
}

fm_claude_trust_file_mode() {
stat -c %a "$1" 2>/dev/null || stat -f %Lp "$1" 2>/dev/null
}

fm_claude_trust_file_identity() {
cksum "$1"
}

# fm_claude_pretrust_worktree <abs-worktree-path>: idempotently ensures
# <config-dir>/.claude.json marks <abs-worktree-path> as trusted, creating the
# file or the project entry only when missing. The caller must have already
# run fm_claude_trust_ensure_dir and must hold the lock from
# fm_claude_trust_lock_path for the duration of this call.
# Firstmate writers are serialized by that lock. A bounded content-identity
# compare retries external changes, but cannot coordinate with Claude's
# internal writer across the final identity-check-to-rename window.
#
# Fails loudly (non-zero, message on stderr) instead of silently skipping,
# including when jq is missing or the existing file fails to parse as JSON: a
# silent skip would reintroduce the exact dialog this function exists to
# prevent, and rewriting a file this cannot parse risks losing content a
# structural merge can't see.
fm_claude_pretrust_worktree() {
local wt=$1 json_path tmp status mode identity live_identity attempt=0
[ -n "$wt" ] || { echo "fm-claude-trust: no worktree path given" >&2; return 1; }
command -v jq >/dev/null 2>&1 || {
echo "fm-claude-trust: jq is required to pre-trust '$wt' for claude; install jq" >&2
return 1
}
json_path=$(fm_claude_trust_json_path)
while [ "$attempt" -lt 5 ]; do
attempt=$((attempt + 1))
mode=
if [ -L "$json_path" ]; then
echo "fm-claude-trust: $json_path is a symlink; refusing to replace it" >&2
return 1
fi
tmp=$(umask 077; mktemp "$json_path.fm-spawn-tmp.XXXXXX") || {
echo "fm-claude-trust: failed to create a private temporary file beside $json_path" >&2
return 1
}
if [ -e "$json_path" ]; then
identity=$(fm_claude_trust_file_identity "$json_path") || {
rm -f "$tmp"
echo "fm-claude-trust: could not identify $json_path; refusing to replace it" >&2
return 1
}
if ! jq -e . "$json_path" >/dev/null 2>&1; then
rm -f "$tmp"
echo "fm-claude-trust: $json_path is not valid JSON; refusing to touch it" >&2
return 1
fi
mode=$(fm_claude_trust_file_mode "$json_path") || {
rm -f "$tmp"
echo "fm-claude-trust: could not read permissions from $json_path; refusing to replace it" >&2
return 1
}
jq --arg path "$wt" '
.projects //= {} |
.projects[$path] //= {
"allowedTools": [],
"mcpContextUris": [],
"mcpServers": {},
"enabledMcpjsonServers": [],
"disabledMcpjsonServers": [],
"hasTrustDialogAccepted": false,
"projectOnboardingSeenCount": 0,
"hasClaudeMdExternalIncludesApproved": false,
"hasClaudeMdExternalIncludesWarningShown": false
} |
.projects[$path].hasTrustDialogAccepted = true
' "$json_path" > "$tmp"
else
identity=absent
jq -n --arg path "$wt" '
{"projects": {($path): {
"allowedTools": [],
"mcpContextUris": [],
"mcpServers": {},
"enabledMcpjsonServers": [],
"disabledMcpjsonServers": [],
"hasTrustDialogAccepted": true,
"projectOnboardingSeenCount": 0,
"hasClaudeMdExternalIncludesApproved": false,
"hasClaudeMdExternalIncludesWarningShown": false
}}}
' > "$tmp"
fi
status=$?
if [ "$status" -ne 0 ] || [ ! -s "$tmp" ]; then
rm -f "$tmp"
echo "fm-claude-trust: failed to compose updated $json_path" >&2
return 1
fi
if [ -n "$mode" ] && { ! chmod "$mode" "$tmp" || ! chmod go-rwx "$tmp"; }; then
rm -f "$tmp"
echo "fm-claude-trust: could not preserve private permissions for $json_path" >&2
return 1
fi
if [ "$identity" = absent ]; then
if [ -e "$json_path" ] || [ -L "$json_path" ]; then
rm -f "$tmp"
continue
fi
else
if [ ! -e "$json_path" ] || [ -L "$json_path" ]; then
rm -f "$tmp"
continue
fi
live_identity=$(fm_claude_trust_file_identity "$json_path") || {
rm -f "$tmp"
continue
}
if [ "$live_identity" != "$identity" ]; then
rm -f "$tmp"
continue
fi
fi
if ! mv -f "$tmp" "$json_path"; then
rm -f "$tmp"
echo "fm-claude-trust: failed to install updated $json_path" >&2
return 1
fi
return 0
done
echo "fm-claude-trust: $json_path kept changing during update; refusing to clobber external writes" >&2
return 1
}
40 changes: 40 additions & 0 deletions bin/fm-spawn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ SUB_HOME_MARKER=".fm-secondmate-home"
. "$SCRIPT_DIR/fm-busy-lib.sh"
# shellcheck source=bin/fm-cursor-lib.sh
. "$SCRIPT_DIR/fm-cursor-lib.sh"
# shellcheck source=bin/fm-claude-trust-lib.sh
. "$SCRIPT_DIR/fm-claude-trust-lib.sh"
# shellcheck source=bin/fm-pr-lib.sh
. "$SCRIPT_DIR/fm-pr-lib.sh"
# shellcheck source=bin/fm-trace-context-lib.sh
Expand Down Expand Up @@ -672,6 +674,8 @@ RELAUNCH_REPLACEMENT_STATE=
RELAUNCH_REPLACEMENT_WT=
CONFIG_INHERIT_LOCK=
CONFIG_INHERIT_LOCK_HELD=0
CLAUDE_TRUST_LOCK=
CLAUDE_TRUST_LOCK_HELD=0

parse_orca_worktree_result() {
local raw=$1 rest
Expand Down Expand Up @@ -783,6 +787,10 @@ spawn_abort_cleanup() {
CONFIG_INHERIT_LOCK_HELD=0
fm_lock_release "$CONFIG_INHERIT_LOCK" || true
fi
if [ "$CLAUDE_TRUST_LOCK_HELD" = 1 ]; then
CLAUDE_TRUST_LOCK_HELD=0
fm_lock_release "$CLAUDE_TRUST_LOCK" || true
fi
return "$status"
}
trap spawn_abort_cleanup EXIT
Expand Down Expand Up @@ -2264,6 +2272,38 @@ if [ "$RELAUNCH" -eq 0 ] && [ "$KIND" != secondmate ]; then
freshen_spawn_worktree_base "$WT" || exit 1
fi

# Deterministically pre-accept Claude Code's per-folder workspace-trust dialog

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 security Automatic workspace trust bypass

Every Claude spawn automatically records the resolved worktree as trusted without checking for a captain opt-in, bypassing Claude's workspace-trust decision and allowing newly created or otherwise unreviewed worktree content to launch in a trusted state.

Context Used: If there is a VISION.md file at the root of the re... (source)

# for this worktree before launch (bin/fm-claude-trust-lib.sh), covering both
# a fresh spawn and --relaunch: WT is finalized for every KIND and RELAUNCH
# state by this point. Captured incident evidence showed that
# --dangerously-skip-permissions did not reliably suppress this dialog, so an
# affected first-time worktree path could otherwise hang the worker with an
# empty status log until a supervisor answers it. Scoped to the verified
# claude harness only; every other adapter's trust/bypass handling is
# unrelated and untouched.
if [ "$HARNESS" = claude ]; then
CLAUDE_TRUST_WT=$(real_path_or_raw "$WT")
fm_claude_trust_ensure_dir || {
echo "error: could not create the claude config directory for $ID" >&2
exit 1
}
CLAUDE_TRUST_LOCK=$(fm_claude_trust_lock_path) || {
echo "error: could not resolve the claude trust lock path" >&2
exit 1
}
if ! fm_claude_trust_lock_acquire "$CLAUDE_TRUST_LOCK"; then
echo "error: could not acquire the claude trust lock for $ID" >&2
exit 1
fi
CLAUDE_TRUST_LOCK_HELD=1
if ! fm_claude_pretrust_worktree "$CLAUDE_TRUST_WT"; then
echo "error: could not pre-trust '$CLAUDE_TRUST_WT' for claude; refusing to spawn a worker that would hang on the folder-trust dialog" >&2
exit 1
fi
CLAUDE_TRUST_LOCK_HELD=0
fm_lock_release "$CLAUDE_TRUST_LOCK"
fi

# Per-task temp root: /tmp/fm-<id>/ with Go's build temp nested at gotmp/. Go won't
# create GOTMPDIR, so mkdir before it is used; fm-teardown removes the whole root.
# Nested (not a bare /tmp/fm-<id>/gotmp) so other per-task temp can live alongside
Expand Down
2 changes: 1 addition & 1 deletion bin/fm-test-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ family_for_basename() {
fm-arm-pretool-check.test.sh|fm-ask-user-authority.test.sh|\
fm-brief.test.sh|fm-vendor-auth-probe.test.sh|\
fm-calm-pi-extension.test.sh|fm-cd-pretool-check.test.sh|\
fm-classify-decision-key.test.sh|\
fm-classify-decision-key.test.sh|fm-claude-trust-lib.test.sh|\
fm-composer-ghost.test.sh|fm-composer-lib.test.sh|\
fm-crew-state.test.sh|fm-decision-hold-lifecycle.test.sh|\
fm-documentation-audiences.test.sh|fm-ensure-agents-md.test.sh|fm-grok-harness.test.sh|\
Expand Down
7 changes: 5 additions & 2 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ The full cmux home label also includes a short hash of the resolved `FM_ROOT` pa
## Harness support

claude, codex, opencode, pi, pi-signed, grok, kimi, and cursor are empirically verified for crewmate and secondmate launches; [README requirements](../README.md#requirements) own the set supported for the primary session.
Before every claude crewmate or secondmate launch, including a relaunch, Firstmate records the resolved worktree as trusted in `<CLAUDE_CONFIG_DIR>/.claude.json` when `CLAUDE_CONFIG_DIR` is set or `$HOME/.claude.json` otherwise.
This pre-accept is limited to the exact `claude` adapter and does not cover Claude Code's separate bypass-permissions warning or first-machine onboarding.
The spawn fails closed instead of risking the Claude configuration when the trust store is malformed, symlinked, unwritable, or keeps changing during the bounded update, and it preserves unrelated keys and project entries when the update succeeds.
A cursor secondmate or primary runs the tracked project-scope `.cursor/hooks.json` in its own home and must be launched with `--trust`, or no project hook loads; [`docs/supervision-protocols/cursor.md`](supervision-protocols/cursor.md) owns its supervision protocol.
Cursor delivery confirmation is verified on tmux and Herdr only.
On Zellij, cmux, and Orca a Cursor steer lands, but `fm-send` reports delivery unconfirmed and exits non-zero because their shared submit core does not consult the busy footer; [runtime backend verification](verification/runtime-backends.md#cursor-agent-cli) owns the evidence and transcript-state boundary.
Expand Down Expand Up @@ -293,10 +296,10 @@ Secondmate homes inherit this file from the primary, so a secondmate's own crewm
On session start the first mate detects what its required toolchain is missing or too old and lists each problem with either an exact install command or manual instructions.
It installs automatically supported tools only after you say go; manual-only tools remain for you to install from the printed instructions.
Required tools come in two parts: a universal toolchain every home needs regardless of backend, and a per-backend delta that follows the runtime backend actually resolved for this home.
The universal toolchain is node, git, gh with GitHub auth via `gh auth login`, no-mistakes v1.31.2 or newer, compatible gh-axi, chrome-devtools-axi, compatible lavish-axi, compatible tasks-axi per "Backlog backend" above, and compatible quota-axi.
The universal toolchain is node, git, gh with GitHub auth via `gh auth login`, jq, no-mistakes v1.31.2 or newer, compatible gh-axi, chrome-devtools-axi, compatible lavish-axi, compatible tasks-axi per "Backlog backend" above, and compatible quota-axi.
[`bin/fm-bootstrap.sh`](../bin/fm-bootstrap.sh) owns the axi-family floor policy and the gh-axi and lavish-axi floors, while [`bin/fm-tasks-axi-lib.sh`](../bin/fm-tasks-axi-lib.sh) and [`bin/fm-quota-axi-lib.sh`](../bin/fm-quota-axi-lib.sh) hold their own tools' floor constants.
This section is the single owner of that universal toolchain list; backend guides' prerequisites point here and add only their backend-specific tools.
In that list, no-mistakes runs the validation pipeline, gh-axi, chrome-devtools-axi, and lavish-axi cover GitHub, browser, and rich-review operations, and tasks-axi plus quota-axi back backlog mutations and quota-aware array dispatch.
In that list, no-mistakes runs the validation pipeline, gh-axi, chrome-devtools-axi, and lavish-axi cover GitHub, browser, and rich-review operations, tasks-axi plus quota-axi back backlog mutations and quota-aware array dispatch, and jq backs the Claude workspace-trust pre-accept described under "Harness support" on top of its existing per-backend and per-feature uses below.
The per-backend delta is required only for the backend resolved from `FM_BACKEND`, then `config/backend`, then runtime auto-detection, then default `tmux`, so a home is never told to install a tool an inactive backend or feature would need.
That delta is owned in code by `fm_backend_required_tools` in `bin/fm-backend.sh`: the resolved backend's own session-provider CLI (`tmux`, `herdr`, `zellij`, `orca`, or `cmux`), `jq` for the JSON-emitting experimental adapters (`herdr`, `zellij`, `cmux`) whose spawn and liveness paths parse the backend's JSON output, and the `treehouse` worktree provider for every session-provider-only backend (`tmux`, `herdr`, `zellij`, `cmux`).
Backend tool availability uses the adapter's own executable resolver, so bootstrap and spawn agree on supported non-`PATH` locations such as cmux's bundled CLI.
Expand Down
2 changes: 1 addition & 1 deletion docs/sessionstart-nudge.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ The OpenCode nudge runs only on `session.created`.
The watcher-arm and turn-end plugins run later on `session.idle`, and the guard lets the watcher coordinator act first, so the plugins do not race for one lifecycle event.

Grok's guaranteed-loading alternative is a global token-guarded hook like the pattern used by `bin/fm-spawn.sh`.
That alternative expands trust and writes outside this repository, so Firstmate never installs it or grants folder trust automatically.
That alternative expands trust and writes outside this repository, so Firstmate never installs it or grants Grok project trust automatically.

## Regression coverage

Expand Down
Loading
Loading