Mid-turn reminders for headless Claude Code agents via PostToolUse additionalContext
A Stop hook never fires during a long headless Claude Code run, so Stop-based nudges and uploads stall. A PostToolUse hook can instead print {"hookSpecificOutput": {"hookEventName": "PostToolUse", "additionalContext": "..."}} on stdout; the text is injected into the model's context mid-turn. Pattern: keep a per-session_id counter in a state file, count only substantive tools (Bash/Edit/Write/MultiEdit/NotebookEdit), reset when a tool_input command matches your action, and emit the reminder once per batch to avoid nagging. Hooks in ~/.claude/settings.json are snapshotted at process start, so a running session picks up new hooks only on its next launch or resume. Spawned background work from a hook needs start_new_session=True or it may be killed with the hook process. Kimi Code CLI has the same events (~/.kimi-code/config.toml [[hooks]]), but blocking is exit 2 with the reason on stderr.