[BUG] Terminal tool gets stuck after exit code

I noticed one of the agents started doing this on its own, I wonder if it discovered the bug and found a workaround :rofl:

This was really insightful and allowed me to build a fix for my most common issue: mostly what it gets stuck on is running my test suite. I already run the tests using a shell script, so now I have the shell script write to a log and just output the logfile name to the terminal, which the LLM can then just read.

So far that’s been keeping it from hanging.

Is there a fix for this yet?!?! This is like total work stoppage for me when it goes into these phases and stops working.

I’m also impacted and it’s been really annoying. I changed everything, from fish to zsh to bash. It seems removing all prompt customizations really helps it, both starship and oh-my-posh makes it worse. But I want to keep my prompt.

I was having the same issue (the cursor agent would execute a terminal command, it would successfully run, but then the agent would not continue until I clicked ā€˜cancel’).

This issue went away when I changed my terminal to have a more standard appearance/theme. I had previously been using oh-my-bash with a theme. When I either turn off the theme, or uninstall oh-my-bash, the cursor agent successfully detects the completion of terminal commands.

Terminal setup with cursor agent working properly:

Terminal setup with where cursor agent hangs on executing terminal commands:

Cursor version:
Version: 0.48.9
VSCode Version: 1.96.2
Commit: 61e99179e4080fecf9d8b92c6e2e3e00fbfb53f0
Date: 2025-04-12T18:33:49.349Z (4 days ago)
Electron: 34.3.4
Chromium: 132.0.6834.210
Node.js: 20.18.3
V8: 13.2.152.41-electron.0
OS: Darwin arm64 24.3.0

These settings helped me:

{
"terminal.integrated.shellIntegration.enabled": true,
"terminal.integrated.defaultProfile.osx": "bash",
"terminal.integrated.defaultProfile.linux": "bash",
"cursor.terminal.usePreviewBox": true,
"terminal.integrated.automationProfile.osx": {},
}

(i am on macos)

1 Like

The entire terminal intigration is dirty and should be cleaned. This was probably taken 1:1 from VScode, but that does not work for the IDE for cursors, makes the agent partially blind and causes race conditions. Powershell without customization is an imposition. Use Powershell 7.5 and remove the content from shellIntegration.ps1 and remove the content of shellIntegration.ps1 and replace it with

# ---------------------------------------------------------------------------------------------
#   Copyright (c) Microsoft Corporation. All rights reserved.
#   Licensed under the MIT License. See License.txt in the project root for license information.
# ---------------------------------------------------------------------------------------------

# Deactivates the VS Code Shell integration in PowerShell
$Global:__VSCodeOriginalPrompt = $function:Prompt

# Defines a cleaned prompt function without escape sequences
function Global:Prompt() {
    return $Global:__VSCodeOriginalPrompt.Invoke()
}

# Prevents PSReadLine overwriting and removes VS code-specific handlers
if (Get-Module -Name PSReadLine) {
    # Resetting the PSConsoleHostReadLine function
    if ($null -ne $__VSCodeOriginalPSConsoleHostReadLine) {
        $function:PSConsoleHostReadLine = $__VSCodeOriginalPSConsoleHostReadLine
    }
    # Remove all VS Code keybindings
    Remove-PSReadLineKeyHandler -Chord 'F12,e' -ErrorAction SilentlyContinue
    Remove-PSReadLineKeyHandler -Chord 'F12,f' -ErrorAction SilentlyContinue
}

Write-Host "Shell integration has been deactivated."

# Cleanup of all VS Code-specific environment variables.
# Does not completely remove VSCode, partially resets it.
$env:VSCODE_NONCE = $null
$env:VSCODE_STABLE = $null
$env:VSCODE_ENV_REPLACE = $null
$env:VSCODE_ENV_PREPEND = $null
$env:VSCODE_ENV_APPEND = $null

# Native PowerShell autocompletion without OSC-633 sequences
function Send-Completions {
    $commandLine = ""
    $cursorIndex = 0
    [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$commandLine, [ref]$cursorIndex)
    
    # Use standard TabExpansion2 for completions
    try {
        $completions = TabExpansion2 -inputScript $commandLine -cursorColumn $cursorIndex -ErrorAction Stop
        if ($completions -and $completions.CompletionMatches) {
            $completions.CompletionMatches | ForEach-Object {
                Write-Output $_.CompletionText
            }
        }
    } catch {
        Write-Error "Error during completion: $_"
    }
}

# Final confirmation
Write-Host "Terminal is now AI-compatible. No VS Code specific functions active."

It’s not perfect but works much better.
Caution! Powershell is very powerful and is loaded in the user context of the user and their Powershell profile.
You should actually restrict it, for example with

  • Set PowerShell Execution Policy
  • Activate PowerShell Constrained Language Mode
  • Restrict PowerShell profiles
  • Command whitelisting (shell wrapper) or via Cursor Settings

or you choose a secure shell like the cmd

I’m noticing the issue crops up when the terminal output for a given command is large.

Hey all,

I might have found an at least temporary solution for me (macos, zsh):
While inspecting the terminal profiles, this caught my eye:

  "terminal.integrated.defaultProfile.osx": "zsh",
  "terminal.integrated.shellIntegration.enabled": false, <-------- !!!
  "terminal.integrated.defaultProfile.linux": "bash",
  "cursor.composer.shouldChimeAfterChatFinishes": true,

I tried changing that to true, and so far I have not encountered a single terminal hang in Agent mode ever since.

Hope this helps at least some of you until an official fix is out.

4 Likes

Haven’t experienced this issue yet in 0.49. :tada:

I’m currently facing this issue…

Guys, I’m having the same issue. It is really weird, because it was working a couple of weeks ago

Thank you! This works for me as well!

I had to tune things a bit (some PATH setup in order to make commands like nvm work)

But I’m still insisting on prioritising this issue. I spend some amount of my requests quota because of it

Im having the same problem on Windows. Works fine on mac

I have the same issue. Started to appear today. Sometimes it gets ā€œunstuckā€ after some time but most of the time I have to copy the output and ā€œwasteā€ a new prompt…

needs to be prioritized still present in 0.50

2 Likes

+1, macos, zsh powerlevel10k

Here is a fix: Agent not detecting that a command has completed - #18 by LQrX6PXc4