You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[bug] Failure to call a tool due to an extra space in the tool name. #4279
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.
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.
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
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?
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.
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?
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
Activity
github-actions commentedon Nov 13, 2025
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.
rekram1-node commentedon Nov 13, 2025
What provider is hosting this one?
We can prolly trim prefixed spaces... I doubt many people would have tools that have that...
burbilog commentedon Nov 14, 2025
This is from openrouter.ai (very popular one).
EasyDevv commentedon Nov 15, 2025
It is said that the issue appears in other suppliers except for the main supplier of kimi.
youcefs21 commentedon Nov 18, 2025
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
bodzebod commentedon Jan 31, 2026
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?
burbilog commentedon Feb 2, 2026
I just stumbled into this problem with new Kimi 2.5 model:
EmanuelNog commentedon Feb 22, 2026
I ran into it with Kimi 2.5, I made a plugin to solve it, here: https://github.com/EmanuelNog/opencode-trim-toolname-plugin
debemdeboas commentedon Apr 22, 2026
stumbled upon this on the new Kimi 2.6 model as well:
KrabsWong commentedon Apr 29, 2026
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 ? 🤔
EmanuelNog commentedon May 26, 2026
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
github-actions commentedon Jul 26, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.