Cursor agent mode - when running terminal commands often hangs up the terminal, requiring a click to pop it out in order to continue commands

This was a huge help! Thanks!

I does work indeed, thank you!

Just wanted to drop by and say thank you as this is my exact setup and the exact problem I was having! Cheers!

I think this fixed the issue for me as well. Note that these instructions work just fine with bash:

[[ "$TERM_PROGRAM" == "vscode" ]] && . "$(code --locate-shell-integration-path bash --user-data-dir='.' --no-sandbox)"

Or omit the --no-sandbox directive if you’re using WSL2 on Windows with the vscode remote server integration.

1 Like

You don’t even need to turn off p10k (Powerlevel10k)! It’s actually instant prompt that’s causing the issue.

Add this snippet to the very top of your ~/.zshrc file:

if [[ "$TERM_PROGRAM" == "vscode" ]]; then
  POWERLEVEL9K_INSTANT_PROMPT=off
fi

It’s actually instant prompt that’s causing the issue.

if [[ "$TERM_PROGRAM" == "vscode" ]]; then
 POWERLEVEL9K_INSTANT_PROMPT=off
fi

Unfortunately, this didn’t work for me.

I’m curious how people are even using Cursor. Are they not getting this error?

Hi @macdonjo, and welome to the forum.

Right, while some have the issue, most users do not. Probably because not all user Powerlevel10k or they just use default shell, so it doesnt affect them.

I personally use PowerLevel10k in zsh and have no issues in Cursor with the shell.

If the above mentioned solutions do not fix it in your case, please file a detailed bug report so your specific issue can be reviewed.

I’m using the default shell and it hangs. Have verified this after doing over 1000 requests in the past 1 week. I’ll file a detailed bug report.

1 Like

@T1000 I have the same error with terminal hanging and it’s devastating.
I have oh my zsh and PowerLevel10k
Will try to fill in the detailed bug report but you have to be aware that it’s ruining the UX for the considerable chunk of the users

UPD: I managed to fix the problem - my .zshrc was too complicated and the regular fixes on the top of the file wasn’t turning off all of the power tools for the Cursor terminal

Pro tip - just ask Claude in Cursor to check your .zshrc file and provide the link to this thread
What a time to be alive! :smiley:

2 Likes

I can’t edit my original comment. This didn’t actually work, or at least didn’t work completely, as I am still regularly getting this issue. Along with the dreaded connection failures, with model name “unknown”, that force you to restart Cursor. Switching to HTTP 1.1 over HTTP2 didn’t fix that either.

I’m having the same issue, and it only started happening on release of version 1.0

:bullseye: More Precise Solution: Keep Powerlevel10k in IDE Terminal

@BoboChen’s solution works great, but I found it also disables Powerlevel10k in Cursor’s built-in IDE terminal, which isn’t ideal if you want the full theme experience there.

:magnifying_glass_tilted_left: The Issue with Broad Detection

Using TERM_PROGRAM == "vscode" affects both:

  • :cross_mark: Agent terminals (where we want minimal config)
  • :cross_mark: IDE built-in terminal (where we want full Powerlevel10k)

:sparkles: Better Solution: Use VSCODE_SHELL_INTEGRATION

After testing environment variables, I discovered that VSCODE_SHELL_INTEGRATION is the perfect differentiator:

Environment VSCODE_SHELL_INTEGRATION
Agent Terminal '1'
IDE Built-in Terminal '' (empty)

:hammer_and_wrench: Updated .zshrc Configuration

Replace the detection logic with this more precise version:

# Agent detection - only activate minimal mode for actual agents  
if [[ -n "$VSCODE_SHELL_INTEGRATION" ]]; then
  POWERLEVEL9K_INSTANT_PROMPT=off
  # Disable complex prompt features for AI agents
  POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir vcs)
  POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=()
  # Ensure non-interactive mode
  export DEBIAN_FRONTEND=noninteractive
  export NONINTERACTIVE=1
fi

# Your existing Powerlevel10k instant prompt setup...
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
  source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi

# Theme selection - disable only for agents
if [[ -n "$VSCODE_SHELL_INTEGRATION" ]]; then
  ZSH_THEME=""  # Disable Powerlevel10k for agents
else
  ZSH_THEME="powerlevel10k/powerlevel10k"  # Full theme for IDE terminal
fi

# Later in your .zshrc - minimal prompt for agents
if [[ -n "$VSCODE_SHELL_INTEGRATION" ]]; then
  PROMPT='%n@%m:%~%# '
  RPROMPT=''
  unsetopt CORRECT
  unsetopt CORRECT_ALL
  setopt NO_BEEP
  setopt NO_HIST_BEEP  
  setopt NO_LIST_BEEP
  
  # Agent-friendly aliases
  alias rm='rm -f'
  alias cp='cp -f' 
  alias mv='mv -f'
  alias npm='npm --no-fund --no-audit'
  alias yarn='yarn --non-interactive'
  alias pip='pip --quiet'
  alias git='git -c advice.detachedHead=false'
else
  [[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
fi

:tada: Results

  • :white_check_mark: Agent terminals: No hangs, minimal prompt, fast startup
  • :white_check_mark: IDE built-in terminal: Full Powerlevel10k theme and functionality
  • :white_check_mark: Clean separation: Only agents get the minimal config

This approach gives you the best of both worlds - preventing agent hangs while preserving your beautiful terminal experience in the IDE!

Hope this helps others who want to keep their full terminal setup in the IDE. :rocket:

3 Likes

Made an account to say thanks. Works great.

:counterclockwise_arrows_button: CORRECTION: Updated Solution for Cursor Agent vs IDE Terminal Detection

Update: My original solution using VSCODE_SHELL_INTEGRATION was incorrect. After deeper testing, I discovered the actual environment differences. Here’s the working solution:

:cross_mark: Why My Original Solution Was Wrong

I originally claimed that VSCODE_SHELL_INTEGRATION differentiates between terminals:

  • :cross_mark: Agent Terminal: VSCODE_SHELL_INTEGRATION='1'
  • :cross_mark: IDE Built-in Terminal: VSCODE_SHELL_INTEGRATION=''

This was incorrect. Both terminals actually have VSCODE_SHELL_INTEGRATION='' (empty).

:white_check_mark: The Real Differentiator: npm_config_yes

After extensive environment variable comparison, the actual differentiator is:

Environment npm_config_yes
Agent Terminal ‘true’
IDE Built-in Terminal (absent)

:hammer_and_wrench: Corrected .zshrc Configuration

Replace your detection logic with this tested and working version:

# Agent detection - only activate minimal mode for actual agents  
if [[ -n "$npm_config_yes" ]] || [[ -n "$CI" ]] || [[ "$-" != *i* ]]; then
  export AGENT_MODE=true
else
  export AGENT_MODE=false
fi

if [[ "$AGENT_MODE" == "true" ]]; then
  POWERLEVEL9K_INSTANT_PROMPT=off
  # Disable complex prompt features for AI agents
  POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir vcs)
  POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=()
  # Ensure non-interactive mode
  export DEBIAN_FRONTEND=noninteractive
  export NONINTERACTIVE=1
fi

# Enable Powerlevel10k instant prompt only when not in agent mode
if [[ "$AGENT_MODE" != "true" ]] && [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
  source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi

# Set Oh My Zsh theme conditionally - disable for agents only
if [[ "$AGENT_MODE" == "true" ]]; then
  ZSH_THEME=""  # Disable Powerlevel10k for agents
else
  ZSH_THEME="powerlevel10k/powerlevel10k"
fi

# Later in your .zshrc - minimal prompt for agents
if [[ "$AGENT_MODE" == "true" ]]; then
  PROMPT='%n@%m:%~%# '
  RPROMPT=''
  unsetopt CORRECT
  unsetopt CORRECT_ALL
  setopt NO_BEEP
  setopt NO_HIST_BEEP  
  setopt NO_LIST_BEEP
  
  # Agent-friendly aliases to avoid interactive prompts
  alias rm='rm -f'
  alias cp='cp -f' 
  alias mv='mv -f'
  alias npm='npm --no-fund --no-audit'
  alias yarn='yarn --non-interactive'
  alias pip='pip --quiet'
  alias git='git -c advice.detachedHead=false'
else
  [[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
fi

:test_tube: How I Discovered This

The agent terminal sets several automation-friendly variables:

npm_config_yes=true                    # Auto-yes for npm prompts
DISABLE_AUTO_UPDATE=true               # Disable package updates  
PIP_NO_INPUT=true                      # No pip interactive prompts
COMPOSER_NO_INTERACTION=1              # No composer prompts
PAGER=head -n 10000 | cat             # Limited output pager

The npm_config_yes=true is the most reliable discriminator as it’s specifically set to enable non-interactive npm operations in agent contexts.

:white_check_mark: Verified Results

  • :white_check_mark: Agent terminals: No hangs, minimal prompt, fast startup
  • :white_check_mark: IDE built-in terminal: Full Powerlevel10k theme and functionality
  • :white_check_mark: Clean separation: Only agents get the minimal config
  • :white_check_mark: Tested extensively: Works reliably across shell restarts

:magnifying_glass_tilted_left: Debugging Your Setup

To verify this works in your environment:

Agent terminal (should show):

❯ echo "AGENT_MODE: $AGENT_MODE, npm_config_yes: $npm_config_yes"
AGENT_MODE: true, npm_config_yes: true

IDE terminal (should show):

❯ echo "AGENT_MODE: $AGENT_MODE, npm_config_yes: $npm_config_yes"  
AGENT_MODE: false, npm_config_yes:

This corrected solution provides the perfect balance - preventing agent hangs while preserving your beautiful terminal experience in the IDE! :rocket:


Sorry for the confusion in my original post - this updated solution is thoroughly tested and working!

5 Likes

I think the best solution would be if Cursor would allow to customize the terminal settings, e.g. by allowing to use a custom terminal setup for Cursor or only switch to bash for Cursor Agent.

1 Like

This is awesome. Thanks a lot, tested this and its working. Great work, compiling this.

@justice47 - thanks for your pro tip as well :sweat_smile:

1 Like

great find! thanks!

Thanks a lot! I just commented out this line :sweat_smile:

alias rm='rm -f'
1 Like

Thanks this is working for me.

1 Like