An overnight program of feature lanes or a multi-hour bug hunt fails in two quiet ways. It exhausts the usage limit of the plan, or an agent, Docker or a test process hangs unnoticed. The ft-watch skill puts two watchdogs on such a run, and you start them only when the run needs them. Choose a scenario and watch one run end.
/ft-watchYou type this command in the Claude Code session that runs the long job.The command is the skill file skills/ft-watch/SKILL.md. It tells the main loop how to start, re-arm and stop the watchers, and what to do on each exit code.
The session
main loopThe Claude Code session in which you talk to the orchestrators. It starts the watchers and acts on each exit code.
lanesA lane is one running top-level orchestrator. Its agents, processes and containers do the long work.
The watchers in watch.py
token watcherReads the 5-hour and the 7-day usage window every 5 minutes.
freeze watcherRuns its checks every 2 minutes and reports each new finding once.
state fileHolds the key of each finding that the watcher already reported.
Blue: you and the session. Orange: the watchers and how a run ends. Grey: what the watchers read. Choose a scenario, or select an element to read about it.
Nothing new: exit 10
You type /ft-watch. The main loop says in one line what is armed.
The main loop starts watch.py as a background task from the project directory.
Every 5 minutes the token watcher reads both usage windows. Both are under the threshold.
The same task runs the freeze watcher.
Every 2 minutes the freeze watcher runs its checks. Each check finds nothing new.
After 25 minutes the run prints REARM and exits with 10.
A task notification reaches the main loop. It sends you no message.
The main loop starts the same command again. This re-arm is one turn.
The usage limit is near: exit 2
The token watcher reads your OAuth token.
It reads the usage figures. The 5-hour window shows 94%, and the threshold is 93%.
It prints a TOKEN STOP line and exits with 2.
A task notification reaches the main loop.
The main loop launches no new agent. Running agents finish or reach their ## HANDOFF.
It tells you the window, the percentage and the reset time.
After the reset time, it re-arms the token watcher.
An agent is stuck: exit 7
One transcript has no write for 30 minutes, and its last step is a tool call.
The key agent:<id> is new, so the watcher stores it.
It prints a FREEZE line and exits with 7.
A task notification reaches the main loop.
The main loop confirms with ListAgents, stops the agent and relaunches it from its last ## HANDOFF.
It re-arms the watcher. The state file keeps this key, so this finding does not return.
Docker stops answering: exit 7
docker info gives no answer within 20 s.
The watcher prints a FREEZE docker-api line and exits with 7.
A task notification reaches the main loop.
The main loop probes Docker once more with a bounded call.
A restart kills the containers of every lane. So the main loop needs your consent or a standing rule of the session.
It re-arms the watcher.
The usage endpoint gives no answer
The endpoint gives no answer. The watcher prints usage=unavailable and keeps going.
The value is unknown, so no STOP can fire. The run ends with 10 after 25 minutes.
A task notification reaches the main loop.
The main loop re-arms the watcher.
A bad argument: exit 3
You type /ft-watch tokens 120.
The main loop passes the value as --stop 120.
The value must be above 0 and at most 100. The script exits with 3 before it watches anything.
A task notification reaches the main loop.
The main loop shows you the error. It does not retry blindly.
How the parts connect
You type the command in the session, and the main loop answers you.
The main loop starts and re-arms the watchers as background tasks.
The token watcher reads the token, then calls the usage endpoint with it.
The freeze watcher runs each of these checks on every poll.
The freeze watcher stores each new key, and drops a key that it already knows.
A run with nothing new ends with exit 10.
A window at the threshold ends the run with exit 2.
A new finding ends the run with exit 7.
A bad argument ends the run with exit 3.
Each exit code reaches the main loop as a task notification.
The main loop launches no new agent after a STOP, and it handles a stuck agent.
The main loop probes Docker again after a docker-api finding.
The token watcher stops before the hard limit
A STOP is exit code 2 of this watcher: a usage window reached the threshold.
1. Read the token
The watcher reads your Claude Code OAuth token. It never prints, logs or writes the token.
2. Read the usage
It reads the 5-hour and the 7-day window every 5 minutes. The endpoint rate-limits, so never poll faster.
3. Compare with the threshold
The default threshold is 93%. Set it with --stop.
BELOWIt prints an ok line and waits.
REACHEDIt prints a TOKEN STOP line and exits with 2.
NO ANSWERIt prints usage=unavailable and keeps going.
macOS, Linux
python3 ~/.claude/skills/ft-watch/watch.py tokens --stop 9309:24:48 ok 5h=88% 7d=50%09:29:48 ok 5h=91% 7d=50%09:34:48 TOKEN STOP 5h=94% (threshold 93%) RESET_EPOCH=1792056000 RESET_LOCAL=2026-10-15 11:20 WINDOW=5h
IllustrationThe main loop runs this command for you. The line formats are real, and the values are invented.
A threshold below 100% leaves room for running agents to finish their step and write a handoff. Without it, they stop mid-edit at the hard limit.
The usage endpoint can change
The endpoint is not a documented API. When it does not answer, the value is unknown, and the watcher does not treat it as 0%. No STOP can fire until it answers again.
Where the figures and the token come from
The figures come from https://api.anthropic.com/api/oauth/usage, called with your OAuth token.
On macOS the watcher first reads the Keychain item Claude Code-credentials. Otherwise it reads ~/.claude/.credentials.json. It honours $CLAUDE_CONFIG_DIR for that file.
The freeze watcher reports what looks stuck
Every 2 minutes it runs the checks below. Each bar shows how long a thing may run before it becomes a finding. Open a row for its rule.
Limit before a finding
Docker gives no answer20 s
The key is docker-api:<hour>. docker info gives no answer within 20 s, or it fails. The watcher runs this check only when docker is on PATH. The key holds the hour, so this finding returns at most once per hour. No flag changes this limit.
Agent with no progress adjustable20 min
The key is agent:<id>. A sub-agent transcript has no write for 20 to 180 minutes, and its last step is a tool call with no later step. --idle-min sets the 20, and the 180 is fixed. A transcript with no write for more than 180 minutes is not a finding.
A transcript that ends in text or a hand-back is a finished agent. An agent that waits on a foreground child agent is not stuck, since the watcher checks the child on its own.
By default the watcher reads the subagents directory of the newest session of the current project: ~/.claude/projects/<project-slug>/<session>/subagents. Start the watcher from the project directory, or pass --subdir. With no directory it prints (no subagents dir), and this check finds nothing.
Docker client command30 min
The key is docker-cli:<pid>. A docker run or docker exec client runs for more than 30 minutes. No flag changes this limit.
Container adjustable30 min
The key is container:<name>. A container runs for more than 30 minutes. --container-min sets the limit. The watcher skips long-lived containers: a name or image that matches buildkit, mcp, kroki or ryuk.
Maven test or build60 min
The key is maven:<pid>. A Maven, Surefire or Failsafe process runs for more than 60 minutes. No flag changes this limit.
Shell wait loop60 min
The key is wait-loop:<pid>. A shell loop with until or while and sleep runs for more than 60 minutes. No flag changes this limit.
A foreground command that hits the timeout of the Bash tool moves to the background and keeps running. So a loop whose condition never comes true outlives the agent that started it.
Lock file or directory adjustable90 min
The key is lock:<path>:<modification time>. A lock is 90 minutes old or older. --lock-min sets the limit. A lock with a newer modification time is a new finding.
The default glob is ~/.local/state/ft-ai-toolkit/*.lock*. --lock replaces that glob, and you can repeat the flag.
A label marks a limit that a flag changes. Your own --extra check adds any other finding. The watcher reports each finding once and remembers its key in ~/.local/state/ft-ai-toolkit/watch-freeze.seen. Delete the file to see everything again.
A finding is a candidate
The watcher stops nothing by itself. The main loop verifies each finding before it acts, within these limits:
Stuck agent
The main loop confirms with the ListAgents tool or the task status before it stops the agent. A run that completed is not stuck. It relaunches the agent from the last ## HANDOFF of its journal.
Long process or container
It reads the log or the CPU use. It stops the process or container only if it is hung AND belongs to a lane of this session.
Old lock
It finds the holder of the lock. It removes the lock only when the holder is gone.
Silent Docker
It probes once more with a bounded call. A restart of Docker or OrbStack kills the containers of every lane, so it needs your consent or a standing rule of the session.
OrbStack is a Docker runtime for macOS. It is an external product, this repository does not define it, and this definition is unverified.
Each run ends with an exit code
A watcher never runs forever. Each run ends with an exit code, and the main loop gets a task notification and acts on that code.
Exit 10: nothing new→ re-arm silently
The main loop starts the same command again and sends you no message. This new start is a re-arm.
Exit 2: token STOP→ launch nothing new
The main loop launches no new agent, workflow or parallel batch of agents. Running agents finish or reach their ## HANDOFF, the resume block in the journal of an agent. The main loop tells you the window, the percentage and the reset time. It does not re-arm the token watcher at once. It re-arms that watcher after the reset time, when the window starts over.
Exit 7: new findings→ verify, act, re-arm
Each finding is one FREEZE <key> <detail> line. The main loop verifies each one and acts within its limits. Then it re-arms the watcher.
Exit 3: bad arguments→ show you the error
The main loop shows you the error and does not retry blindly.
Why the watchers are on demand
Every re-arm is one turn of the main loop, and that turn re-reads the whole conversation. Both costs below are estimates. They depend on the context size and the cache state.
25 minlongest runSet it with --minutes. Claude Code kills a background task after about 30 minutes.
~$0.15one re-armThe estimate for one turn at 300K tokens of context.
~$4ten hours of re-armsThe estimate for re-arming through a ten-hour run.
Start the watchers
Check the install once, then type one command in the session that runs the long job.
1
Check the install
The self-test covers the transcript states, the process, container and lock rules, the report-once state file, usage parsing and the STOP threshold. It does not reach Docker or the usage endpoint. A passing run prints selftest OK.
macOS, Linux
python3 ~/.claude/skills/ft-watch/watch.py --selftestselftest OK
The STOP comes at 95%. The number becomes --stop 95. With no number, the threshold is 93%.
Freeze watcher only→/ft-watch freeze
The token watcher stays off.
Both, with your own limits→/ft-watch all 95 --idle-min 30
Extra flags go to watch.py verbatim. The list is below these steps.
End the watch→/ft-watch stop
The main loop stops every running watcher of this session and says which ones it stopped.
You
4
Read the one-line confirmation
The main loop first checks its background tasks, and it never runs two watchers of the same mode. It starts the command as a background task and confirms in one line what is armed, at which threshold. After that, it reports only a STOP or a finding.
Main loop
Every flag of watch.py
Add any flag after the command, as in /ft-watch freeze --container-min 45.
Flag
Default
Sets
--stop
93
Token STOP threshold, in percent.
--minutes
25
Run length before exit 10.
--poll
120
Freeze check interval, in seconds.
--token-poll
300
Usage probe interval, in seconds.
--subdir
Newest session of this project
The sub-agent directory to watch.
--idle-min
20
Agent idle limit, in minutes.
--container-min
30
Container age limit, in minutes.
--lock
~/.local/state/ft-ai-toolkit/*.lock*
Lock glob. Repeatable.
--lock-min
90
Lock age limit, in minutes.
--extra
None
Your own check command.
--state
~/.local/state/ft-ai-toolkit/watch-freeze.seen
The state file of reported keys.
Platform differences
skills/ft-watch/watch.py is one stdlib-only Python script for macOS, Linux and Windows. It has no .sh and .ps1 pair, and these differences live inside the script.
Item
macOS and Linux
Windows
Python
python3
python or py -3
Process list
ps -A -o pid=,etime=,args=
PowerShell Get-CimInstance Win32_Process
OAuth token
Keychain on macOS, else ~/.claude/.credentials.json