← 开源
ProjectBarks

gopher-code

Claude Code, rewritten from scratch in Go. Zero Node.js. Zero Electron. One binary.

ApplicationsCodingGo
在 GitHub 打开
增长势头
+024 小时新增 Star0.0%
802
Star
22
Fork
+0
本周
1
贡献者
创建于 2026-04-02 · 更新于 2026-10-09 · 今日第 13528 名
主要开发者
README

Gopher Code

Gopher Code, rewritten from scratch in Go. Zero Node.js. Zero Electron. One binary.

513K lines of TypeScript → clean, idiomatic Go.

Starts in 12ms. No runtime dependencies. Cross-compiles everywhere Go does.


[!IMPORTANT] This is an active ground-up rewrite. Gopher Code is not a wrapper, binding, or transpilation. Every subsystem of Claude Code v2.1.88 has been analyzed and rebuilt natively in Go using modern 2026 packages. See Porting Status for current progress.


Why This Exists

An incredible tool trapped inside a 500K-line TypeScript monolith that ships with Node.js, a bundled Ink/React renderer, native addons for every platform, and a node_modules tree deeper than the Mariana Trench.

Gopher Code asks: what if it was just a binary?

  • 12ms cold start vs multi-second Node.js bootstrap
  • Single static binary — go build and ship, no npm install, no native addons
  • Native concurrency — goroutines for parallel tool execution, not Promise.all
  • Cross-compile in seconds — GOOS=linux GOARCH=arm64 go build and done
  • Memory efficient — no V8 heap, no garbage collector pauses from React re-renders
  • Hackable — read the source in an afternoon, not a week

Repository Layout

gopher/
├── cmd/gopher/       # CLI entry point & REPL
│   └── main.go
├── pkg/                   # Core packages
│   ├── compact/           # Token budget & context compaction
│   ├── message/           # Message types & normalization
│   ├── mcp/               # Model Context Protocol client
│   ├── permissions/        # Tool permission evaluation
│   ├── prompt/            # System prompt assembly
│   ├── provider/          # Anthropic API provider (SSE streaming)
│   ├── query/             # Query loop orchestration
│   ├── session/           # Session state & persistence
│   └── tools/             # 33 built-in tools
├── internal/
│   ├── cli/               # Bubble Tea TUI renderer
│   └── testharness/       # Golden file test framework
├── testdata/              # Parity test fixtures
└── notes/                 # Architecture & dependency docs

Porting Status

Full parity audit of 1,885 TypeScript source files against the Go port. 594 tasks identified across 24 subsystems. Every behavior, string, flag, keybinding, and error message has been classified.

Subsystem Parity Tasks Notes
API & Streaming 8% 25 Core SSE streaming works; billing, analytics, retry gaps
CLI & Headless Mode 0% 21 Auth, --print mode, subcommands not started
Commands (60+ slash) 1% 89 Descriptors registered, handlers mostly stubs
Compaction & Context 22% 10 Auto-compact works; reactive/collapse pipelines missing
Configuration & Constants 13% 22 Beta headers ~80% done; OAuth config, prompt builders gap
Context & Overlays 0% 10 Notification queue, modal system, voice state
Hook System 1% 25 Execution exists; 100+ React hooks need bubbletea equivalents
IDE & Desktop 0% — Entirely new subsystem
Keybindings 0% 15 13 of ~100 bindings across 17 contexts
Memory & CLAUDE.md 5% 8 Type enum exists; scanning, relevance, paths missing
MCP Protocol 0% — Client exists; service layer + 18 util files absent
Migrations 0% 12 Startup migration registry not started
Model & Provider 57% — Best coverage area; edge cases + allowlists remain
Permissions 13% — Rule engine works; UI, classifiers, auto-mode missing
Plugins 0% 10 Entirely new subsystem
Remote / Bridge (CCR) 0% 32 31-file subsystem, 100% absent
Session & Storage 18% 61 Core state exists; 195 of 215 fields missing
Terminal UI (Ink → Bubbletea) 1% 17 Architecture replaced; behavioral parity gaps
Tools (33 built-in) 9% 63 Skeletons exist; validation, permissions, UI missing
UI Components (390 files) 0% 56 Largest gap — design system, messages, permissions
Utilities (564 files) 5% 31 Sprawling helper layer across 50+ subdirs
Vim Mode 0% 5 1,513 LOC absent
Voice 0% — Entirely new subsystem
Overall ~3% 594 ~301 impl / ~9,100 missing / ~124 fix

Parity % = implemented items / (implemented + missing + fix). Tasks = numbered work items in the full porting plan (notes/plan-v2/02-tasks.md).


Built With

Gopher Code is built on the modern 2026 Go ecosystem. No legacy. No baggage.

Concern Package Why
Terminal UI charm.land/bubbletea/v2 Elm-architecture TUI
Styling charm.land/lipgloss/v2 ANSI styling & layout
Markdown charm.land/glamour/v2 Terminal markdown rendering
Components charm.land/bubbles/v2 Spinner, viewport, text input, progress bar
Prompts charm.land/huh/v2 Permission dialogs & interactive forms
Syntax HL github.com/alecthomas/chroma/v2 Code highlighting in terminal output
API streaming github.com/tmaxmax/go-sse Server-Sent Events for LLM API
HTTP github.com/hashicorp/go-retryablehttp Resilient HTTP with exponential backoff
MCP github.com/mark3labs/mcp-go Model Context Protocol client SDK
Shell parsing mvdan.cc/sh/v3 Bash AST for security analysis
Glob github.com/bmatcuk/doublestar/v4 ** pattern support
Git github.com/go-git/go-git/v5 Pure Go git operations
GitHub github.com/google/go-github/v84 GitHub API v84
Config github.com/knadh/koanf/v2 Multi-source configuration
Schema github.com/santhosh-tekuri/jsonschema/v6 Tool input validation
Concurrency golang.org/x/sync errgroup + semaphore for parallel tools
Caching github.com/hashicorp/golang-lru/v2 File state LRU cache
Keyring github.com/zalando/go-keyring OS-native credential storage
Observability go.opentelemetry.io/otel Traces, metrics, spans

Quickstart

# Clone
git clone https://github.com/projectbarks/gopher.git
cd gopher

# Build
go build -o gopher ./cmd/gopher

# Run interactive REPL
./gopher

# Run headless
./gopher -p "explain this codebase"

# Cross-compile for Linux ARM64
GOOS=linux GOARCH=arm64 go build -o gopher-linux-arm64 ./cmd/gopher

CLI Flags

Usage: gopher-code [flags]

Flags:
  -p, --print string     Run a single query in headless mode
  -m, --model string     Model to use (default: claude-sonnet-4-20250514)
  -c, --cwd string       Working directory
  -r, --resume string    Resume a previous session by ID
  -o, --output string    Output format: text, json, stream-json
  -v, --verbose          Enable verbose logging

Architecture

Gopher Code mirrors the subsystem architecture of Claude Code while leveraging Go's strengths:

                    ┌─────────────────────────┐
                    │     CLI / Bubble Tea     │
                    │    (cmd/gopher-code)     │
                    └────────────┬────────────┘
                                 │
                    ┌────────────▼────────────┐
                    │      Query Engine        │
                    │     (pkg/query)          │
                    └──┬──────────┬──────────┬┘
                       │          │          │
              ┌────────▼───┐ ┌───▼────┐ ┌───▼────────┐
              │  Provider   │ │ Tools  │ │  Session   │
              │ (Anthropic) │ │ (x33)  │ │ (persist)  │
              └──────┬─────┘ └───┬────┘ └────────────┘
                     │           │
              ┌──────▼─────┐ ┌───▼────────────┐
              │ SSE Stream │ │  Permissions    │
              └────────────┘ │  Shell Parse    │
                             │  MCP Client     │
                             └────────────────┘

Key design decisions:

  • No global state — all state flows through explicit function parameters and the session store
  • Context-first cancellation — every goroutine respects context.Context
  • Interfaces at boundaries — provider, tools, and transport are all interface-based for testing
  • Golden file tests — parity tests run against captured Claude Code v2 transcripts

Current Parity Checkpoint

Gopher Code passes L1-L4 parity tests against Claude Code v2.1.88:

  • L1 — Message normalization round-trips match TypeScript output
  • L2 — System prompt assembly produces identical prompts
  • L3 — Tool input/output schemas match the API contract
  • L4 — Multi-turn query loops produce equivalent tool call sequences

The parity test suite uses golden files captured from the TypeScript implementation to ensure behavioral equivalence, not just structural similarity.


Contributing

This is a research project exploring what a native Go implementation of an agentic coding assistant looks like. Contributions, ideas, and feedback are welcome.

# Run tests
go test ./...

# Run with race detector
go test -race ./...

# Update golden files
go test ./... -update

Built by @projectbarks

Gopher Code is an independent project. Not affiliated with Anthropic.

排名相邻
同类项目