uberblick/ub-agents v0.5.4
Configuration · Cleanup hook

Configuration

Cleanup hook

After every run, the launcher removes the run's private worktree. The optional cleanup hook runs just before that, to stop things a run started, such as test services.

Branches on GitHub

Hook configuration

cleanup:
  command: [./scripts/cleanup-agent-worktree]
  timeout-seconds: 60

Command

An argument list, run without a shell from the launcher's checkout.

command: [./scripts/cleanup-agent-worktree]

Timeout

Seconds before the hook is stopped. Defaults to 60, up to 3600.

timeout-seconds: 60

What it gets

The worktree and branch, plus a JSON file with the run's details.

UB_AGENTS_WORKTREE
UB_AGENTS_BRANCH
UB_AGENTS_CLEANUP_CONTEXT

Result

Exit zero to let the worktree be removed. Any other exit keeps the worktree and branch for a later retry; the run's outcome stands. Make the hook safe to run twice.

Leftovers

At startup, launch clears leftover worktrees (running the hook before removing each) and run scratch, and removes run logs older than 7 days. Decisions go to .ub-agents/sessions/*.cleanup.log. See the cleanup rules.

Key reference

cleanup is an optional mapping; without it, no project hook runs.

KeyType and defaultRules
commandRequired argv listRuns without a shell in the control checkout, so ./scripts/... resolves there even when a candidate changes its scripts.
timeout-secondsNumber, 60Positive, at most 3600.

Context fields

UB_AGENTS_CLEANUP_CONTEXT points to a JSON file with these fields, null when unavailable:

FieldValue
repositoryowner/name
runRun id
agentAgent name
assignmentIssue or PR number
kindissue or pr
handoffThe PR the run handed off to
statusThe released claim's result during later cleanup; otherwise the reported status
outcomeThe named outcome
worktreeAbsolute worktree path
branchBranch name

The hook also gets UB_AGENTS_REPOSITORY, UB_AGENTS_RUN, UB_AGENTS_AGENT, UB_AGENTS_ASSIGNMENT, UB_AGENTS_WORKTREE and UB_AGENTS_BRANCH, empty when unknown. Other UB_AGENTS_* variables are removed.

Put operator recovery steps in a project operations document linked from AGENTS.md, not in agent instructions. See the cleanup contract for process ownership, failed hooks and lease expiry, and the startup sweep for artifact protection and retention rules.