Skip to content

[bug] Failure to call a tool due to an extra space in the tool name. #4279

Closed as not planned

Description

@burbilog

Description

Using Kimi K2 Thinking (and possibly other modes), it often fails because it tries to call tools like " bash" or " edit" instead of "bash" and "edit." After that, OpenCode tends to stop or start looping, repeating the same actions and consuming the quota.

OpenCode version

1.0.62

Steps to reproduce

  1. Select Kimi K2 Thinking
  2. Use it for a while

Screenshot and/or share link

Image Image

Operating System

debian 13

Terminal

yakuake

Activity

  1. added
    opentuiThis relates to changes in v1.0, now that opencode uses opentui
    on Nov 13, 2025
  2. github-actions commented on Nov 13, 2025

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    While these issues have different root causes (plugin conflicts, rendering issues, empty arrays vs spaces), they all involve tool calling problems that result in hanging, looping, or failure to proceed. The pattern of tool calling failures causing OpenCode to stop or loop appears consistent across these reports.

    Feel free to ignore if none of these address your specific case with the extra space in tool names.

  3. removed
    opentuiThis relates to changes in v1.0, now that opencode uses opentui
    on Nov 13, 2025
  4. rekram1-node commented on Nov 13, 2025

    @rekram1-node
    Contributor

    What provider is hosting this one?

    We can prolly trim prefixed spaces... I doubt many people would have tools that have that...

  5. burbilog commented on Nov 14, 2025

    @burbilog
    Author

    What provider is hosting this one?
    We can prolly trim prefixed spaces... I doubt many people would have tools that have that...

    This is from openrouter.ai (very popular one).

  6. EasyDevv commented on Nov 15, 2025

    @EasyDevv

    It is said that the issue appears in other suppliers except for the main supplier of kimi.

  7. self-assigned this
    on Nov 16, 2025
  8. youcefs21 commented on Nov 18, 2025

    @youcefs21
    Image I believe I'm facing the same issue. I'm on v1.0.72, using kimi k2 thinking using open router + vertex AI

    This seems to only happen with this specific command for some reason? when I installed the package manually, and told it the package is installed, it kept going just fine, and is using tools correctly

  9. bodzebod commented on Jan 31, 2026

    @bodzebod

    I happen to have the exact same issue (leading space=error, openrouter and kimi-k2-thinking). Could it be possible to trim the tool name at some point before calling?

  10. burbilog commented on Feb 2, 2026

    @burbilog
    Author

    I just stumbled into this problem with new Kimi 2.5 model:

     invalid [tool= read, error=Model tried to call unavailable tool ' read'. Available tools: invalid, >uedtout. bash, read, glob, grep, edit,
         write, task, webfetch, todowrite, todoread, skill.]  
    
  11. EmanuelNog commented on Feb 22, 2026

    @EmanuelNog

    I ran into it with Kimi 2.5, I made a plugin to solve it, here: https://github.com/EmanuelNog/opencode-trim-toolname-plugin

  12. debemdeboas commented on Apr 22, 2026

    @debemdeboas

    stumbled upon this on the new Kimi 2.6 model as well:

    ⚙ invalid [tool= edit, error=Model tried to call unavailable tool ' edit'. Available tools: invalid, question, bash, read, glob, grep, edit, write, task, webfetch, todowrite, skill, compress.]
    Thinking: The edit call failed because of a space before the tool name. Let me try again properly.
    
  13. KrabsWong commented on Apr 29, 2026

    @KrabsWong

    I ran into it with Kimi 2.5, I made a plugin to solve it, here: https://github.com/EmanuelNog/opencode-trim-toolname-plugin

    HI @EmanuelNog
    Thanks for creating this plugin to address the common issue where LLMs occasionally call tools with leading/trailing spaces (e.g., " read" instead of "read").

    I was looking at how opencode(v1.4.20) handles tool execution, and I'm wondering if the current implementation actually catches the tool name before the AI SDK tries to resolve it. Based on my review of the opencode source code, it seems like tool.execute.before is triggered after the tool has already been successfully matched and identified by the AI SDK's streamText() function.

    So by the time your hook receives the input.tool, the AI SDK has already (hopefully) resolved the correct tool name, or the error has already occurred. Your hook receives item.id which is the correct tool name from the registry, not the raw name from the LLM.

    Have you been able to successfully test this scenario where the LLM sends " bash" and the plugin corrects it to "bash" before the error occurs?

    I might be missing something ? 🤔

  14. EmanuelNog commented on May 26, 2026

    @EmanuelNog

    Have you been able to successfully test this scenario where the LLM sends " bash" and the plugin corrects it to "bash" before the error occurs?

    Sorry for late reply, in fact I have not through-out tested it, I had no time to check implementation, I let kimi create the plugin and run it once, it worked, I'm still using it and have not had the same trailing space issue again, even in 2.6

  15. github-actions commented on Jul 26, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions