Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
31f817d1
Commit
31f817d1
authored
Jan 29, 2026
by
cyhhao
Browse files
fix: add newline separation for Claude Code system prompt
parent
59231668
Changes
2
Hide whitespace changes
Inline
Side-by-side
backend/internal/service/account_test_service.go
View file @
31f817d1
...
@@ -123,7 +123,7 @@ func createTestPayload(modelID string) (map[string]any, error) {
...
@@ -123,7 +123,7 @@ func createTestPayload(modelID string) (map[string]any, error) {
"system"
:
[]
map
[
string
]
any
{
"system"
:
[]
map
[
string
]
any
{
{
{
"type"
:
"text"
,
"type"
:
"text"
,
"text"
:
"You are C
laude
Code
, Anthropic's official CLI for Claude."
,
"text"
:
c
laudeCode
SystemPrompt
,
"cache_control"
:
map
[
string
]
string
{
"cache_control"
:
map
[
string
]
string
{
"type"
:
"ephemeral"
,
"type"
:
"ephemeral"
,
},
},
...
...
backend/internal/service/gateway_service.go
View file @
31f817d1
...
@@ -39,7 +39,9 @@ const (
...
@@ -39,7 +39,9 @@ const (
claudeAPICountTokensURL
=
"https://api.anthropic.com/v1/messages/count_tokens?beta=true"
claudeAPICountTokensURL
=
"https://api.anthropic.com/v1/messages/count_tokens?beta=true"
stickySessionTTL
=
time
.
Hour
// 粘性会话TTL
stickySessionTTL
=
time
.
Hour
// 粘性会话TTL
defaultMaxLineSize
=
40
*
1024
*
1024
defaultMaxLineSize
=
40
*
1024
*
1024
claudeCodeSystemPrompt
=
"You are Claude Code, Anthropic's official CLI for Claude."
// Keep a trailing blank line so that when upstream concatenates system strings,
// the injected Claude Code banner doesn't run into the next system instruction.
claudeCodeSystemPrompt
=
"You are Claude Code, Anthropic's official CLI for Claude.
\n\n
"
maxCacheControlBlocks
=
4
// Anthropic API 允许的最大 cache_control 块数量
maxCacheControlBlocks
=
4
// Anthropic API 允许的最大 cache_control 块数量
)
)
...
@@ -2479,7 +2481,8 @@ func injectClaudeCodePrompt(body []byte, system any) []byte {
...
@@ -2479,7 +2481,8 @@ func injectClaudeCodePrompt(body []byte, system any) []byte {
case
nil
:
case
nil
:
newSystem
=
[]
any
{
claudeCodeBlock
}
newSystem
=
[]
any
{
claudeCodeBlock
}
case
string
:
case
string
:
if
v
==
""
||
v
==
claudeCodeSystemPrompt
{
// Be tolerant of older/newer clients that may differ only by trailing whitespace/newlines.
if
strings
.
TrimSpace
(
v
)
==
""
||
strings
.
TrimSpace
(
v
)
==
strings
.
TrimSpace
(
claudeCodeSystemPrompt
)
{
newSystem
=
[]
any
{
claudeCodeBlock
}
newSystem
=
[]
any
{
claudeCodeBlock
}
}
else
{
}
else
{
newSystem
=
[]
any
{
claudeCodeBlock
,
map
[
string
]
any
{
"type"
:
"text"
,
"text"
:
v
}}
newSystem
=
[]
any
{
claudeCodeBlock
,
map
[
string
]
any
{
"type"
:
"text"
,
"text"
:
v
}}
...
@@ -2489,7 +2492,7 @@ func injectClaudeCodePrompt(body []byte, system any) []byte {
...
@@ -2489,7 +2492,7 @@ func injectClaudeCodePrompt(body []byte, system any) []byte {
newSystem
=
append
(
newSystem
,
claudeCodeBlock
)
newSystem
=
append
(
newSystem
,
claudeCodeBlock
)
for
_
,
item
:=
range
v
{
for
_
,
item
:=
range
v
{
if
m
,
ok
:=
item
.
(
map
[
string
]
any
);
ok
{
if
m
,
ok
:=
item
.
(
map
[
string
]
any
);
ok
{
if
text
,
ok
:=
m
[
"text"
]
.
(
string
);
ok
&&
text
==
claudeCodeSystemPrompt
{
if
text
,
ok
:=
m
[
"text"
]
.
(
string
);
ok
&&
strings
.
TrimSpace
(
text
)
==
strings
.
TrimSpace
(
claudeCodeSystemPrompt
)
{
continue
continue
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment