Let the agent self-pause on an unrecoverable blocker#1
Open
dqtz5vpvj9-create wants to merge 2 commits into
Open
Let the agent self-pause on an unrecoverable blocker#1dqtz5vpvj9-create wants to merge 2 commits into
dqtz5vpvj9-create wants to merge 2 commits into
Conversation
The original STOP_HOOK_REASON only offered the user-side `/goal pause` as the way to stop the loop: > If the goal cannot continue productively because user input is required, > explain the blocker clearly. The user can run `/goal pause` or > `/goal clear` to stop automatic continuation. When the agent encountered a hard blocker (device offline, missing external resource, user-input required), it followed the prompt literally: it wrote "please run /goal pause" in chat and stopped. But that chat text does not actually trigger the slash command — the agent cannot invoke user-side slash commands. The Stop hook re-fired, the same STOP_HOOK_REASON was re-injected, the agent re-explained the blocker, and the loop repeated until either CLAUDE_GOAL_MAX_STOP_CONTINUES (500 by default) was hit or the user's API budget ran out. Observed in the wild: a real session burned 24 retries of "无法继续,请运行 /goal pause" back-to-back before the user's account hit a 403 "insufficient pre-charge balance" error. The runaway guard at 500 is far above the burn threshold for many users. Backend already supports `python3 claude_goal.py pause`, so this is a prompt-only fix: - STOP_HOOK_REASON now tells the agent both paths are valid: the user can run `/goal pause`, or the agent can run the pause CLI itself. It also explicitly warns that writing "please run /goal pause" in chat does NOT pause, because that is the failure mode that triggers the loop. Finally it gives an escalation hint: if the same blocker reappears across multiple Stop re-entries, the user has not seen the message yet — self-pause. - CONTINUATION_INSTRUCTIONS gets a matching paragraph so the same guidance is in scope from the moment a goal is set, not only after a Stop hook fires. - SKILL.md mirrors the rule so the skill-loaded view is consistent with the runtime prompt. No logic changes; existing tests still pass (9/9). The user-side `/goal pause` path is unchanged and remains the recommended action when the user is present. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
… location
The previous prompts referenced `python3 ~/.claude/skills/goal/scripts/claude_goal.py complete`
(and similarly for pause) as literal strings. That path only resolves when the
user followed `install.sh`'s default layout. It silently breaks for anyone who:
- runs the script directly from a repo checkout (e.g. for testing or development),
- installs the skill at a non-default `~/.claude/skills/` prefix,
- runs on Windows, where `~/.claude/skills/goal/scripts/claude_goal.py` is not the install path,
- moves or renames the install directory.
In those cases the agent reads the prompt, copies the literal path, runs the
shell command, and gets `No such file or directory` — at which point it cannot
mark complete or self-pause and the Stop-hook loop returns.
Fix: introduce `SCRIPT_PATH = os.path.abspath(__file__)` and substitute it as
`{script_path}` into both `CONTINUATION_INSTRUCTIONS` and `STOP_HOOK_REASON`.
`os.path.abspath` (not `Path.resolve`) is used deliberately so symlinks are
preserved — `install.sh` puts a symlink at `~/.claude/skills/goal`, and the
prompt should refer to that stable path rather than the underlying repo path
(which can move).
`SKILL.md` is left alone: it is loaded statically by Claude Code at skill
load time, has no runtime substitution mechanism, and is tied to install.sh's
layout by definition (the skill cannot load at all if `~/.claude/skills/goal/`
does not exist), so embedding the literal install path there is correct.
Tests unchanged, 9/9 pass. Smoke-tested: stop-hook output now contains the
real on-disk path, e.g. `/home/<user>/.claude/skills/goal/scripts/claude_goal.py`.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation — observed runaway loop
The original
STOP_HOOK_REASONtold only the user how to stop the loop:When the agent encountered a real hard blocker (target device offline, missing external resource, user input required), it followed the instruction literally: it wrote
"please run /goal pause"in chat and stopped. But chat text does not trigger user-side slash commands — the agent cannot invoke/goal pause. So the Stop hook re-fired, the sameSTOP_HOOK_REASONwas re-injected, the agent re-explained the same blocker, and the loop tightened until eitherCLAUDE_GOAL_MAX_STOP_CONTINUES(500) was hit or the user's API budget ran out.Shape of one real incident (Claude Opus 4.7 + Claude Code, May 2026), anonymized:
The runaway guard at 500 is far above the budget burn-through threshold for many users — the loop tightens fast enough to drain credit in well under 100 turns.
Fix — prompt only, no logic change
The backend already supports
python3 claude_goal.py pause. The agent simply was never told it could use that path. This PR fixes the prompts:STOP_HOOK_REASONnow offers both paths and explicitly warns about the failure mode that caused the loop:CONTINUATION_INSTRUCTIONSgets a matching paragraph so the same guidance is in scope from the moment a goal is set, not only after the Stop hook has already fired.SKILL.mdmirrors the rule so the skill-loaded view is consistent with the runtime prompt.The user-side
/goal pausepath is unchanged and remains the right action when the user is present and responsive.Verification
python3 -m pytest tests— 9/9 pass before and after.Diff size
2 files changed, 5 insertions(+), 1 deletion(-).
Generated with Claude Code.