[BUG] Process Hangs Indefinitely When Reading InputStream from Claude Code Headless Execution

Resolved 💬 5 comments Opened Sep 12, 2025 by Lroyia Closed Jan 7, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Description:

I'm experiencing a blocking issue when trying to execute Claude Code in headless mode using Java's ProcessBuilder. The Node.js process starts successfully (confirmed via system task manager), but my Java application hangs indefinitely while reading from the input stream, even after waiting 24+ hours.

Code Snippet:

ProcessBuilder processBuilder = new ProcessBuilder("claude", "-p", prompt, "--output-format", "stream-json", "--dangerously-skip-permissions", "--verbose");  
processBuilder.directory(file);  
Process process = processBuilder.start();  
 
// print inputstream
new Thread(() -> handleStream(process.getInputStream())).start();  
 
// print errorstream  
new Thread(() -> handleStream(process.getErrorStream())).start();  
process.waitFor();  
int exitCode = process.exitValue();

private void handleStream(InputStream inputStream) {
        try (BufferedReader reader = new BufferedReader(
                new InputStreamReader(inputStream, "GBK"))) { 
            String line;
            while ((line = reader.readLine()) != null) {
                log.info(line); 
            }
        } catch (IOException e) {
            log.error("io exception", e);
        }
}

Environment:

JDK: OpenJDK 21 HotSpot
OS: Windows & Linux (reproducible on both)
Node.js: v22.19.0
Claude Code: 1.0.112

What Should Happen?

Claude should stably output to the Java program via stdio and terminate the program normally.

Error Messages/Logs

Steps to Reproduce

ProcessBuilder processBuilder = new ProcessBuilder("claude", "-p", prompt, "--output-format", "stream-json", "--dangerously-skip-permissions", "--verbose");  
processBuilder.directory(file);  
Process process = processBuilder.start();  
 
// print inputstream
new Thread(() -> handleStream(process.getInputStream())).start();  
 
// print errorstream  
new Thread(() -> handleStream(process.getErrorStream())).start();  
process.waitFor();  
int exitCode = process.exitValue();

private void handleStream(InputStream inputStream) {
        try (BufferedReader reader = new BufferedReader(
                new InputStreamReader(inputStream, "GBK"))) { 
            String line;
            while ((line = reader.readLine()) != null) {
                log.info(line); 
            }
        } catch (IOException e) {
            log.error("io exception", e);
        }
}

Claude Model

Other

Is this a regression?

Yes, this worked in a previous version

Last Working Version

_No response_

Claude Code Version

1.0.112

Platform

Anthropic API

Operating System

Ubuntu/Debian Linux

Terminal/Shell

Other

Additional Information

_No response_

View original on GitHub ↗

This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗