Skip to main content
Station integrates with AI coding assistants to provide powerful coding capabilities. Unlike sandbox execution which runs in isolated containers, coding backends work directly on your local filesystem with full IDE-like features.

Supported Backends

Coding Backends vs Sandbox

Coding Backends

Local development with full filesystem access. AI reads, writes, and refactors code on your machine.

Sandbox Execution

Isolated containers for safe code execution. Code runs in ephemeral Docker containers.

How It Works

OpenCode backend creates coding sessions that give agents access to your local filesystem:
  1. Session Creation: Agent calls coding_open with a workspace path
  2. Code Operations: Agent sends tasks via code tool - OpenCode’s AI reads, writes, and modifies files
  3. Session End: Agent calls coding_close to clean up

Quick Start

1. Install OpenCode

2. Start OpenCode Server

For container mode (stn up), you must bind to all interfaces:
See Container Mode for details.

3. Configure Station

Add OpenCode URL to your Station config:

4. Create an Agent with Coding Backend

5. Run the Agent

Coding Tools

When coding.enabled: true and coding.backend: opencode, agents receive these tools:

Tool Reference

Start a new coding session or continue an existing one.
To continue an existing session:
Returns session ID for subsequent operations.

Backend Options

Station supports three backend options for OpenCode integration:
The backend is configured at the Station level (config.yaml), not per-agent. All agents with coding.enabled: true use the same backend. This keeps agent definitions portable across environments.

HTTP Backend (opencode)

Direct HTTP communication with OpenCode. Best for local development where OpenCode runs on the same machine.

NATS Backend (opencode-nats)

Uses NATS messaging for communication. Best for containerized or distributed setups where OpenCode runs remotely or in a container with the Station plugin.
The NATS backend enables:
  • Running OpenCode in a separate container
  • Decoupled architecture (Station and OpenCode can restart independently)
  • Multiple Station instances sharing one OpenCode

CLI Backend (opencode-cli)

Spawns opencode run as a subprocess for each task. No server required - OpenCode bootstraps itself on a random port for each execution.
The CLI backend is ideal for:
  • CI/CD pipelines (GitHub Actions, GitLab CI)
  • Serverless environments where you can’t run a persistent server
  • Simple setups without infrastructure dependencies
  • Session continuation across multiple agent runs

Configuration Reference

HTTP Backend Config

NATS Backend Config

When using opencode-nats, ensure the OpenCode container has the Station plugin installed and is connected to the same NATS server. See OpenCode Container for setup instructions.

CLI Backend Config

The CLI backend requires opencode to be installed and available in your PATH. No server needs to be running - each task spawns a fresh OpenCode process.

Claude Code Backend Config

Claude Code is Anthropic’s official AI coding agent. It uses your Claude Max/Pro subscription or API key.
  1. Install Claude Code CLI: https://docs.anthropic.com/en/docs/claude-code
  2. Authenticate: Run claude login for Max/Pro, or set ANTHROPIC_API_KEY
Claude Code runs with --dangerously-skip-permissions for non-interactive use. Ensure workspace directories are appropriately secured.

Private Repository Authentication

To work with private repositories, configure git credentials in your Station config:
Create a Personal Access Token with repo scope:
  1. Go to GitHub Settings → Developer Settings → Personal Access Tokens
  2. Generate a token with repo (full control of private repositories)
  3. Set it as an environment variable:
Security Notes:
  • Never commit tokens to config files - use token_env to reference environment variables
  • Tokens are automatically redacted from logs and error messages
  • In CI/CD, use secrets management (GitHub Secrets, Vault, etc.)
Example: Clone and work on a private repo
The git token is automatically injected into HTTPS URLs during clone/push operations.

When to Use Each Backend

Long-Running Tasks and Timeouts

MCP (Model Context Protocol) has a default timeout of ~60 seconds. Complex coding tasks like project scaffolding, large refactors, or multi-file changes may exceed this limit.

Understanding the Timeout

When Station executes agent tools via MCP, each tool call has a timeout. If OpenCode takes longer than 60 seconds to complete a task, the MCP call will fail with a timeout error. Tasks that commonly timeout:
  • Generating entire project structures (scaffolding)
  • Large codebase refactors
  • Complex multi-file changes
  • Tasks requiring many LLM calls (iterative refinement)
Tasks that typically complete quickly:
  • Single file edits
  • Adding/modifying functions
  • Code review and analysis
  • Simple bug fixes

Solutions for Long-Running Tasks

Instead of one large task, use multiple smaller ones:
Design your agents to work incrementally.

Timeout Configuration

The task_timeout_min setting only affects the NATS backend. For HTTP backend, you’re constrained by the MCP protocol timeout.

Session Continuation (CLI Backend)

The CLI backend supports session continuation - allowing multiple agent runs to share the same OpenCode context. This is useful for:
  • Multi-step workflows where each step builds on previous work
  • Interactive development with human-in-the-loop review
  • CI/CD pipelines that need to maintain state across jobs

How It Works

  1. First run creates a new session (title = your task message)
  2. Subsequent runs use --coding-session <name> to continue by title
  3. OpenCode maintains conversation history, file context, and tool state

Using Session Continuation

Pass a session name or ID to continue from a previous run:
The --coding-session flag accepts:
  • Session name - Searches titles (case-insensitive, partial match)
  • Session ID - Direct lookup (starts with ses_)
Run opencode session list to see all sessions with their titles.

Listing Sessions

You don’t need to remember session IDs - just use part of the session title. But if you want to see all sessions:
Then continue any session by name:

Environment Variables

Agent Frontmatter

The agent frontmatter only controls whether coding tools are enabled for that agent. The backend transport (HTTP vs NATS) is determined by Station’s global config. This makes agents portable - the same agent definition works whether Station uses HTTP or NATS backend.

Agent Prompt Template

When creating agents that use coding tools, you must use the {{userInput}} template variable to pass the user’s task to the code tool. Without this, the agent won’t correctly forward the task.
The {{userInput}} variable is populated by Station with the user’s task message. If you don’t reference it in your prompt, the agent won’t know what task to execute and may ask for clarification or pass incorrect instructions to the code tool.

Container Mode (stn up)

When running Station in container mode via stn up, special configuration is needed for OpenCode connectivity.

The Problem

By default, OpenCode binds to 127.0.0.1:4096 which is only accessible from localhost. Docker containers cannot reach 127.0.0.1 on the host.

The Solution

Start OpenCode with --hostname 0.0.0.0 to listen on all interfaces:
Station’s stn up command automatically rewrites the config:

Verify Connectivity

Architecture

Files created by OpenCode persist on the host machine, not in the container. This is the key difference from sandbox mode.

Example Workflows

Simple File Creation

Agent workflow:
  1. coding_open({"workspace_path": "/tmp/workspace"})
  2. code({"task": "Create hello.py with a hello world function"})
  3. coding_close()
Result: /tmp/workspace/hello.py created on your filesystem.

Code Refactoring

Agent workflow:
  1. coding_open({"workspace_path": "/home/user/my-app"})
  2. code({"task": "Read the current database.py implementation"})
  3. code({"task": "Refactor to use connection pooling with a pool size of 10"})
  4. coding_commit({"message": "Refactor: add database connection pooling"})
  5. coding_close()

Full Development Cycle

Troubleshooting

OpenCode Not Responding

Container Can’t Reach OpenCode

Session Errors

If you see “no active session” errors:
  • Ensure coding_open was called first
  • Check OpenCode logs for connection issues
  • Verify workspace path exists and is accessible

Next Steps

OpenCode Container

Run OpenCode in Docker with OAuth

Sandbox Execution

Run code in isolated containers

Agent Development

Create custom agents

Workflows

Multi-step agent orchestration