fix: 提升 CLAUDE.md 指令权重 — 独立 project-instructions + deferred tools 位置调整

- prependUserContext: 将 claudeMd 从通用 <system-reminder> 提取为独立的
  <project-instructions> 用户消息,不带免责声明,置于消息列表最前面
- queryModel: deferred tools 消息从 prepend 改为 append,避免抢占
  project-instructions 的最高权重位置;标签规范化为 <system-reminder>

Co-Authored-By: glm-5-turbo <zai-org@claude-code-best.win>
This commit is contained in:
claude-code-best 2026-05-09 17:50:15 +08:00 committed by James Feng
parent a308aa8fcc
commit 35927b20ad
2 changed files with 31 additions and 12 deletions

View File

@ -1411,12 +1411,14 @@ async function* queryModel(
.sort()
.join('\n')
if (deferredToolList) {
// Append to the end of the messages array (not prepend) so it
// never抢占 <project-instructions> (CLAUDE.md) at the front.
messagesForAPI = [
...messagesForAPI,
createUserMessage({
content: `<system-reminder>\n<available-deferred-tools>\n${deferredToolList}\n</available-deferred-tools>\nIMPORTANT: The tools listed above are deferred-loading — they are NOT in your tool list. To use them, you MUST first discover a tool via SearchExtraTools, then invoke it with ExecuteExtraTool.\n\nSearchExtraTools and ExecuteExtraTool are core tools already in your tool list right now — call them directly, do NOT use Bash/Glob to find them.\n\nSteps:\n1. SearchExtraTools({"query": "select:<tool_name>"}) — discover the tool and its schema\n2. ExecuteExtraTool({"tool_name": "<name>", "params": {...}}) — invoke it with correct parameters\n</system-reminder>`,
isMeta: true,
}),
...messagesForAPI,
]
}
}

View File

@ -458,19 +458,36 @@ export function prependUserContext(
return messages
}
return [
createUserMessage({
content: `<system-reminder>\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 <system-reminder> 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: `<project-instructions>\n${claudeMd}\n</project-instructions>\n`,
isMeta: true,
}),
)
}
const restEntries = Object.entries(rest)
if (restEntries.length > 0) {
result.push(
createUserMessage({
content: `<system-reminder>\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</system-reminder>\n`,
isMeta: true,
}),
...messages,
]
isMeta: true,
}),
)
}
return [...result, ...messages]
}
/**