$ show xtherk/open-claude-code
This repository is a source-recovered reconstruction of Anthropic's Claude Code CLI v2.1.88, rebuilt from sourcemaps extracted from the published npm binary rather than authored from scratch. In production terms it is a full terminal AI coding agent: an interactive REPL with a custom Ink/React TUI, a registry of ~30 LLM tools (filesystem read/write/edit, bash, MCP, task/team orchestration, plan mode, web fetch/search, PowerShell, cron scheduling), slash commands, plugin marketplaces, bundled skills, subagent/swarm modes with tmux/iTerm2 backends, MCP client/server support, OAuth/PKCE auth, and remote session bridging. The primary entry point is src/entrypoints/cli.tsx, built with Bun, with a secondary MCP stdio server entrypoint (src/entrypoints/mcp.ts) exposing the same tools. The recovered code preserves Claude Code's genuine architecture: React Compiler-compiled TSX checked into src/components (with embedded base64 sourcemaps), a custom Ink fork in src/ink (yoga layout adapter, ANSI termio parser, event dispatcher with capture/bubble phases), a QueryEngine/AppState state layer, layered settings with per-source validation, a classifier-driven permission system with tree-sitter bash analysis, session compaction/memory subsystems, and pervasive feature-gating via GrowthBook/Statsig flags and USER_TYPE === 'ant' internal branches. Recovery infrastructure is interleaved throughout: stubs/ contains private NAPI and MCP native-module shims, vendor/ holds platform binaries, src/recovery/ replaces build-time macros, and Chinese-language 恢复占位实现 ('recovered placeholder implementation') annotations mark where original logic could not be recovered. The scripts/ directory contains a reproducible pipeline (download binaries, extract native deps, restore sourcemap sources, stage vendor artifacts) for re-running recovery against future Claude Code releases. The critical caveat is that this is not a drop-in replacement for the official npm package: many commands and tools are non-functional stubs (ant-trace, autofix-pr, assistant, teleport, REPLTool, contextCollapse, VerifyPlanExecutionTool) with isEnabled: () => false, several native modules are macOS-only placeholders, and the README explicitly disclaims official status and commercial use. Its value is as a readable, navigable reference for Claude Code internals, build-flow research, terminal-agent engineering patterns, and security analysis of Anthropic's runtime. Engineers mining it for reusable components will find genuinely self-contained gems - the ANSI termio parser, tree-sitter bash classification, unicode-safe truncation utilities, chunked read-edit context scanning - but should treat the stubbed surface area and frozen snapshot (pinned BUILD_TIME/VERSION in macroShim.js) as expected drift risk.
The LLM identified 5 files worth highlighting for reuse:
Tree-sitter-based bash command parser with an abort sentinel, producing an AST consumed by security decisions: destructive-command detection, read-only validation, and sandbox eligibility. It is paired with command-specific spec files (alias, nohup, sleep, timeout, srun, time, pyright) that model side effects of individual commands. Self-contained enough to extract as a 'classify shell commands for safety' library; demonstrates non-obvious integration of tree-sitter with hard timeout/abort guarantees, which recurs in sandboxes, permission systems, and CI command validation.
A standalone tokenizer/parser for terminal escape sequences covering ANSI CSI, DEC private modes, OSC, ESC, and SGR, paired with a typed token model (src/ink/termio/types.ts). It is what lets the TUI query modern terminals (kitty keyboard protocol, cursor/viewport queries) for search highlight, IME cursor declaration, and terminal-focus tracking. The parser is a pure state machine with no internal imports, so it can be lifted directly into any terminal-emulation, logging, or TUI project needing robust ANSI input handling.
Width- and grapheme-safe string truncation strategies: middle-path truncation for file paths, start/end truncation, ellipsis variants, and wrap-at-width. It handles wide CJK characters and ANSI boundaries correctly, solving the recurring 'clip a string without breaking terminal rendering or Unicode graphemes' problem. Dependency-light and extraction-ready for any CLI, log formatter, or UI project.
Chunked file scanning (8KB windows with straddle overlap, CRLF handling, 10MB cap) that builds numbered, fenced read/edit context windows for feeding large source files to an LLM tool call. It solves the recurring data problem of fitting arbitrarily large files into bounded context without losing boundary fidelity, and the fencing/line-numbering output shape is portable to RAG pipelines and context-window builders beyond Claude Code.
PKCE code-verifier/challenge generation and the localhost auth-code listener pattern supporting both automatic (localhost callback) and manual (paste-code) OAuth flows. The crypto primitives are self-contained and the listener lifecycle (port binding, timeout, token exchange, profile fetch) is directly reusable in any desktop or CLI application needing device-style OAuth without a browser redirect surface.