Skip to content

Latest commit

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

OpenCode logo

⚠️ WORK IN PROGRESS — Active Development Branch ⚠️

This fork is implementing comprehensive improvements based on the OpenCode Port Plan.

The open source AI coding agent.

DiscordnpmBuild status

English | 简体中文 | 繁體中文 | 한국어 | Deutsch | Español | Français | Italiano | Dansk | 日本語 | Polski | Русский | Bosanski | العربية | Norsk | Português (Brasil) | ไทย | Türkçe | Українська | বাংলা | Ελληνικά | Tiếng Việt

OpenCode Terminal UI


🔧 Active Development: OpenCode Port Plan

This branch contains work-in-progress implementation of the OpenCode Port Plan, a comprehensive upgrade to OpenCode inspired by Claude Code's superior implementations. NOT AFFILIATED WITH ANOMALY OR OPENCODE TEAM AT ALL

⚠️ This codebase has errors and will not run as-is. All features are represented in the codebase but are scaffolding/partial implementations that need completion.


📋 Phase 1: Base Prompt Improvements

Hard numeric limits and explicit prohibitions to reduce unnecessary token usage:

FeatureDescription
Conciseness RulesHard numeric limits: ≤4 lines for conversational responses, ≤25 words between tool calls, ≤100 words final responses
Preamble ProhibitionNo "I'll now...", "Let me...", "Certainly!" — begin immediately with action
Post-Action Summary ProhibitionNo summarizing what was done — results speak for themselves
Meta-Rule: When in Doubt, Don'tExplicit instruction to ask rather than proceed under uncertainty
Targeted Failure Mode ProhibitionsSpecific prohibitions: no edits without reading first, no adding docstrings to unmodified code, no TODO comments
Read Before ModifyExplicit rule: must read file in current session before editing
Parallelism InstructionIssue independent tool calls simultaneously, not sequentially
Subagent Task WritingGuidance for writing self-contained subagent prompts

Files:packages/opencode/src/session/prompt/assembly.ts, prompt templates


🧠 Phase 2: Context & Memory Improvements

Multi-layered context system for better prompt caching and session continuity:

FeatureDescription
Static/Dynamic Cache BoundaryStatic prompt content (rules, identity) before dynamic content (session-specific) for 90% cache cost reduction
AGENTS.md in Messages ArrayMove project AGENTS.md to messages array instead of system prompt, preserving shared cache prefix
Global User AGENTS.md~/.opencode/AGENTS.md loaded for all projects, project-level overrides global
Subdirectory AGENTS.mdAuto-load AGENTS.md from subdirectories when entering that context
Path-Scoped Rules.opencode/rules/ with YAML frontmatter for path-specific rules (auto-triggered on file access)
Session Exit SummaryGenerate ≤200 word summary on exit, inject at next session start (7-day TTL)
AGENTS.md Update SuggestionsPrompt to suggest AGENTS.md updates when discovering project conventions

Files:packages/opencode/src/session/prompt.ts, packages/opencode/src/session/exit-summary.ts, skill system


📦 Phase 3: Compaction Upgrades

Smarter context management when approaching context limits:

FeatureDescription
Circuit BreakerStop retrying after 3 consecutive compaction failures, surface error to user
Structured Compaction Prompt9-section structured format: Active task, Completed work, Commands executed, Unresolved issues, Dead ends, Decisions made, Current file states, Next steps, Important constraints
AGENTS.md Re-injectionExplicitly re-inject AGENTS.md after compaction (not rely on summary preserving it)
MicroCompactLocal stale output pruning before full compaction: superseded tool results, aged listings (10+ turns), aged search results (15+ turns)

Files:packages/opencode/src/session/compaction.ts


📐 Phase 4: Plan Mode Upgrade

Tool-level plan mode enforcement and explicit enter/exit transitions:

FeatureDescription
Tool-Level Write RemovalWrite tools removed from tool list entirely in plan mode (not just blocked)
enter_plan_mode ToolExplicit tool call to enter plan mode with clear identity
exit_plan_mode ToolExplicit tool call to exit plan mode (requires plan_summary parameter)
Plan Mode Identity Section"Your role is architect and analyst, not implementor" — qualitative identity shift

Files:packages/opencode/src/session/prompt.ts (PROMPT_PLAN), permission system


⚙️ Phase 5: Settings Hierarchy

Per-machine configuration that never gets committed:

FeatureDescription
Local Gitignored Settings.opencode/settings.local.json — per-machine overrides
Explicit Resolution OrderDocumented priority: CLI flags > ENV > local > project > global
CLI Commandopencode config local to edit local settings

Files:packages/opencode/src/config/config.ts


🔌 Phase 6: MCP Client Improvements

Optimized MCP tool loading:

FeatureDescription
Tool Schema CachingSerialize MCP tool schemas once at session start, reuse across API calls
Category-Based Lazy LoadingGroup tools by category (filesystem, git, web, database, testing, terminal), load on-demand

Files:packages/opencode/src/mcp/index.ts


🤖 Phase 7: Agent System

Rich per-agent configuration:

FeatureDescription
Per-Agent Modelmodel: field in agent YAML — different models for different tasks
Per-Agent Tool AllowlistallowedTools: field — restrict tools at API level
Per-Agent Tool DenylistdisallowedTools: field — block specific tools
Background Agentsbackground: true — non-blocking subagent execution
Max Turns Per AgentmaxTurns: — limit agent iterations
Worktree Isolationisolation: worktree — isolated git worktree per agent
Scoped Lifecycle HooksAgent-specific hooks via YAML

Files:packages/opencode/src/agent/agent.ts, packages/opencode/src/agent/subagent.ts


📊 Phase 8: Context Window Visibility

Real-time token tracking:

FeatureDescription
Context Usage BarTUI status: Context: 45,230 / 200,000 (22%) with color warnings
Per-Turn Token Breakdown+1,240 tokens this turn with cache read/write stats
Cost EstimationEstimated cost per turn and cumulative session cost
Verbose Mode ToggleCtrl+O to show system prompt, tool payloads, cache status

🪝 Phase 9: Hooks System

Extensible lifecycle events:

FeatureDescription
PreToolUse HookBlock/modify tool calls before execution
PostToolUse HookInject context after successful tool execution
PostToolUseFailure HookObserve and log failed tool calls
UserPromptSubmit HookInject context before sending to model
SessionStart/End HooksLifecycle observability
Stop HookInject continuation after model turn
PreCompact HookObserve compaction triggers
Hook TypesCommand hooks (shell), HTTP hooks (webhook), Prompt hooks (inject), Agent hooks (spawn)
Tool Name MatchingRegex patterns to scope hooks to specific tools

Files:packages/opencode/src/config/config.ts (hooks schema)


🧠 Bonus: Memory System

Session memory and knowledge management:

FeatureDescription
AutoDreamIdle-time memory consolidation — merges observations, removes contradictions
Skeptical MemoryEphemeral claims with verification obligations, auto-promote verified claims to persistent layer
Tool Observation CaptureAuto-capture notable read/bash/grep results as raw observations
Session Exit SummaryGenerate and persist summary for next session continuity

Files: Memory modules, packages/opencode/src/session/exit-summary.ts


📁 Key Files Modified

packages/opencode/src/
├── agent/
│ ├── agent.ts # Per-agent config (model, tools, background)
│ └── subagent.ts # Isolated subagent spawning
├── config/
│ └── config.ts # Settings hierarchy, hooks schema
├── mcp/
│ └── index.ts # Tool caching, category lazy loading
├── session/
│ ├── compaction.ts # Circuit breaker, structured prompt, MicroCompact
│ ├── exit-summary.ts # Session exit summaries
│ ├── llm.ts # Static/dynamic prompt boundary
│ ├── prompt.ts # Plan mode, reminders, tool resolution
│ └── (prompt/) # Prompt assembly and templates
├── skill/
│ └── index.ts # Enhanced skill metadata (model, allowedTools, paths)
└── (memory modules) # AutoDream, Skeptical Memory

See opencode-port-plan.md for full implementation tasks.

Installation

# YOLO
curl -fsSL https://opencode.ai/install | bash
# Package managers
npm i -g opencode-ai@latest # or bun/pnpm/yarn
scoop install opencode # Windows
choco install opencode # Windows
brew install anomalyco/tap/opencode # macOS and Linux (recommended, always up to date)
brew install opencode # macOS and Linux (official brew formula, updated less)
sudo pacman -S opencode # Arch Linux (Stable)
paru -S opencode-bin # Arch Linux (Latest from AUR)
mise use -g opencode # Any OS
nix run nixpkgs#opencode # or github:anomalyco/opencode for latest dev branch

Tip

Remove versions older than 0.1.x before installing.

Desktop App (BETA)

OpenCode is also available as a desktop application. Download directly from the releases page or opencode.ai/download.

PlatformDownload
macOS (Apple Silicon)opencode-desktop-darwin-aarch64.dmg
macOS (Intel)opencode-desktop-darwin-x64.dmg
Windowsopencode-desktop-windows-x64.exe
Linux.deb, .rpm, or AppImage
# macOS (Homebrew)
brew install --cask opencode-desktop
# Windows (Scoop)
scoop bucket add extras; scoop install extras/opencode-desktop

Installation Directory

The install script respects the following priority order for the installation path:

  1. $OPENCODE_INSTALL_DIR - Custom installation directory
  2. $XDG_BIN_DIR - XDG Base Directory Specification compliant path
  3. $HOME/bin - Standard user binary directory (if it exists or can be created)
  4. $HOME/.opencode/bin - Default fallback
# Examples
OPENCODE_INSTALL_DIR=/usr/local/bin curl -fsSL https://opencode.ai/install | bash
XDG_BIN_DIR=$HOME/.local/bin curl -fsSL https://opencode.ai/install | bash

Agents

OpenCode includes two built-in agents you can switch between with the Tab key.

  • build - Default, full-access agent for development work
  • plan - Read-only agent for analysis and code exploration
    • Denies file edits by default
    • Asks permission before running bash commands
    • Ideal for exploring unfamiliar codebases or planning changes

Also included is a general subagent for complex searches and multistep tasks. This is used internally and can be invoked using @general in messages.

Learn more about agents.

Documentation

For more info on how to configure OpenCode, head over to our docs.

Contributing

If you're interested in contributing to OpenCode, please read our contributing docs before submitting a pull request.

Building on OpenCode

If you are working on a project that's related to OpenCode and is using "opencode" as part of its name, for example "opencode-dashboard" or "opencode-mobile", please add a note to your README to clarify that it is not built by the OpenCode team and is not affiliated with us in any way.

FAQ

How is this different from Claude Code?

It's very similar to Claude Code in terms of capability. Here are the key differences:

  • 100% open source
  • Not coupled to any provider. Although we recommend the models we provide through OpenCode Zen, OpenCode can be used with Claude, OpenAI, Google, or even local models. As models evolve, the gaps between them will close and pricing will drop, so being provider-agnostic is important.
  • Out-of-the-box LSP support
  • A focus on TUI. OpenCode is built by neovim users and the creators of terminal.shop; we are going to push the limits of what's possible in the terminal.
  • A client/server architecture. This, for example, can allow OpenCode to run on your computer while you drive it remotely from a mobile app, meaning that the TUI frontend is just one of the possible clients.

Join our communityDiscord | X.com

About

opencode branch for testing merge basis of cc RE'd features

Resources

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages