Repository navigation
Pre- and post-settle hooks for any thread, including ones T3 doesn't manage a worktree for #22320
Replies: 1 comment
|
+1 for the post-settle hook. Another use case, and two additions to the payload. Use case. I run a background review of each thread when I settle it: a script reads the thread's Claude Code transcript and proposes notes and rule changes for me to approve later. Most of these threads are scratch threads with no worktree, so Current workaround. A launchd job polls T3's local state database every 15 minutes, read-only, and looks for threads whose Additions to the proposed payload:
|
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Problem
Settling a thread is the natural "this work is done" moment, but T3 only lets a project hook into it in one narrow case: a
runOnSettleproject action (#16290) runs a shell command in the thread's worktree, and only when the thread is bound to a worktree T3 knows about. Many workflows don't look like that, so there's nowhere to attach wrap-up or cleanup work.Example workflow
I keep one directory that holds a set of related repositories side by side (it is not itself a git repo), and I open it in T3 as a single project. Threads start in that directory. When a task needs changes, the agent creates a worktree for whichever repositories it touches, often more than one, using an external worktree tool rather than T3's built-in worktrees.
I don't use T3's worktrees because they don't fit this workflow. A thread binds to one worktree in one project, and
delegate_taskwithisolation: "worktree"only branches from the parent's own project. A thread rooted in a non-git directory therefore can't get T3-managed worktrees for the repositories inside it, short of launching a separate top-level thread per repository, which scatters one piece of work across many threads.From T3's point of view these threads have no worktree:
worktreePathis null, sorunOnSettlenever fires and T3's own worktree cleanup never sees those directories. With the way I work today, nothing runs on settle at all. When the thread settles, the worktrees it created stay behind until I clean them up by hand or a scheduled job catches them later. The agent also can't record which worktrees belong to which thread, because nothing exposes the thread's ID to its shell (#6781).Generic pre- and post-settle hooks would fix this without T3 needing to understand my layout or my worktree tool, and they'd open up many other uses people have asked for around settling: wrap-up prompts, notifications, tracker updates, tearing down environments, and cleanup for whatever workspace tooling someone uses.
Proposal: pre- and post-settle hooks
Two optional hooks around settlement, configurable globally with per-project overrides, off by default:
Thread context for the post-settle hook could be environment variables or JSON on stdin, for example:
{ "threadId": "...", "projectId": "...", "projectRoot": "/path/to/project", "worktreePath": null, "branch": null, "settledBy": "user | auto-merge | auto-inactivity", "relationshipToParent": null }If agent shells also got the thread ID (e.g.
T3CODE_THREAD_ID, as in #6781), an agent could tag the worktrees it creates with that ID, and the post-settle hook could remove exactly those, without guessing.How this relates to existing work
runOnSettle(feat(server): run a project action when a worktree thread settles #16290) stays as is; it becomes one specific post-settle hook, scoped to the project's worktree.Open questions
All reactions