OpenCode

repository·dev·Indexed 12 days ago

https://github.com/anomalyco/opencode

An open-source AI coding agent designed for development, planning, and code exploration. It includes a GitHub Action that allows users to explain issues, fix bugs, and review pull requests directly via comments using /oc or /opencode commands.

Tokens
369.3K
Snippets
1.2K
Records
1.7K
Agent score
97%

What's inside OpenCode

  1. Overview of OpenCode Enterprise capabilities

    dev

    OpenCode Enterprise is designed for organizations requiring strict data sovereignty. Key features include:

    • Data Sovereignty: OpenCode does not store your code or contextual data. Processing occurs locally or via direct API calls to your AI provider.
    • Centralized Configuration: Allows organizations to enforce a single configuration across all users, ensuring they only access approved internal AI gateways.
    • SSO Integration: Integrates with your organization's SSO provider for authentication, allowing OpenCode to obtain credentials for internal AI gateways through your existing identity management system.
    • Internal AI Gateway Enforcement: Can be configured to restrict all AI requests to your organization's approved internal infrastructure, disabling all other providers.
    • Code Ownership: You retain full ownership of all code produced by OpenCode with no licensing restrictions.
  2. Use the TUI Plugin API

    dev

    The TUI (Terminal User Interface) plugin API is exposed via the tui(api, options, meta) function. It provides a comprehensive set of tools for building plugins, including routing, UI components, keybindings, state management, and lifecycle control.

    Core API Groups:

    • api.app: App metadata (e.g., api.app.version).
    • api.attention: User notifications and sound management.
    • api.keys: Key sequence and binding formatting.
    • api.keymap: Keybinding registration and mode-aware layers.
    • api.mode: Managing UI modes (e.g., api.mode.push).
    • api.route: Navigation and route registration.
    • api.ui: Dialogs, prompts, toasts, and slots.
    • api.tuiConfig: Access to host configuration.
    • api.kv: Shared key-value store.
    • api.state: Synced TUI state (config, path, session, etc.).
    • api.theme: Theme management and installation.
    • api.plugins: Plugin lifecycle (list, activate, install, add).
    • api.lifecycle: Cleanup and signal handling.
  3. Secure OpenCode for Organizations with Enterprise

    dev

    OpenCode Enterprise is designed for organizations that require strict data sovereignty. It ensures code and data remain within your infrastructure by using a centralized configuration that integrates with your Single Sign-On (SSO) provider and your internal AI gateway.

    Key features include:

    • Central Config: Manage settings for your entire organization from one place.
    • SSO Integration: Authenticate users via your existing identity management system to obtain credentials for internal AI gateways.
    • Internal AI Gateway: Force all AI requests through your organization's approved infrastructure and disable all other AI providers.
    • Data Sovereignty: OpenCode does not store code or context data; processing happens locally or via direct API calls to your provider.
  4. Explore the OpenCode Ecosystem: Add-ons, Projects, and Agents

    dev

    The OpenCode ecosystem consists of community-built extensions, full-scale projects, and specialized AI agents designed to enhance the OpenCode experience.

    Add-ons (Dodaci)

    Add-ons are plugins or tools that integrate directly with OpenCode to provide specific functionalities such as:

    • Authentication & Cost Savings: Tools like opencode-openai-codex-auth, opencode-gemini-auth, and opencode-antigravity-auth allow using existing subscriptions or free models instead of direct API billing.
    • Environment & Isolation: opencode-daytona for Daytona sandboxes and opencode-devcontainers for isolated development environments.
    • Developer Experience: opencode-type-inject for TypeScript/Svelte type injection, opencode-pty for interactive PTY process control, and opencode-wakatime for usage tracking.
    • Workflow & Automation: opencode-scheduler for recurring tasks, opencode-skillful for on-demand skill loading, and opencode-background-agents for asynchronous delegation.
    • Security & Monitoring: opencode-vibeguard for PII/secret redaction and opencode-sentry-monitor for error tracking.

    Projects (Projekti)

    These are standalone applications or integrations built using the OpenCode SDK or API, including:

    • Editor Integrations: opencode.nvim (Neovim plugin) and OpenCode-Obsidian (Obsidian plugin).
    • Clients & Interfaces: portal (mobile interface via Tailscale), CodeNomad (multi-platform client), and OpenChamber (Web/Desktop/VS Code).
    • SDK Integrations: ai-sdk-provider-opencode-sdk for using OpenCode with the Vercel AI SDK.
    • Management Tools: ocx for managing extensions with isolated profiles.

    Agents (Agenti)

    Specialized AI agent configurations and modular command sets designed for structured development workflows, such as Agentic and opencode-agents.

    If you have built an OpenCode project and want to add it to this list, please submit a Pull Request.

  5. Overview of OpenCode language-specific formatters

    dev
    OpenCode automatically formats files after they are written or edited using language-specific formatters. This ensures that generated code adheres to your project's existing code styles. The process happens in the background: OpenCode checks the file extension, runs the corresponding formatting command, and automatically applies the changes.
  6. What is @opencode-ai/codemode?

    dev

    CodeMode is an Effect-native, confined code execution environment. It allows an AI model to write small JavaScript programs that can only interact with a specific set of tools provided by the host.

    Key characteristics:

    • Confined Execution: Programs have no access to the filesystem, process, network, modules, or ambient application authority.
    • Tool-Centric: Programs interact with tools via a tools object. They can sequence calls, transform data, branch, loop, and run calls in parallel.
    • Effect-Native: It uses the effect library for tool implementations and result types, ensuring type safety and robust error handling.
    • Safe Results: Program failures, validation errors, and limit breaches are returned as diagnostics within a CodeMode.Result rather than failing the host's Effect. Successful results are always JSON-safe data.
  7. What is OpenCode Zen?

    dev
    OpenCode Zen is an AI gateway providing a curated list of tested and verified models specifically optimized for use as coding agents. It aims to solve performance inconsistencies found in general-purpose providers by offering specific model/provider combinations that have been benchmarked and configured for optimal coding performance.
  8. Overview of OpenCode Stats architecture

    dev

    OpenCode Stats is a separate site from the console. The architecture is split into three primary packages that handle different layers of the application:

    • app: The SolidStart frontend/site.
    • core: Contains Effect services, application configuration, Drizzle schema/migrations, and stats domains.
    • function: Contains the Lambda handlers that interface with core services.
  9. Understand the CodeMode authority boundary

    dev

    CodeMode is designed to confine programs to a supplied tool tree, but it does not manage the permissions of those tools. It is critical to understand the division of responsibility:

    The Host (Your Application) owns:

    • Authentication and authorization.
    • Tool selection and immutable scope.
    • Credentials and network clients.
    • Persistence, idempotency, approval, and durable side effects.
    • Logging and redaction policy.

    CodeMode owns:

    • Parsing and interpreting a supported subset of JavaScript (without eval).
    • Schema boundaries around tool calls.
    • Plain-data copying and blocking prototype members.
    • Resource limits (timeouts, call counts) and normalized diagnostics.
    • Model-facing tool discovery and instructions.

    Security Principle: A program cannot gain authority through prose or generated code. It can only exercise authority already present in the tools you provide. Do not expose a broad tool and expect the prompt to restrict its usage.

  10. Use arguments in custom commands

    dev

    You can pass arguments to your custom commands in the TUI. These arguments are injected into your prompt template using specific placeholders:

    • $ARGUMENTS: Replaces with all arguments passed after the command.
    • $1, $2, $3, etc.: Positional parameters representing the first, second, third argument, and so on.

    Example usage: If a command is defined with /component $ARGUMENTS, running /component Button will replace $ARGUMENTS with Button.

    ---
    description: Create a new file with content
    ---
    
    Create a file named $1 in the directory $2
    with the following content: $3

    // Execution: /create-file config.json src "{ "key": "value" }" // Results in: // $1 -> config.json // $2 -> src // $3 -> { "key": "value" }

  11. Use Transform Hooks to modify stateful domains

    dev

    Transform hooks allow plugins to contribute to or modify stateful domains. When a transform is registered or disposed, OpenCode rebuilds the domain by starting from a fresh state and running every active transform in registration order.

    Available transform hooks are namespaced by domain:

    • ctx.agent.transform
    • ctx.catalog.transform
    • ctx.command.transform
    • ctx.integration.transform
    • ctx.reference.transform
    • ctx.skill.transform
    yield *
      ctx.agent.transform((agent) => {
        agent.update("reviewer", (item) => {
          item.description = "Reviews code for regressions"
          item.mode = "subagent"
        })
      })
  12. Core API patterns for Effect Drizzle SQLite

    dev

    When working with @opencode-ai/effect-drizzle-sqlite, follow these core patterns derived from Drizzle's Effect implementation:

    • Effect-yieldable Queries: Drizzle query builders are designed to be yielded within an Effect generator: yield* db.select().from(table).
    • Effect Transactions: Transactions are handled as Effect values. Use the transaction method with a generator function and specify the behavior (e.g., { behavior: "immediate" }): yield* db.transaction((tx) => Effect.gen(function* () { ... }), { behavior: "immediate" }).
    • Service Provision: Database instances are typically provided using Effect.provide(EffectDrizzleSqlite.DefaultServices), which includes default loggers and cache services.