Skip to content

[Bug]: Duplicate text when using CodeCompanionChat Add to add text when loading plugin for the first time #1658

@Aqothy

Description

@Aqothy

Did you check the docs and existing issues?

  • I have read all the docs
  • I have updated the plugin to the latest version before submitting this issue
  • I have searched for existing issues/discussions
  • I have searched the existing issues of plugins related to this issue

Neovim version (nvim -v)

nightly

Operating system/version

Macos sequioa 15.5

Adapter and model

Claude and gpt with copilot

Describe the bug

When using CodeCompanionChat Add and loading plugin for the first time, the text added is duplicated, it seems be text added from CodeCompanionChat Toggle + CodeCompanionChat Add. When I try to clear the text using gx, only the text added from CodeCompanionChat Add is cleared but not from CodeCompanionChat Toggle, it seems to be just stuck there. Also adding text with CodeCompanionChat Toggle only works the first time, not sure if thats intended, and also the text added with CodeCompanionChat Toggle cant be removed with gx either.

Here is a video (forgot to record with repro.lua but I've tested with repro.lua and its the same issue):
Image

Steps To Reproduce

make sure the code companion chat is not on yet, select some text, use CodeCompanionChat Add

Expected Behavior

No duplicate text added, when using CodeCompanionChat Toggle for the first time and text is added to the chat, it should be able to be cleared by using gx.

init.lua file

--[[
NOTE: Set the config path to enable the copilot adapter to work.
It will search the following paths for a token:
  - "$CODECOMPANION_TOKEN_PATH/github-copilot/hosts.json"
  - "$CODECOMPANION_TOKEN_PATH/github-copilot/apps.json"
--]]
vim.env["CODECOMPANION_TOKEN_PATH"] = vim.fn.expand("~/.config")

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

vim.g.mapleader = " "
-- Your CodeCompanion setup
local plugins = {
	{
		"olimorris/codecompanion.nvim",
		dependencies = {
			{ "nvim-lua/plenary.nvim" },
		},
		cmd = { "CodeCompanion", "CodeCompanionChat" },
		opts = {
			strategies = {
				chat = {
					adapter = {
						name = "copilot",
						model = "claude-3.7-sonnet",
					},
				},
				inline = {
					adapter = {
						name = "copilot",
						model = "gpt-4.1",
					},
				},
			},
			display = {
				chat = {
					intro_message = "",
					window = {
						opts = {
							breakindent = false,
							number = false,
							relativenumber = false,
						},
					},
				},
			},
		},
		keys = {
			{ "<leader>ac", "<cmd>CodeCompanionActions<CR>", desc = "Open the action palette", mode = { "n", "x" } },
			{ "<Leader>ai", "<cmd>CodeCompanionChat Toggle<CR>", desc = "Toggle a chat buffer", mode = { "n", "x" } },
			{ "<leader>aa", "<cmd>CodeCompanionChat Add<CR>", desc = "Add code to a chat buffer", mode = "x" },
		},
	},
}

-- Leaving this comment in to see if the issue author notices ;-), yes ive tested with my own repro.lua
-- This is so I can tell if they've really tested with their own repro.lua file

require("lazy.minit").repro({ spec = plugins })

-- Setup Tree-sitter
local ts_status, treesitter = pcall(require, "nvim-treesitter.configs")
if ts_status then
	treesitter.setup({
		ensure_installed = { "lua", "markdown", "markdown_inline" },
		highlight = { enable = true },
	})
end

Log output

No logs

Have you provided and tested with a repro.lua file?

  • Yes, I have tested and provided a repro.lua file

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions