Skip to content

AtomCode Reverse Engineering — Analysis Report

1. Binary Overview

PropertyValue
Fileatomcode-v4.25.0-linux-x64
Size26 MB
TypeELF 64-bit LSB shared object, x86-64, dynamically linked, stripped
LanguageRust (with embedded web frontend: Preact/JS)
Source reposatomgit.com/atomgit_atomcode/atomcode

2. Architecture

┌─────────────────────────────────────────────────────────────┐
│  AtomCode Daemon (localhost:13456)                          │
│  ┌──────────────────────────────────────────────────────┐   │
│  │  Web UI (embedded JS)  ←→  REST API                  │   │
│  │  CLI (TUI)             ←→  WebSocket (SSE stream)    │   │
│  └──────────────────────────────────────────────────────┘   │
│         ↕                                                    │
│  ┌──────────────────────────────────────────────────────┐   │
│  │  Auth Layer (AtomGit OAuth)                          │   │
│  │  Provider Layer (OpenAI/Claude/Ollama/DeepSeek)      │   │
│  │  CodingPlan (Quota/Auth management)                  │   │
│  └──────────────────────────────────────────────────────┘   │
└──────────────┬──────────────────────────────────────────────┘

    ┌──────────┴──────────┐
    ▼                     ▼
llm-api.atomgit.com    acs.atomgit.com
(LLM API)              (Telemetry)

3. API Endpoints

LLM API (AI 能力)

EndpointPurpose
https://llm-api.atomgit.com/v1Main LLM API (OpenAI-compatible)
https://pre-llm-api-cce.atomgit.com/v1Staging/pre-release LLM API

Auth (本地 daemon 的 REST API)

EndpointMethodPurpose
/auth/statusGETCheck login status
/auth/login/startPOSTStart OAuth login, returns {url, login_id}
/auth/login/:login_id/pollPOSTPoll for login completion
/auth/login/:login_idDELETECancel login session
/auth/logoutPOSTLogout

Chat (本地 daemon WebSocket/SSE)

EndpointMethodPurpose
/chatPOSTSend chat message (streaming via SSE)
/chat/stopPOSTStop generation
/chat/activeGETActive chat status

Provider Management

EndpointMethodPurpose
/modelsGETList available models
/providersGETList configured providers
/providers/:name/defaultPATCHSet default provider
/providers/:name/thinkingPATCHConfigure thinking mode
/config/reloadPOSTReload config

CodingPlan

EndpointMethodPurpose
/codingplan/setupPOSTSetup CodingPlan
https://api.gitcode.com/api/v5/models-v2?plan_type=GETFetch available models for plan
/coding-plan/claim-v2?Claim CodingPlan tokens

Sessions

EndpointMethodPurpose
/projects/:hash/sessionsGETList sessions
/projects/:hash/sessionsPOSTCreate session
/projects/:hash/sessions/:idGETGet session detail
/projects/:hash/sessions/:id/renamePATCHRename session
/healthGETHealth check
/shutdownPOSTShutdown daemon

4. Authentication Flow

AtomGit OAuth Flow

  1. User runs /login or clicks "Sign in"
  2. Daemon calls POST /auth/login/start → returns {url, login_id, expires_in_seconds}
  3. Browser opens url (AtomGit OAuth page)
  4. User authorizes → AtomGit redirects with ?token=xxx
  5. Web UI polls POST /auth/login/:login_id/poll every 2 seconds
  6. On success, daemon stores the token
  7. Token is sent as Authorization: Bearer <token> header

Token Usage

javascript
var Ji = new URLSearchParams(location.search).get('token') ?? '';
function Yi() { return Ji ? { Authorization: 'Bearer ' + Ji } : {}; }

Key Data Structures

struct AuthInfo:
  - access_token: string
  - token_type: string (Bearer)
  - expires_in: number
  - has_refresh_token: boolean

struct UserInfo:
  - name: string
  - username: string
  - avatar_url: string

5. CodingPlan (AI 额度系统)

CodingPlan is the free AI usage quota system. It provides tokens to free users.

  • Base URL: https://api.gitcode.com/api/v5 (AtomGit API)
  • Endpoint: /models-v2?plan_type=X — fetches models available for the plan
  • CodingPlan credentials are managed via ATOMCODE_CODINGPLAN_LLM_BASE_URL
  • Crypto implementation in: crates/atomcode-codingplan-crypto/src/versions/v1.rs
  • Daemon API: crates/atomcode-daemon/src/api_codingplan.rs

Data structures:

struct PlanInfo:
  - plan_name: string
  - claimed_at: timestamp
  - expires_at: timestamp
  - remaining_days: number
  - total_days: number
  - window_token_limit: number
  - window_tokens_used: number
  - usage_percent: number
  - is_infinity: boolean
  - is_atomcode_exclusive: boolean
  - display_model_name: string

struct RateLimitWindow:
  - window_size_seconds: number
  - call_limit: number
  - calls_used: number
  - quota_exhausted: boolean

6. Provider System

The app supports multiple LLM providers:

ProviderBase URL
DeepSeekhttps://api.deepseek.com/v1
OpenAIhttps://api.openai.com/v1
Claude/Anthropichttps://api.anthropic.com
Ollama(local)

ProviderConfig (15 fields):

  • name, model, base_url, api_key, provider_type (openai/claude/ollama)
  • max_tokens, thinking_budget, thinking_type, thinking_keep
  • reasoning_history, user_agent, is_default
  • skip_tls_verify, clear_api_key, clear_base_url

ChatRequest (5 fields):

  • messages, model, stream, max_tokens, ...

Streaming Chunk Types (SSE):

  • text, reasoning, tool_start, tool_output, tool_result, tokens, error, done, stopped

7. Embedded Web UI

The binary embeds a full web UI built with a React-like library (Preact):

  • Chat interface with streaming
  • Sidebar for session management
  • Model/provider selector
  • Login/logout UI
  • Settings (theme, language)
  • File attachment support
  • Image upload

8. Key Observations for Reverse Proxy

  1. LLM API is OpenAI-compatible: llm-api.atomgit.com/v1 uses OpenAI API format
  2. Auth tokens come from AtomGit OAuth: After login, a Bearer token is acquired
  3. CodingPlan provides the actual API access: This is the mechanism that provides AI tokens/credits
  4. Streaming uses SSE: text/event-stream with custom chunk types
  5. Daemon listens on port 13456: Web UI + REST API

9. Files/Paths

PathPurpose
~/.atomcode/Home directory
~/.atomcode/config.tomlConfiguration
~/.atomcode/auth.tomlAuth storage (OAuth tokens)
~/.atomcode/codingplan_sync.jsonCodingPlan sync timestamp
~/.atomcode/pending_inviteReferral invite
~/.atomcode/mcp.jsonMCP server config
~/.atomcode/hooks.tomlHooks config
~/.atomcode/marketplaces.jsonPlugin marketplaces
~/.atomcode/installed_plugins.jsonInstalled plugins
~/.atomcode/telemetry/Telemetry data
~/.atomcode/stderr.logDaemon stderr log
~/.atomcode/historyCommand history (observed empty)
~/.atomcode/recent_dirs.txtRecent working directories
~/.atomcode/datalog/<project>/llm/<timestamp>.jsonPer-LLM-call logs (request+response)
~/.atomcode/datalog/<project>/llm/calls.logAggregated call log
~/.atomcode/sessions/<project_hash>/<session_id>.jsonPer-session full message history

10. Session Data Model (实测)

Each session file is a complete conversation record:

json
{
  "id": "<uuid>",
  "name": "<first user message>",
  "working_dir": "<cwd when created>",
  "created_at": 1781279460,
  "updated_at": 1781279467,
  "messages": [
    {"role": "User", "content": {"Text": "..."}},
    {"role": "Assistant", "content": {
      "AssistantWithToolCalls": {
        "text": "...",
        "tool_calls": [],
        "reasoning_content": "..."
      }
    }},
    {"role": "Tool", "content": {"ToolResults": [...]}}
  ]
}

11. LLM Call Log Model (实测)

json
{
  "context_window": 1000000,
  "model": "deepseek-v4-flash",
  "session_id": "<uuid>",
  "step": 0,
  "timestamp": "2026-06-12T15:51:05",
  "request": {
    "estimated_tokens": 6332,
    "message_count": 2,
    "messages": [/* full OpenAI-format messages with system prompt injected */],
    "tool_count": 0,
    "tools": [/* available tool definitions */]
  },
  "response": {
    "duration_ms": 2023,
    "reasoning_content": "...",
    "text": "...",
    "tool_calls": []
  }
}

The aggregated call log (calls.log) tracks: timestamp model step msgs/Ntok → Nms tools=N [names] text_only

12. Daemon Version & Auto-Update

  • Observed versions: v4.25.1 → v4.25.3 (auto-upgraded between sessions)
  • Daemon health response includes binary_hash for integrity tracking
  • Config has auto_update = true by default
  • Update mechanism appears to be built into the binary itself

13. Model Detection

The binary contains references to:

  • deepseek-chat (default model in config template)
  • deepseek-v4-flash (mentioned in user context as CodingPlan)
  • Claude models via api.anthropic.com
  • OpenAI models via api.openai.com

14. See Also

DEEP_ANALYSIS.md — 补充分析报告,覆盖 daemon 本质、system prompt 注入内容、会话持久化结构、LLM 日志格式、直接调用 llm-api 可行性验证、MCP/插件系统状态、登出行为、未被覆盖的盲区清单等。

逆向命令索引

bash
# 从二进制查看所有覆盖的子系统
strings atomcode.bin.bak | grep "^crates/atomcode" | sort -u

# 统计结构体
strings atomcode.bin.bak | grep -oP 'struct \w+ with \d+ element' | wc -l

本报告由持续分析循环生成

基于 VitePress 构建 · AtomCode v4.25.3 逆向工程分析文档