The Deska blog

Running OpenCode Against Local Models

Learn how to configure and optimize running OpenCode against local models for a secure, private, and local-first development environment.

· 10 min read

The shift toward decentralized AI development has made running OpenCode against local models a priority for developers who value privacy and reduced latency. By moving the inference process from cloud providers to your own hardware, you gain full control over your data and execution environment. This guide explores the architectural requirements, configuration steps, and practical workflows for integrating open weights models into your daily coding routine.

The Architecture of Local Inference

Running an agent like OpenCode locally requires two primary components: the agent logic and the inference engine. The agent acts as the brain that understands file structures and executes commands, while the inference engine serves as the power source providing the LLM outputs. When you choose to host your own models, you replace third party APIs with a local server, typically powered by tools like Ollama, Llama.cpp, or vLLM.

This setup offers a distinct advantage in terms of security. Since the code never leaves your machine, you mitigate the risks associated with data leakage or unauthorized training on proprietary repositories. However, this approach demands significant hardware resources, particularly VRAM, to maintain acceptable token generation speeds. Developers must balance model size against the available memory on their GPU or unified memory systems.

Setting Up Your Local Environment

To start running OpenCode against local models, you must first prepare your host machine. The most common entry point is Ollama due to its simple API and wide support for coding models like DeepSeek Coder V2 or CodeLlama.

  1. Install your preferred inference engine and verify it is accessible via a local network port, usually 11434 for Ollama.
  2. Pull a model optimized for coding. Models with 7B to 33B parameters are generally sufficient for most tasks, though larger models provide better reasoning at the cost of speed.
  3. Configure the OpenCode environment variables to point to your local endpoint rather than a hosted service.
  4. Ensure your workspace has direct access to the files you intend to modify.

For those who prefer a structured environment, Deska provides a free desktop app for Mac, Windows, and Linux that simplifies this process. It operates as a local-first workspace where you can run these tools side by side.

Integrating OpenCode into Your Workspace

Once the local server is running, the next step is managing the interaction between the agent and your project. A productive workflow often involves seeing the agent output, the terminal, and the code editor simultaneously.

Deska uses an infinite canvas workspace where you can place panels anywhere. You can run OpenCode within a terminal panel and keep your code editor open in another. This allows you to monitor the agent as it attempts to solve problems or refactor code. The canvas approach is helpful because it lets you zoom out to see the entire context of your project, including multiple terminals and browser windows.

When working with local models, context window management is critical. Local hardware might struggle with massive contexts. You should periodically clear agent sessions or use specific flags to limit the number of files the agent reads at once. This ensures the inference remains snappy and the agent does not lose track of the primary objective.

Comparing Local and Cloud Strategies

Choosing between local models and cloud providers involves trade-offs in speed, cost, and intelligence.

FeatureLocal ModelsCloud Providers
PrivacyMaximum (Data stays on disk)Variable (Depends on TOS)
LatencyMinimal (No network roundtrip)Network dependent
CostFree (After hardware purchase)Pay per token or subscription
IntelligenceLimited by local VRAMHighest available models
AvailabilityOffline capableRequires internet

Cloud providers generally offer more powerful reasoning capabilities through models like Claude 3.5 Sonnet or GPT-4o. However, for many standard boilerplate tasks, unit test generation, and refactoring, a quantized local model is more than capable. Using OpenCode allows you to switch between these strategies as needed.

Maximizing Productivity with Local-First Tools

A local-first approach is not just about the model. It is about the entire development experience. When your code, files, and sessions stay on your machine, the friction of synchronization disappears. You can use tools like Ask Deska, a voice and chat assistant, to drive your workspace. It can open panels or run commands while you focus on the logic.

If you need to step away from your workstation, the mobile app allows you to monitor the progress of a long running local task. It uses a secure relay to pair devices directly, so you do not have to expose any ports to the internet. This maintains the security of your local setup while providing the flexibility of remote monitoring.

FAQ

How to use OpenCode with Ollama?

To use OpenCode with Ollama, set the base URL in your agent configuration to your local IP address and port 11434. Ensure the model name matches exactly what you have pulled via the Ollama CLI. You may need to adjust the temperature and context length settings to match your hardware capabilities.

Best local models for coding?

Currently, DeepSeek Coder V2 and specialized versions of Llama 3 are highly regarded for local execution. For machines with limited VRAM, a 7B parameter model like Mistral or a quantized version of Phind-CodeLlama can provide a good balance of speed and accuracy.

Is OpenCode free to use?

OpenCode itself is an open source project, but the costs depend on how you run it. Running it locally is free in terms of API costs. If you use a tool like Deska to manage your agents, the workspace itself is free, and you can use your own API keys or local endpoints through the lifetime tier.

Getting Started with OpenCode

Transitioning to a local-first workflow provides the ultimate level of privacy for your intellectual property. By running OpenCode against local models, you ensure that your development environment remains functional even without an internet connection.

If you are looking for a unified environment to manage these tools, you can download the Deska desktop app. It allows you to run coding agents like OpenCode, Claude Code, and Codex CLI side by side as panels on an infinite canvas. Explore the getting started guide to configure your first workspace and begin building with local AI today.

💡 Ideas+🐛 BugsSuggest a feature or report a bug