From 84f12f34bdacd484eb21d0e60903675e53233592 Mon Sep 17 00:00:00 2001 From: claude-code-best Date: Sat, 9 May 2026 17:50:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8F=90=E5=8D=87=20CLAUDE.md=20?= =?UTF-8?q?=E6=8C=87=E4=BB=A4=E6=9D=83=E9=87=8D=20=E2=80=94=20=E7=8B=AC?= =?UTF-8?q?=E7=AB=8B=20project-instructions=20+=20deferred=20tools=20?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - prependUserContext: 将 claudeMd 从通用 提取为独立的 用户消息,不带免责声明,置于消息列表最前面 - queryModel: deferred tools 消息从 prepend 改为 append,避免抢占 project-instructions 的最高权重位置;标签规范化为 Co-Authored-By: glm-5-turbo --- src/services/api/claude.ts | 6 ++++-- src/utils/api.ts | 39 +++++++++++++++++++++++++++----------- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/services/api/claude.ts b/src/services/api/claude.ts index aba74a0f9..9b82f428e 100644 --- a/src/services/api/claude.ts +++ b/src/services/api/claude.ts @@ -1407,12 +1407,14 @@ async function* queryModel( .sort() .join('\n') if (deferredToolList) { + // Append to the end of the messages array (not prepend) so it + // never抢占 (CLAUDE.md) at the front. messagesForAPI = [ + ...messagesForAPI, createUserMessage({ - content: `\n${deferredToolList}\n\nTo invoke any tool listed above, use ExecuteExtraTool with {"tool_name": "", "params": {...}}. This is the ONLY way to call deferred tools — do not read source code or analyze implementation, just call ExecuteExtraTool directly.`, + content: `\n\n${deferredToolList}\n\nTo invoke any tool listed above, use ExecuteExtraTool with {"tool_name": "", "params": {...}}. This is the ONLY way to call deferred tools — do not read source code or analyze implementation, just call ExecuteExtraTool directly.\n`, isMeta: true, }), - ...messagesForAPI, ] } } diff --git a/src/utils/api.ts b/src/utils/api.ts index 5ee820c8a..12c11ecdf 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -452,19 +452,36 @@ export function prependUserContext( return messages } - return [ - createUserMessage({ - content: `\nAs you answer the user's questions, you can use the following context:\n${Object.entries( - context, - ) - .map(([key, value]) => `# ${key}\n${value}`) - .join('\n')} + // Extract claudeMd as a dedicated high-weight user message so it isn't + // buried inside the generic with the "may or may not be + // relevant" disclaimer, which would degrade its instructional weight. + const { claudeMd, ...rest } = context + const result: Message[] = [] + + if (claudeMd) { + result.push( + createUserMessage({ + content: `\n${claudeMd}\n\n`, + isMeta: true, + }), + ) + } + + const restEntries = Object.entries(rest) + if (restEntries.length > 0) { + result.push( + createUserMessage({ + content: `\nAs you answer the user's questions, you can use the following context:\n${restEntries + .map(([key, value]) => `# ${key}\n${value}`) + .join('\n')} IMPORTANT: this context may or may not be relevant to your tasks. You should not respond to this context unless it is highly relevant to your task.\n\n`, - isMeta: true, - }), - ...messages, - ] + isMeta: true, + }), + ) + } + + return [...result, ...messages] } /**