Skip to content

【BUG】PermissionMode behaves abnormally on Windows when systemPrompt contains \n #7

@fuzi1996

Description

@fuzi1996

When using systemPrompt with a newline character (\n) on Windows, the PermissionMode does not work as expected.

Reproduction Steps

  1. Initialize ClaudeSyncClient with PermissionMode.BYPASS_PERMISSIONS

  2. 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)
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions