Session-start dirty-state triage with background agents
Use when a handoff or user asks you to confirm a repo is clean before resuming work, especially in workspace-hub where overnight Claude runs, governance hooks, and provider scorecards may keep the orchestrator repo dirty.
Why this exists
A plain git status can overstate risk. In workspace-hub, dirty state may come from:
.claude/state/* session and correction logs
- provider scorecard/report outputs under
config/ai-tools/ and docs/reports/
- transient directories like
.nightly-results/ or inspection scratch dirs
- an active overnight/background Claude run still writing state
Meanwhile a nested implementation repo (for example aceengineer-website/) may still be fully clean and ready.
Workflow
Read the handoff first and extract any mentioned repos, issue numbers, and active parallel-agent warnings.
Check git state separately for each repo involved, not just the top-level workspace.
- Example:
git status --short --branch in workspace-hub
git status --short --branch in aceengineer-website
If the top-level repo is dirty, classify the paths:
- generated governance/session state
- generated reports/scorecards
- transient scratch/output dirs
- real source/docs changes affecting the intended task
Check for active agent processes before concluding the dirty state is yours to clean up.
ps aux | grep -E 'claude|codex|gemini' | grep -v grep
- Include interactive shells/agents, not only background jobs:
pwdx <pid> can reveal an active claude sitting in the repo even after a reboot.
process(action='list') may be empty after reboot because Hermes-tracked background sessions do not survive, while OS-level Claude/Hermes/TUI processes may still exist.
Correlate active processes with the dirty paths and any issue-specific overnight work.
- If an overnight agent is actively working an issue, avoid choosing a path that collides with that issue.
- If an active interactive Claude process has cwd in the same repo, treat repo-wide Git mutation as unsafe even if no Hermes background sessions are listed.
For post-reboot salvage or stale-lock recovery, preserve state before any mutation:
- create a backup branch at current
HEAD, e.g. git branch salvage/post-reboot-YYYYMMDD-HHMMSS HEAD
- save
git diff --binary, git diff --cached --binary, and git status --porcelain=v1 outside the repo or under a dated salvage directory
- copy any key handoff/result file explicitly before reset/rebase/stash attempts
- only remove
.git/index.lock after confirming no live Git/agent process owns it or is working in the repo; a stale lock alone is not permission to mutate when an active Claude cwd is present
Report the result precisely:
- which repo is clean
- which repo is dirty
- whether the dirt appears operational/generated vs implementation work
- whether an active background/interactive agent makes the state unsafe to touch
- where salvage artifacts were written if mutation is deferred
Recommend the next task based on lowest contention, not just highest priority.
- If safe reconciliation is blocked by an active writer, schedule or hand off a delayed narrow reconciliation job that re-checks process/git state before mutating.
For post-reboot recovery where important commits/artifacts exist outside the dirty primary checkout, reconcile from an isolated clean worktree rather than touching the active checkout.
- Create or use a throwaway reconciliation worktree from
origin/main (for example /mnt/local-analysis/reconcile-main-YYYYMMDD).
- Fetch the remote, cherry-pick/rebase only the recovered commits or copy only the recovered handoff/artifact files into that worktree.
- Resolve shared planning-index conflicts there, preserving newer remote rows/status and adding only the missing recovered rows/artifacts.
- Push the reconciled commit(s) from the clean worktree if verification passes.
- Leave the primary dirty checkout untouched while any Claude/Hermes/TUI process has cwd there.
- Separately schedule a delayed cleanup/reconcile job for the primary checkout that re-checks live processes and saves diffs before any reset/stash.
- If the recovery also reveals queued plan-review or implementation work, schedule that as a separate future job from the clean worktree so salvage, restart/review, and future work are decoupled.
Good output pattern
workspace-hub: not clean; mostly generated state/report churn plus active overnight agent on #2348
aceengineer-website: clean
- Recommendation: choose a non-colliding path like #2357 rather than #2348
Pitfalls
- Do not say "both repos are clean" just because the implementation repo is clean.
- Do not assume top-level dirt means the user's requested work is blocked.
- Do not ignore active overnight agents; they can explain the churn and create issue-level contention.
- Do not collapse nested repos into one cleanliness judgment.
Reuse trigger
Apply this whenever a session handoff says "confirm clean git state" and the workspace uses background AI agents, nightly runs, or generated governance artifacts.
1---2name: session-start-dirty-state-triage-with-background-agents-23description: Distinguish real implementation dirt from generated session-state churn when resuming a repo with active overnight/background agents.4---56# Session-start dirty-state triage with background agents78Use when a handoff or user asks you to confirm a repo is clean before resuming work, especially in workspace-hub where overnight Claude runs, governance hooks, and provider scorecards may keep the orchestrator repo dirty.910## Why this exists1112A plain `git status` can overstate risk. In workspace-hub, dirty state may come from:13- `.claude/state/*` session and correction logs14- provider scorecard/report outputs under `config/ai-tools/` and `docs/reports/`15- transient directories like `.nightly-results/` or inspection scratch dirs16- an active overnight/background Claude run still writing state1718Meanwhile a nested implementation repo (for example `aceengineer-website/`) may still be fully clean and ready.1920## Workflow21221. Read the handoff first and extract any mentioned repos, issue numbers, and active parallel-agent warnings.232. Check git state separately for each repo involved, not just the top-level workspace.24 - Example:25 - `git status --short --branch` in `workspace-hub`26 - `git status --short --branch` in `aceengineer-website`273. If the top-level repo is dirty, classify the paths:28 - generated governance/session state29 - generated reports/scorecards30 - transient scratch/output dirs31 - real source/docs changes affecting the intended task324. Check for active agent processes before concluding the dirty state is yours to clean up.33 - `ps aux | grep -E 'claude|codex|gemini' | grep -v grep`34 - Include interactive shells/agents, not only background jobs: `pwdx <pid>` can reveal an active `claude` sitting in the repo even after a reboot.35 - `process(action='list')` may be empty after reboot because Hermes-tracked background sessions do not survive, while OS-level Claude/Hermes/TUI processes may still exist.365. Correlate active processes with the dirty paths and any issue-specific overnight work.37 - If an overnight agent is actively working an issue, avoid choosing a path that collides with that issue.38 - If an active interactive Claude process has cwd in the same repo, treat repo-wide Git mutation as unsafe even if no Hermes background sessions are listed.396. For post-reboot salvage or stale-lock recovery, preserve state before any mutation:40 - create a backup branch at current `HEAD`, e.g. `git branch salvage/post-reboot-YYYYMMDD-HHMMSS HEAD`41 - save `git diff --binary`, `git diff --cached --binary`, and `git status --porcelain=v1` outside the repo or under a dated salvage directory42 - copy any key handoff/result file explicitly before reset/rebase/stash attempts43 - only remove `.git/index.lock` after confirming no live Git/agent process owns it or is working in the repo; a stale lock alone is not permission to mutate when an active Claude cwd is present447. Report the result precisely:45 - which repo is clean46 - which repo is dirty47 - whether the dirt appears operational/generated vs implementation work48 - whether an active background/interactive agent makes the state unsafe to touch49 - where salvage artifacts were written if mutation is deferred508. Recommend the next task based on lowest contention, not just highest priority.51 - If safe reconciliation is blocked by an active writer, schedule or hand off a delayed narrow reconciliation job that re-checks process/git state before mutating.52539. For post-reboot recovery where important commits/artifacts exist outside the dirty primary checkout, reconcile from an isolated clean worktree rather than touching the active checkout.54 - Create or use a throwaway reconciliation worktree from `origin/main` (for example `/mnt/local-analysis/reconcile-main-YYYYMMDD`).55 - Fetch the remote, cherry-pick/rebase only the recovered commits or copy only the recovered handoff/artifact files into that worktree.56 - Resolve shared planning-index conflicts there, preserving newer remote rows/status and adding only the missing recovered rows/artifacts.57 - Push the reconciled commit(s) from the clean worktree if verification passes.58 - Leave the primary dirty checkout untouched while any Claude/Hermes/TUI process has cwd there.59 - Separately schedule a delayed cleanup/reconcile job for the primary checkout that re-checks live processes and saves diffs before any reset/stash.60 - If the recovery also reveals queued plan-review or implementation work, schedule that as a separate future job from the clean worktree so salvage, restart/review, and future work are decoupled.6162## Good output pattern6364- `workspace-hub`: not clean; mostly generated state/report churn plus active overnight agent on #234865- `aceengineer-website`: clean66- Recommendation: choose a non-colliding path like #2357 rather than #23486768## Pitfalls6970- Do not say "both repos are clean" just because the implementation repo is clean.71- Do not assume top-level dirt means the user's requested work is blocked.72- Do not ignore active overnight agents; they can explain the churn and create issue-level contention.73- Do not collapse nested repos into one cleanliness judgment.7475## Reuse trigger7677Apply this whenever a session handoff says "confirm clean git state" and the workspace uses background AI agents, nightly runs, or generated governance artifacts.