Skip to content

Commit 63f7d09

Browse files
committed
feat(ai-chat): surface queued user clarifications via PostToolUse
With PreToolUse hooks now returning {} (allow), the old practice of appending CLARIFICATION_HINT to permissionDecisionReason no longer reaches Claude when a user types a follow-up mid-stream — Edit, Write, and Read all fall straight through to native execution. Add a catch-all PostToolUse hook (no matcher) that returns the hint as additionalContext whenever _queuedClarification is set. Fires after every tool — Bash, Grep, Glob, WebFetch, Task, the Phoenix MCP tools, etc. — so any in-flight checkpoint prompts Claude to call getUserClarification before continuing. Becomes a no-op once the queue is drained. Edit/Write specific PostToolUse hooks now return {} for all paths; clarification is centralised in the catch-all so we can't double-fire.
1 parent 4562292 commit 63f7d09

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

src-node/claude-code-agent.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,7 @@ async function _runQuery(requestId, prompt, projectPath, model, signal, locale,
864864
edit: editPayload
865865
});
866866
}
867+
// Catch-all PostToolUse below handles clarification.
867868
return {};
868869
}
869870
]
@@ -900,14 +901,45 @@ async function _runQuery(requestId, prompt, projectPath, model, signal, locale,
900901
}
901902
});
902903
}
904+
// Catch-all PostToolUse below handles clarification.
903905
return {};
904906
}
905907
]
908+
},
909+
{
910+
// Catch-all: surface a queued user follow-up after every
911+
// tool. Edit/Write/Read have their own hooks above, but
912+
// any tool can be a meaningful checkpoint (Bash, Grep,
913+
// Glob, WebFetch, Task, the Phoenix MCP tools, etc.) so
914+
// we register one matcher-less hook that just returns
915+
// the clarification context if any is queued. Once
916+
// getUserClarification runs and clears _queuedClarification,
917+
// _maybeClarifyContext returns {} and this becomes a no-op.
918+
hooks: [
919+
async () => {
920+
return _maybeClarifyContext();
921+
}
922+
]
906923
}
907924
]
908925
}
909926
};
910927

928+
// Returns a PostToolUse SyncHookJSONOutput that injects the clarification
929+
// hint as additionalContext when the user has typed a follow-up while the
930+
// AI is streaming. With our PreToolUse hooks now returning {} (allow), the
931+
// old practice of appending CLARIFICATION_HINT to permissionDecisionReason
932+
// no longer reaches Claude — PostToolUse additionalContext is the new path.
933+
function _maybeClarifyContext() {
934+
if (!_queuedClarification) { return {}; }
935+
return {
936+
hookSpecificOutput: {
937+
hookEventName: "PostToolUse",
938+
additionalContext: CLARIFICATION_HINT
939+
}
940+
};
941+
}
942+
911943
// Set Claude CLI path if found
912944
const claudePath = findGlobalClaudeCli();
913945
if (claudePath) {

0 commit comments

Comments
 (0)