opencode icon indicating copy to clipboard operation
opencode copied to clipboard

Opencode in linux cannot access tools or create files

Open codyseally opened this issue 1 year ago • 32 comments

I am using opencode with devstral / ollama in ubuntu. Devstral keeps telling me it has no access to files on my computer, and keeps giving me "advice" on how to implement stuff myself. Am I missing some config?

codyseally avatar Jul 06 '25 19:07 codyseally

I had the same issue with many ollama models. I wonder whether it's an issue with the models being trained in such a way to not expect file manipulation - but it seemed so commonplace that I wondered otherwise. GPT4 through copilot also had the same issue for me - it wouldn't want to run commands or do anything and then just throw it back to me.

JonBoyleCoding avatar Jul 06 '25 20:07 JonBoyleCoding

No idea, but I was watching THIS GUY showing how he used Devstral with opencode, so I said to give it a try. I get this:

Image

I see that he is not using ollama but Unsloth for getting devstral. The whole point to me was to use local models, otherwise I'm not really interested in another API client.

LE: Tried the exact devstral + ollama setup with aider, works with no problems. The issue is clearly in opencode.

codyseally avatar Jul 06 '25 20:07 codyseally

Intriguing - I presume then this is explicitly an ollama issue with opencode. I have been using opencode on some of my open repositories that I don't care about with claude and github copilot and it works fine.

JonBoyleCoding avatar Jul 06 '25 21:07 JonBoyleCoding

It most likely has to do with the way opencode formats tool use. Probably it is incompatible with ollama's tools use api, the same way aider is. I guess the json format in which the llm served with ollama calls a tool is not the expected json for opencode.

Sadly I have to stick to aider, although I really like opencode's interface, but it's useless to me if it does not work with ollama.

codyseally avatar Jul 06 '25 22:07 codyseally

I'm having the same issue. Qwen 30B (MoE) seems to work well in the likes of Codename Goose, but sadly on opencode (which tbh is much nicer to use) it "thinks" it's unable to write or create any files, which also affects /init

KodeMunkie avatar Jul 07 '25 19:07 KodeMunkie

I can confirm with the same issue. I will attach an screenshot of running Devstral small 24b Q8 with a context window of 90k.

I also have to say, that in the configuration, the "limit" part is not working, as it defaults to 4k context window ignoring this parameters. I had to create an ollama model with devstral an default 90k context length. This is the config is ignoring the context:

 "models": {
        "devstral-24b-q8-90k:latest": {
          "name": "Devstral small 24b",
          "attachment": true,
          "reasoning": false,
          "temperature": true,
          "tool_call": true,
          "cost": {
            "input": 0,
            "output": 0
          },
          "limit": {
            "context": 32768,
            "output": 8192
          }
        }
      }

So with a 90k window, all input can fit on the LLM, this is the results I'm getting. Devstral knows about the tools, and "calls them", but nothing happens. And in the example, "test.txt" file is not created (nor AGENTS.md).

Image

ajunca avatar Jul 08 '25 21:07 ajunca

Same same, I've tried with qwen3:8b . I'm not able to run /init successfully and to generate the AGENTS.md file

Also some models out there like gemme3n:latest do not support tools . Maybe we can compile a list of local models compatible with opencode ?

abate avatar Jul 09 '25 07:07 abate

this is likely an issue with the default system prompt we use. dax is working on custom system prompts per model (and configurable) today.

adamdotdevin avatar Jul 09 '25 11:07 adamdotdevin

this is likely an issue with the default system prompt we use. dax is working on custom system prompts per model (and configurable) today.

But would you need a custom prompt per model or a tool-calling prompt that works with Ollama ? My guess is that Ollama has a fixed way in which all models call tools and that just needs to be made compatible with Opencode. Otherwise you would need to design new prompts every time a new model comes out.

codyseally avatar Jul 09 '25 11:07 codyseally

Whatever it is, please avoid if you can, whatever Codename Goose uses. Goose is hit and miss whether in any one session tooling works without telling it (and reminding) and the massive prompts it have fill up the context (it's 3.6K tokens by default it seems, based on a simple hello prompt and viewing the Ollama logs).

KodeMunkie avatar Jul 09 '25 12:07 KodeMunkie

Same same, I've tried with qwen3:8b . I'm not able to run /init successfully and to generate the AGENTS.md file

Also some models out there like gemme3n:latest do not support tools . Maybe we can compile a list of local models compatible with opencode ?

I have a short list of ollama models that support tools calls that I have tried to use: mistral:7b, qwen2.5-coder:3b, llama3.2:1b and devstral:24b. When you're looking at the ollama models, you can see which models support tools on the model listing page.

But all of these do not appear to work with opencode with ollama. Looking at the logs from ollama, it does appear to be trying to use tools, but I haven't parsed the logs in any depth to troubleshoot yet.

skirmish avatar Jul 09 '25 16:07 skirmish

I am also facing the same issue, but I noticed something that is not the main issue but may trip people in the future and they wouldn't notice what's happening.

The default context size of ollama is 4096, the context size that you may set in opencode.json doesn't affect that.

I suspect this could also cause the model to not be aware of the tools available to it, if the tool description is part of the system prompt.

When I increased the context size, I started noticing that the model actually attempts to use the tools, before that it was just trying to give me instruction on how to do the things I requested myself.

Here is an example of ollama logs when it received requests from opencode

time=2025-07-07T21:20:16.525Z level=INFO source=server.go:637 msg="llama runner started in 26.06 seconds" time=2025-07-07T21:20:16.577Z level=WARN source=runner.go:128 msg="truncating input prompt" limit=4096 prompt=9928 keep=5 new=4096 [GIN] 2025/07/07 - 21:20:18 | 200 | 28.558789481s | 172.17.0.3 | POST "/v1/chat/completions" [GIN] 2025/07/07 - 21:20:21 | 200 | 31.097274311s | 172.17.0.3 | POST "/v1/chat/completions" time=2025-07-07T21:21:43.390Z level=WARN source=runner.go:128 msg="truncating input prompt" limit=4096 prompt=9954 keep=5 new=4096 [GIN] 2025/07/07 - 21:21:46 | 200 | 2.755439948s | 172.17.0.3 | POST "/v1/chat/completions" time=2025-07-07T21:21:54.068Z level=WARN source=runner.go:128 msg="truncating input prompt" limit=4096 prompt=9928 keep=5 new=4096 [GIN] 2025/07/07 - 21:21:54 | 200 | 434.072425ms | 172.17.0.3 | POST "/v1/chat/completions" [GIN] 2025/07/07 - 21:22:02 | 200 | 8.145161783s | 172.17.0.3 | POST "/v1/chat/completions" time=2025-07-07T21:23:16.578Z level=WARN source=runner.go:128 msg="truncating input prompt" limit=4096 prompt=9789 keep=5 new=4096 [GIN] 2025/07/07 - 21:23:16 | 200 | 105.434536ms | 172.17.0.3 | POST "/v1/chat/completions" [GIN] 2025/07/07 - 21:23:18 | 200 | 2.352566149s | 172.17.0.3 | POST "/v1/chat/completions" time=2025-07-07T21:23:59.664Z level=WARN source=runner.go:128 msg="truncating input prompt" limit=4096 prompt=9928 keep=5 new=4096 [GIN] 2025/07/07 - 21:24:00 | 200 | 1.208387214s | 172.17.0.3 | POST "/v1/chat/completions" [GIN] 2025/07/07 - 21:24:15 | 200 | 15.747611753s | 172.17.0.3 | POST "/v1/chat/completions" time=2025-07-07T21:28:33.421Z level=WARN source=runner.go:128 msg="truncating input prompt" limit=4096 prompt=9928 keep=5 new=4096 [GIN] 2025/07/07 - 21:28:34 | 200 | 992.314849ms | 172.17.0.3 | POST "/v1/chat/completions" [GIN] 2025/07/07 - 21:28:42 | 200 | 8.904389371s | 172.17.0.3 | POST "/v1/chat/completions"

The solution I found for that was to create another model in ollama from my main model, you can find instructions for that here: https://github.com/ollama/ollama/blob/main/docs/modelfile.md

Here is how I setup mine:

Create a file with any name

FROM devstral:24b PARAMETER num_ctx 131072

Then add these configuration to ollama:

ollama create <new-model-name> -f <path-to-model-file>

Now when you use that new model name in opencode it will no longer run into the issue where it has to truncate the context as easily.

The context size can also be set in the request to ollama and it would be nice if opencode can support that as it will give more flexibility.

ahmed-bekhet avatar Jul 09 '25 19:07 ahmed-bekhet

I had thought the solution would be more technical than just the custom prompts as I've seen people use other backends for similar models and have largely different responses. I hadn't thought to try what @ahmed-bekhet tried. When I have a chance I'll see if I can confirm it works for me.

JonBoyleCoding avatar Jul 10 '25 07:07 JonBoyleCoding

I had thought the solution would be more technical than just the custom prompts as I've seen people use other backends for similar models and have largely different responses. I hadn't thought to try what @ahmed-bekhet tried. When I have a chance I'll see if I can confirm it works for me.

Oh, I didn't mean to imply that this fixed the issue, it didn't. It just allows the full context of the "/Init" to be passed on to the model.

Even after receiving the full context and the tools' details it still doesn't really call tools with any consistency. I checked the http traffic and the tool calls weren't there, I played around a little with temperature and with context length and max output tokens, but it didn't really help.

I ended up switching to LM Studio with the exact same LLM and it's working and calling the tools correctly.

ahmed-bekhet avatar Jul 10 '25 22:07 ahmed-bekhet

I've tried as well to play around with the suggestions in this thread, but still I can't get it to work with a local ollama model. It's a bit sad. This project looks awesome !

abate avatar Jul 14 '25 20:07 abate

Yeah same issue here - please fix if you can!

jsguy avatar Jul 14 '25 22:07 jsguy

I just want to summarize the main points discussed in this issue to make it easier to follow:

  • Configuring the context size for Ollama using the opencode config file doesn’t work — the limit/context field is ignored.
  • The /Init context length is large (or at least larger than Ollama’s default 4k). To pass the full /Init context, you need to create a custom Ollama model with an extended context length (as demonstrated by @ahmed-bekhet).
  • When the model can read the full context, it correctly detects the available tools.
  • However, the model fails to actually call the tools — this appears to be the main issue.
  • As @ahmed-bekhet also pointed out, LM Studio seems to handle this correctly.

ajunca avatar Jul 15 '25 10:07 ajunca

Usually, default models in ollama that are supposed to work with tools do not work with them, since their default configuration does not support correct execution. Therefore, users add models separately where there is a description of how to work with tools https://ollama.com/search?o=newest&c=tools&q=devstral https://ollama.com/fomenks/devstral-small_cline_roocode-64k:latest

pomazanbohdan avatar Jul 16 '25 07:07 pomazanbohdan

Tried with:

https://ollama.com/fomenks/devstral-small_cline_roocode-64k:latest https://ollama.com/antony66/gemma3-tools

With no luck neither. Gemma3-tools is successfully calling tools on another app (browser use).

Devstral-small_cline_rootcode-64k is doing as it calls, but nothing happens:

Image

ajunca avatar Jul 16 '25 16:07 ajunca

I changed the title of the issue a bit to "cannot access tools or create files" as I see tool calling is clearly the issue. I also have not been able to make any local model work with opencode, either hosted with ollama or lmstudio. They all tell you what to do instead of doing it themselves.

codyseally avatar Jul 16 '25 17:07 codyseally