When using systemPrompt with a newline character (\n) on Windows, the PermissionMode does not work as expected.
Reproduction Steps
-
Initialize ClaudeSyncClient with PermissionMode.BYPASS_PERMISSIONS
-
Case 1 (Works correctly): Do not set systemPrompt (or set it without \n)
- Code snippet:
try (ClaudeSyncClient client = ClaudeClient.sync()
.workingDirectory(Path.of("."))
.model(MODEL_HAIKU)
.permissionMode(PermissionMode.BYPASS_PERMISSIONS)
.build()) {
client.connect("hi");
Iterator<ParsedMessage> response = client.receiveResponse();
while (response.hasNext()) {
ParsedMessage msg = response.next();
if (msg.isRegularMessage() && msg.asMessage() instanceof SystemMessage system) {
String permissionMode = (String) system.data().get("permissionMode");
System.out.println(permissionMode);
}
}
} catch (Exception e) {
// ignore
}
- Output:
bypassPermissions (expected)
-
Case 2 (Abnormal behavior): Set systemPrompt with \n (e.g., "You are an AI assistant.\n")
- Code snippet:
public static void main(String[] args) {
try (ClaudeSyncClient client = ClaudeClient.sync()
.workingDirectory(Path.of("."))
.model(MODEL_HAIKU)
.systemPrompt("You are an AI assistant.\n")
.permissionMode(PermissionMode.BYPASS_PERMISSIONS)
.build()) {
client.connect("hi");
Iterator<ParsedMessage> response = client.receiveResponse();
while (response.hasNext()) {
ParsedMessage msg = response.next();
if (msg.isRegularMessage() && msg.asMessage() instanceof SystemMessage system) {
String permissionMode = (String) system.data().get("permissionMode");
System.out.println(permissionMode);
}
}
} catch (Exception e) {
// ignore
}
}
- Output:
default (unexpected, should be bypassPermissions)
Environment
- OS: Windows
- Key issue: The existence of
\n in systemPrompt causes PermissionMode to not be applied correctly.
When using
systemPromptwith a newline character (\n) on Windows, thePermissionModedoes not work as expected.Reproduction Steps
Initialize
ClaudeSyncClientwithPermissionMode.BYPASS_PERMISSIONSCase 1 (Works correctly): Do not set
systemPrompt(or set it without\n)bypassPermissions(expected)Case 2 (Abnormal behavior): Set
systemPromptwith\n(e.g.,"You are an AI assistant.\n")default(unexpected, should bebypassPermissions)Environment
\ninsystemPromptcausesPermissionModeto not be applied correctly.