Feature: expose background Bash/Monitor task liveness to hooks (Stop/SessionEnd) via a stable, documented signal

Open 💬 0 comments Opened Jul 13, 2026 by oconnorjoseph

Context

Related to #62516 (closed as stale/not-planned) — same underlying gap, re-filed with a concrete empirical finding and a narrower ask.

Building a Stop-hook check-battery gate that defers while session-spawned background work is in flight (a Workflow run, background Agent-tool subagents, a led team, and — the gap this issue is about — a run_in_background Bash task or a Monitor watcher).

What I found

Both run_in_background Bash tasks and Monitor watchers (confirmed to be a local_bash task type under the hood) write their stdout continuously to a real (non-symlink) file at:

/tmp/claude-<uid>/<cwdSlug>/<sessionId>/tasks/<taskId>.output

I verified empirically (macOS, current CLI) that this file's mtime advances while the underlying process is alive and producing output, and that completed tasks' files are eventually cleaned up. This means a hook can currently detect background-task liveness by checking this directory's freshness — I built exactly this as a workaround (mirroring the existing pattern already used to detect Workflow-tool runs and Agent-tool subagents via their own per-session state directories under ~/.claude/projects/<cwdSlug>/<sessionId>/).

The problem

This directory scheme (/tmp/claude-<uid>/<cwdSlug>/<sessionId>/tasks/) is undocumented internal implementation detail — not a stable, versioned contract. It could change format, location, or retention behavior in any future release with no notice, silently breaking any hook that depends on it. Unlike ~/.claude/projects/<cwdSlug>/<sessionId>/{workflows,subagents}/, which several of our own hooks already treat as a de facto stable structure, this tasks/ directory has no documented guarantee at all.

Ask

Either:

  1. Document and stabilize the existing tasks/<taskId>.output directory/file scheme (path format, retention, symlink-vs-regular-file semantics for different task kinds) as a supported way for hooks to check background-task liveness, or
  2. Add a first-class hook-facing primitive — e.g. a TaskList-equivalent readable from a command hook (a tasks.json summary file, or a new hook input field enumerating in-flight background task/Monitor IDs) — so hooks don't need to reverse-engineer temp-directory internals at all.

Option 2 is the more robust fix and matches the "Option B" proposal in #62516, but option 1 (just documenting/stabilizing what already empirically works) would unblock this today with much less implementation work.

Environment

  • Claude Code (current, as of 2026-07-13)
  • macOS (Darwin 25.5.0)

View original on GitHub ↗