Repository navigation
Conversation
…rub local credentials A project that tracks .claude/settings.local.json shows spawn's hook wiring as a modification, so the pre-kill safety check refused cleanup of every finished task in that project over a file cleanup deletes a few lines later. The dirty filter now ignores firstmate's own hook files (.claude/settings.local.json and the .opencode/plugins/fm-*.js plugins) at any status, including tracked-and-modified or deleted. Credential files a worker writes are untracked or gitignored, so neither the branch reset nor treehouse's return removes them, and a gitignored .env survived into the pooled worktree for the next task leased into that slot. Every treehouse pool return (a task worktree, a child worktree, a retired secondmate home) now first scrubs untracked or ignored credential-shaped files. It runs after the safety checks and never touches tracked files or vendor directories. The tmux and child Orca return paths also remove .opencode/plugins/fm-busy-state.js, which the other return paths already did. Claude-Session: https://claude.ai/code/session_01TpHCR5sezvXg8nyoVGogBb
This was referenced Sep 11, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Upstream contribution from a fork (dmealing/firstmate to kunchenguid/firstmate) of two teardown fixes a downstream firstmate home has been carrying locally, plus one small rider. (1) Firstmate's own hook files - .claude/settings.local.json, .opencode/plugins/fm-turn-end.js and .opencode/plugins/fm-busy-state.js - must never count as dirty in validate_worktree_teardown_safety at any git status, including tracked-and-modified or deleted. Some projects track .claude/settings.local.json; spawn overwrites it with hook wiring, and the existing filter only skipped untracked .claude/, so the pre-kill safety check refused cleanup of every finished task in those projects over a file teardown deletes itself. Accepted consequence: an uncommitted edit to one of exactly those three paths is not protected, which is fine because spawn owns their content. (2) scrub_local_credentials: untracked or gitignored credential-shaped files (.env, *.env, .npmrc, .pypirc, .netrc, .git-credentials, credentials, settings.xml, nuget.config, NuGet.Config, *.pem, *.key) survive treehouse return --force, and a live registry token was observed handed to the next task leased into the same pool slot. The function is a port of an existing field-tested implementation: its name list and its vendor-directory skip list (node_modules, target, dist, build, .venv, vendor) are deliberate, and it never touches tracked files. It runs at the top of teardown_treehouse_return so every pool return (task worktree, child worktree, retired secondmate home) is scrubbed, which is always after teardown's landed-work and dirty safety checks. The Orca path is deliberately not scrubbed because orca worktree rm --force deletes that worktree and Orca worktrees are not pooled. A single git ls-files --others with no exclude flag deliberately lists untracked and ignored files in one pass. (3) Rider: the tmux and child Orca return paths now also remove .opencode/plugins/fm-busy-state.js, as the other return paths already did. Regression tests in tests/fm-teardown.test.sh: one tracked hook file modified plus another deleted does not block teardown; a gitignored .env is removed before the worktree is returned while an ignored non-credential file and a tracked credential-shaped file are left untouched; both tests fail on unpatched main. wt_commit_file now creates parent directories and force-adds, so a host's global git excludes cannot break fixtures. Out of scope for this PR (follow-ups): deriving teardown's hook-path lists from fm_control_harness_wiring_paths, and having spawn pass Claude hooks via --settings instead of writing into a tracked file. The related upstream issues #4215 (cross-clone overlap warning) and #4216 (git 2.38 floor for merge-tree --write-tree) are separate and not addressed here.
What Changed
validate_worktree_teardown_safetyto exclude firstmate's own hook files (.claude/settings.local.json,.opencode/plugins/fm-turn-end.js,.opencode/plugins/fm-busy-state.js) from the dirty-worktree check at any git status, including when they are tracked-and-modified or deleted, since teardown cleanup removes them itself.scrub_local_credentialsfunction that removes untracked or gitignored credential-shaped files (.env,*.env,.npmrc,.pypirc,.netrc,.git-credentials,credentials,settings.xml,nuget.config,NuGet.Config,*.pem,*.key) from worktrees before they are returned to the pool, preventing live secrets from being handed to the next task in the same pool slot. The function deliberately avoids vendor directories and never touches tracked files.scrub_local_credentialsat the top ofteardown_treehouse_returnto ensure all pool returns (task worktree, child worktree, retired secondmate home) are scrubbed after safety checks.cleanup_firstmate_home_children) and the main teardown path to also remove.opencode/plugins/fm-busy-state.js.wt_commit_filetest helper to create parent directories and force-add files so a host's global git excludes cannot break fixtures.Risk Assessment
✅ Low: Change is a well-bounded, narrowly-scoped fix (hook-file allowlist regex plus a deliberately narrow credential-scrub helper run only on pooled worktree returns) that matches the stated intent exactly, includes regression tests reproducing both fixed failure modes, and does not touch tracked files or the non-pooled Orca path.
Testing
Ran full fm-teardown.test.sh test suite with 86 tests, all passing (0 failures). Verified the two new regression tests specifically validate the user intent: hook files no longer block teardown even when modified/deleted, and credential files are scrubbed before worktree return while preserving tracked files and non-credential ignored files. Code inspection confirmed scrub_local_credentials is called at the right lifecycle point (start of treehouse_return) and hook file removal is added to all return paths.
Evidence: Test Validation Report
Source: Test Validation Report
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
bash tests/fm-teardown.test.sh — full test suite executiontest_tracked_hook_file_changes_do_not_block_teardown — validates modified/deleted hook files don't block teardowntest_ignored_credentials_are_scrubbed_before_worktree_return — validates credential scrubbing before treehouse returnHook file removal verification across all return paths (cleanup_firstmate_home_children, orca tmux return, main return)✅ **Document** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.