Skip to content

Conversation

ravitemer
Copy link
Contributor

Description

This is related to the ravitemer/codecompanion-history.nvim#43 issue at the history extension.

For the anthropic adapter, the content field of a tool result message is a table rather than a plain string e.g:

{
    content = {
      content = "**`neovim__list_directory` Tool**: Returned the following:\n\n````\n Directory Listing: ````",
      is_error = false,
      tool_use_id = "toolu_012TCg3Xi16Ef8fPdhafFynS",
      type = "tool_result"
    },
    cycle = 2,
    id = 2082665656,
    opts = {
      visible = true
    },
    role = "tool"
  }, 

This leads to issues while restoring the chat with messages of this kind while rendering that chat buffer as we assume msg.content will always be a string as follows previously:

local trimempty = not (msg.role == "user" and msg.content == "")
for _, text in ipairs(vim.split(msg.content or "", "\n", { plain = true, trimempty = trimempty })) do
table.insert(lines, text)
end

This PR handles checks for msg.content.content field to handle the special anthropic case.

Related Issue(s)

ravitemer/codecompanion-history.nvim#43

Screenshots

Checklist

  • I've read the contributing guidelines and have adhered to them in this PR
  • I've updated CodeCompanion.has in the init.lua file for my new feature
  • I've added test coverage for this fix/feature
  • I've updated the README and/or relevant docs pages
  • I've run make all to ensure docs are generated, tests pass and my formatting is applied

@ravitemer ravitemer force-pushed the fix/restoring-anthropic-chats branch from eb8b87d to 850ca05 Compare August 22, 2025 06:16
@olimorris olimorris added the P4 Negligible impact and urgency label Aug 27, 2025
@amadeus
Copy link
Contributor

amadeus commented Aug 31, 2025

Any movement on this? It essentially means we can't use the history plugin with any anthropic models that utilize a file tool of some kind, which is kind of a bummer.

This is what happens when it tries to resume a saved chat:

CleanShot 2025-08-31 at 00 24 11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P4 Negligible impact and urgency
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants