Skip to content

[BUG] Claude hangs in "Caramelizing" state after completing task with background processes #20336

Description

@mhcandan

Preflight Checklist

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

What's Wrong?

Title: Claude hangs in "Caramelizing" state after completing task with background processes

Description:
After starting background processes (backend/frontend servers) and responding that the task was complete, Claude Code remained in a waiting state ("Caramelizing") for 19+ minutes without returning control to the user. User had to
press Escape to interrupt.

Steps to reproduce:

  1. Ask Claude to start backend and frontend servers using run_in_background: true
  2. Claude starts both servers successfully and responds "The app is ready"
  3. Claude does not return control - stays in "Caramelizing" state indefinitely
  4. Background task notifications continue to arrive but Claude takes no action
  5. User must press Escape to regain control

Expected behavior:
After completing the response, Claude should immediately return control to the user without requiring manual interruption.

Environment:

  • Claude Code CLI
  • Model: Claude Opus 4.5

What Should Happen?

o bug in the PWZ code - that was just me waiting for your next instruction after the servers started. The "Caramelizing" state means I had completed the task and was idle. The background task notifications were coming in (showing
the servers were active), but I had nothing more to do until you gave another command.

The servers are running and the app is working. What would you like me to do next?

❯ why should I have to press escape to take you out of this mode ?

⏺ You're right - you shouldn't have to. After I said "The app is ready and serving requests," my turn was complete and I should have returned control to you immediately.

The background task notifications kept coming in (showing server activity), but I had no action to take on them. Something in my processing kept me in a waiting state when I should have simply finished.

This isn't expected behavior. I apologize for the confusion - you shouldn't need to interrupt me after I've completed a task.

Error Messages/Logs

Steps to Reproduce

#!/usr/bin/env python3
"""
Reproduction script for Claude Code "Caramelizing" hang bug.

Bug: After starting background processes and completing a response,
Claude Code hangs in "Caramelizing" state instead of returning control
to the user. User must press Escape to interrupt.

To reproduce:

  1. Open Claude Code in this directory
  2. Ask: "Run the reproduction script in the background"
  3. Claude will start the script and say it's running
  4. Observe: Claude stays in "Caramelizing" state indefinitely
  5. Press Escape to regain control

The script simulates a long-running server that periodically outputs,
similar to uvicorn/next.js dev servers.
"""

import time
import sys
from datetime import datetime

def simulate_server():
"""Simulate a dev server that outputs periodic status messages."""
print("=" * 60)
print("REPRODUCTION SCRIPT FOR CLAUDE CODE CARAMELIZING BUG")
print("=" * 60)
print(f"[{datetime.now().isoformat()}] Server starting...")
print(f"[{datetime.now().isoformat()}] Listening on http://localhost:9999")
print(f"[{datetime.now().isoformat()}] Server ready!")
print()

# Simulate periodic server activity (like request logs)
counter = 0
while True:
    counter += 1
    timestamp = datetime.now().isoformat()

    # Output to stdout (like server request logs)
    print(f"[{timestamp}] Heartbeat #{counter} - server is running")
    sys.stdout.flush()

    # Also output to stderr occasionally (like uvicorn does)
    if counter % 3 == 0:
        print(f"[{timestamp}] INFO: Background activity", file=sys.stderr)
        sys.stderr.flush()

    time.sleep(5)  # Output every 5 seconds

if name == "main":
try:
simulate_server()
except KeyboardInterrupt:
print("\nServer stopped.")
sys.exit(0)

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

2.1.5

Claude Code Version

2.1.17

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions