OpenCode

The Second Edition of How to OpenCode to a Remote AI LLM Ollama Server

Author: Stan Switaj

In the first version of How to OpenCode to a Remote AI LLM Ollama Server there was an answer of how to remote AI LLM Ollama Server.

Today is a great day. Therefore, I will inform you of how to do this in an easy way.

1. Connect to your remote AI server, from your remote computer run on it and keep this open the cli statement of ssh -L 11434:localhost:11434 username@ip # and also configure your ai llm ollama server so that only your select ips can get to it (perhaps use ufw or if you are using a firewall it would be ok to do that there)

2. The ollama server by default uses cuda, not great if your machine has a lot of ram and cpu (though email me at opensource3@yahoo.com and or call (215) 954-4908 if you want me to build you an ai llm server computer, same or better than the ai llm server I utilize, the price is cost of parts + my fee of $299 to build it + actual shipping for individuals, and businesses let's talk, and there's a service plan for the computer if you want to purchase it and provide your support to me that way), though sparse on the gpu, you'll get run out of cuda memory quickly, therefore run the following connecting to the ai llm ollama server

2.A
stop the ollama server in the usual linux way

2.B This is where the nice fantastic thing happens, invoke the ollama server with your data models , and do so using ONLY ram and cpu, this will allow you to run opencode models without cuda memory crashes and limitations that way.

CUDA_VISIBLE_DEVICES="" OLLAMA_HOST=127.0.0.1:11434 OLLAMA_MODELS="/path/to/ollama_data/models" ollama serve

You will want to either do this statement using ssh , or run it on the ai llm ollama server.

3. Download and install opencode from https://opencode.ai/download

4. Run opencode, it will utilize the folder /home/username/.config/opencode

5. Create a opencode.jsonc ( or opencode.json ) in this opencode configuration folder

6. I like the opencode.jsonc version because I can have comments all throughout the jsonc configuration (that's the only difference between the jsonc and json versions.

7. This is a great example jsonc that I made, and it allows all the opencode tools such as web searching, and bash tools to do ls and asking to do counts of files and or within files of a string.

Lua
{
  "$schema": "https://opencode.ai/config.json",
  "providers": {
    "ollama": {
      "settings": {
        // Points directly to your forwarded loopback address
        "baseURL": "http://127.0.0.1:11434/v1" 
      }
    }
  },
  "model": "ollama/Qwen3.8-27aaa:latest",

  "version": "2.0", // Specifies the modern OpenCode configuration standard
  
  // =========================================================================
  // V1/STANDARD PERMISSION FORMAT
  // =========================================================================
  "permission": {
    // Global fallback wildcard rule - sets the base baseline to allow everything
    "*": "allow",

    // Terminal & Shell Tool execution rules
    "bash": "allow",               // Allows all shell, terminal, and build script operations
    
    // File system access and engineering tools
    "edit": "allow",               // Allows file modifications (write, patch, multiedit)
    "read": "allow",               // Allows reading individual file payloads
    "list": "allow",               // Allows listing directory contents
    "glob": "allow",               // Allows finding matching file paths using glob expressions
    "grep": "allow",               // Allows regex content searches via background indexers
    "codesearch": "allow",         // Explicit coverage for the extended codesearch tool
    
    // Code intelligence and local agent state tools
    "lsp": "allow",                // Allows Language Server Protocol actions (definitions, references)
    "skill": "allow",              // Allows loading prompt additions from local skill files
    "task": "allow",               // Allows spawning isolated subagents for child tasks
    
    // External Network Access
    "websearch": "allow",          // Allows online discovery via integrated endpoints (e.g., Exa)
    "webfetch": "allow",           // Allows fetching web documents and reading full target URLs
    
    // Built-in checklists and internal workflow states
    "todowrite": "allow",          // Allows editing structured checklists during tasks
    "todoread": "allow",           // Allows viewing structured checklists
    "question": "allow",           // Handled as auto-pass for general interactive dialogue checks
    
    // Safety guard rails and system boundaries
    "external_directory": "allow", // Allows tools to interact with paths outside your active workspace
    "doom_loop": "allow",          // Bypasses the 3-strike identical repeating tool call check
    
    // Model Context Protocol (MCP) wildcard
    "mcp/*": "allow"               // Automatically permits all custom tools inside connected MCP servers
  },

  // =========================================================================
  // V2 STRUCTURED ACTION ARRAY FORMAT
  // =========================================================================
  // OpenCode parses this array if V2 features are active. This replicates 
  // the exact "allow all" behavior across all granular action vectors.
  "permissions": [
    { "action": "shell", "resource": "*", "effect": "allow" },
    { "action": "edit", "resource": "*", "effect": "allow" },
    { "action": "read", "resource": "*", "effect": "allow" },
    { "action": "list", "resource": "*", "effect": "allow" },
    { "action": "glob", "resource": "*", "effect": "allow" },
    { "action": "grep", "resource": "*", "effect": "allow" },
    { "action": "codesearch", "resource": "*", "effect": "allow" },
    { "action": "lsp", "resource": "*", "effect": "allow" },
    { "action": "skill", "resource": "*", "effect": "allow" },
    { "action": "task", "resource": "*", "effect": "allow" },
    { "action": "websearch", "resource": "*", "effect": "allow" },
    { "action": "webfetch", "resource": "*", "effect": "allow" },
    { "action": "todowrite", "resource": "*", "effect": "allow" },
    { "action": "todoread", "resource": "*", "effect": "allow" },
    { "action": "question", "resource": "*", "effect": "allow" },
    { "action": "external_directory", "resource": "*", "effect": "allow" },
    { "action": "doom_loop", "resource": "*", "effect": "allow" },
    { "action": "mcp/*", "resource": "*", "effect": "allow" }
  ]
}

8. If you notice my model line statement, it says "model": "ollama/Qwen3.8-27aaa:latest" and this is different from part 1 of How to OpenCode to a Remote AI LLM Ollama Server where I attempted to create a program to rename, bla, bla, bla. Simply find an installed ollama ai llm running the statement ollama list (probably on the ai llm server, or ssh to it and run that) , now there's a way to make a copy so that opencode can open it (or create symbolic links of the format ollama/[ai llm model] if you don't want to cp the ai llm model on the server). Opencode simply wants the format of

Plain Text
'ollama/model_name'

So there's ollama to rename a model to that format that opencode will accept, the following is a quick example.

ollama cp 'NAME/Qwen3.8-27B-Q5_NVFP4:latest' 'ollama/Qwen3.8-27aaa'

9. There are a few ways to run opencode

10. From within a named_project folder get a cli and run opencode ( this should read your .jsonc file , and the way you know this is that right beneath the ask anything ... it will say the ai llm model you are running, Build·Qwen3.8-27aaa:latest Ollama for example.

11. Perhaps you want to run it from cli because that is an efficient way to run statements to opencode.

12. Use the cli statement of opencode run "this is our prompt that is ok"

13. An example of this is the following, I ran a few statements, such as...

14.

Plain Text
opencode run "summarize the webpage linuxdoors.com"

15.

Plain Text
opencode run "who is the programmer of linuxdoors.com"

16.

Plain Text
opencode run "give me a ls of the Desktop of this computer"

The output does indeed give me the absolute listing of ls (the linux command) of the contents of Desktop

17.

Plain Text
opencode run "search the file on the Desktop,  ok_way_samba.txt  and report to me in a table format a count of the word      server "

You may simply run the program of opencode and provide prompts there also.

18. I hope you enjoyed this tutorial, please email me at opensource3@yahoo.com and let me know if you liked it, or it helped you in any way. Any donations and work tasks that need to be done, please send to me, I am ready to help your efforts and business organization to get the tasks to work nice.

0 Comments

No comments yet. Be the first!

Leave a Comment