copilot-cli icon indicating copy to clipboard operation
copilot-cli copied to clipboard

`~/.bash_history` is truncated.

Open your-diary opened this issue 2 months ago • 2 comments

Describe the bug

It seems copilot executes shell commands via bash without first loading ~/.bashrc.

So, even if users explictly set HISTFILESIZE=-1 in ~/.bashrc to customize the max number of lines of ~/.bash_history, running a shell command once via copilot truncates ~/.bash_history to 1000 lines or so.

This problem does not occur on codex.

Affected version

0.0.352 Commit: e743766

Steps to reproduce the behavior

  1. In one terminal, check the number of lines of ~/.bash_history.

    In my case:

    $ wc -l ~/.bash_history
    
    375136 /Users/user/.bash_history
    
  2. In another terminal, run copilot and type Run "echo hello".

  3. Then copilot runs echo hello for you.

  4. In the terminal used in the step 1, re-check the number of lines

    $ wc -l ~/.bash_history
    
    1004 /Users/user/.bash_history
    

By the way, after the truncation, ~/.bash_history includes

{
    echo ___BEGIN___COMMAND_OUTPUT_MARKER___;
    PS1="";
    PS2="";
    EC=$?;
    echo "___BEGIN___COMMAND_DONE_MARKER___$EC";
}

, which I'm sure is derived from copilot:

$ rg -o '___BEGIN___COMMAND_OUTPUT_MARKER___' ~/.npm/bin/copilot

995:___BEGIN___COMMAND_OUTPUT_MARKER___

Expected behavior

~/.bash_history should not be truncated.

Additional context

No response

your-diary avatar Nov 07 '25 08:11 your-diary

Hey @your-diary, thanks for reaching out! You're right that we're running bash with the --no-rc and --noprofile flags to execute shell tool calls. We discussed this and came to the conclusion that we shouldn't be writing to bash_history at all for the shell tool calls as we wrap them with a bunch of boilerplate to simplify parsing so they end up not being suited for shell reuse anyway. I've got a PR open to suppress writing to history which will also fix your truncation issue. I'll update once it's been merged

niik avatar Nov 12 '25 13:11 niik

Hi @niik thanks for the excellent tool. Writing stuff to bash_history is a bit disruptive in particular when using Ctrl+r to navigate my history.

My workaround at the minute is to do the following:

export HISTFILE=/tmp/dontcare && copilot

ahmaze avatar Nov 27 '25 11:11 ahmaze

I've got a PR open to suppress writing to history which will also fix your truncation issue. I'll update once it's been merged

Following up to say this got merged and was published in version 0.0.362! copilot shouldn't write to bash or powershell history any more. Thanks for the kind words, gonna close this out!

niik avatar Dec 05 '25 12:12 niik