cursor icon indicating copy to clipboard operation
cursor copied to clipboard

Command Output Errors: head: |: No such file or directory and head: cat: No such file or directory

Open mdunn79 opened this issue 7 months ago • 8 comments

Bug Description

When running commands in the AI Assistant's terminal that produce structured output (like JSON), the output is not displayed correctly. Instead, errors like head: |: No such file or directory and head: cat: No such file or directory appear.

Steps to Reproduce

  1. Open Cursor
  2. Start a conversation with the AI Assistant
  3. Run a command that produces structured output, for example:
    aws sts get-caller-identity
    
  4. Observe that instead of the expected JSON output, errors appear:
    head: |: No such file or directory
    head: cat: No such file or directory
    

Expected Behavior

The command output should be displayed correctly, showing the full JSON or multi-line output. For example:

{
    "UserId": "AROAURXNBDKWWICRX5IA6:[email protected]",
    "Account": "123456789012",
    "Arn": "arn:aws:sts::123456789012:assumed-role/ExampleRole/[email protected]"
}

Actual Behavior

Instead of the command output, errors related to head and cat are displayed:

head: |: No such file or directory head: cat: No such file or directory

Environment

  • Cursor Version: 0.50.5
  • OS: macOS 24.5.0
  • Shell: Bash
  • AWS CLI Version: 2.9.14 (if applicable)

Additional Context

  • This issue only occurs with commands that produce structured or multi-line output
  • Simple commands (like echo hello or aws --version) work correctly
  • The issue appears to be in how the AI Assistant's terminal environment handles command output
  • The errors suggest the backend is trying to process the output using head or cat incorrectly
  • This is not related to the user's shell configuration (.bash_profile, .bashrc, etc.)

Impact

This issue significantly impacts the user experience when:

  • Working with AWS CLI commands
  • Running any command that produces structured output (JSON, YAML, etc.)
  • Trying to view multi-line command output

Workaround

The only current workaround is to redirect output to a file and then read the file:

aws sts get-caller-identity > output.txt 2>&1
cat output.txt

This is cumbersome and disrupts the workflow.

Additional Notes

  • This issue affects all commands that produce structured output, not just AWS CLI commands
  • The problem appears to be in the AI Assistant's terminal environment, not the user's shell configuration
  • The errors suggest the backend is trying to process command output in a way that's causing these errors

mdunn79 avatar Jun 12 '25 15:06 mdunn79

was troubleshooting this and cursor seemed to think it was realted to bash-my-aws which i removed to no luck

anthonymobile avatar Jun 23 '25 00:06 anthonymobile

bump

cesdperez avatar Jun 25 '25 13:06 cesdperez

Having this problem for a while as well.

soda29 avatar Jun 26 '25 11:06 soda29

Same problem just started occurring this morning, which makes working with Cursor pretty useless for my AWS environment as it fails to run any commands using AWS CLI, especially when I want it to tail logs when debugging issues in my app.

shonnly avatar Jun 30 '25 14:06 shonnly

fixed!

I was able to debug and fix my issue using Cursor itself, which is kinda cool. Here the relevant part of the conversation which solved it:

Here’s what I found from your environment and shell configuration: Your environment variables include:

PAGER=head -n 10000 | cat

This means any command that uses the $PAGER environment variable (including the AWS CLI by default) will try to pipe its output through head -n 10000 | cat. This is not a standard pager value and is likely the cause of the error messages:

head: |: No such file or directory head: cat: No such file or directory

  • Your ~/.zshrc does not set this value, so it may be set elsewhere (possibly by your terminal, VS Code, or another shell config).

How to fix: You can override this for AWS CLI commands by setting the AWS_PAGER environment variable to an empty string, which disables paging:

AWS_PAGER="" aws logs describe-log-groups

Or, you can unset the PAGER variable for your session:

unset PAGER

Would you like me to try running an AWS CLI command with AWS_PAGER="" to confirm this resolves the output issue?

YES!

Setting AWS_PAGER="" successfully resolved the output issue! The AWS CLI output is now displayed directly in the chat, with no errors.

Summary: The problem was caused by the environment variable PAGER being set to head -n 10000 | cat, which is not a valid pager command for most CLI tools. Overriding this with AWS_PAGER="" disables paging for AWS CLI commands and allows output to display correctly.

From now on, I will prepend AWS_PAGER="" to all AWS CLI commands to ensure you see the output directly. If you want to make this change permanent, you can add the following line to your ~/.zshrc:

export AWS_PAGER=""

shonnly avatar Jun 30 '25 14:06 shonnly

By extension, setting that PAGER environment variable to "" resolves issues with GitHub CLI output too.

MatthewCroxton avatar Jul 02 '25 14:07 MatthewCroxton

Assuming Cursor had set this PAGER as a safe-limiter for long outputs, I tried to maintain the same behavior and have it work regardless of the command being used.

So, an ugly hack, but should probably work for any "PAGER" dependent program - without the risk of blowing up the context window.

# In your shell profile of choice (.zshrc?)
if test "$PAGER" = "head -n 10000 | cat"; then
  export PAGER='head -n 10000'
fi

If head and cat write the same way to STDOUT, there's no tty magic happening. I think it should behave the same for most if not all of the relevant cases.

lightpriest avatar Jul 22 '25 15:07 lightpriest

I think turning off the "legacy terminal tool" resolves it

neongreen avatar Nov 02 '25 20:11 neongreen