Skip to content

docs: Claude Code architecture research + 1:1 refactor plan#15

Open
Planckbaka wants to merge 23 commits into
mainfrom
docs/claude-code-architecture
Open

docs: Claude Code architecture research + 1:1 refactor plan#15
Planckbaka wants to merge 23 commits into
mainfrom
docs/claude-code-architecture

Conversation

@Planckbaka

Copy link
Copy Markdown
Owner

What

The research deliverable for the 1:1 Claude Code replica effort: a complete docs/claude-code-architecture/ tree.

Why

Before refactoring iroha into a faithful Claude Code replica, we needed a precise, source-grounded spec of how the real thing works (v2.1.x). This PR lands that spec + the gap analysis + the refactor plan so the implementation work has a single source of truth.

Contents

  • research/ — 16 detailed architecture specs (agent loop, canonical tools, tool-exec engine, streaming protocol, session/transcript, context compaction, system-prompt assembly, memory/CLAUDE.md, permissions, hooks, MCP, subagents/Task, skills, slash-commands/plan, TUI/IDE/config, sandbox/security). Sourced via anysearch against docs.claude.com / code.claude.com / anthropic.com / github.com/anthropics.
  • audit/ — 6 honest capability inventories of the current iroha codebase, each with an ADK/Genkit coupling map.
  • gap-analysis.md — iroha-vs-CC delta per cluster (present / partial / missing / divergent).
  • refactor-plan.md — native-engine rewrite roadmap (4 decisions, Phase 0→4) to reach 1:1 fidelity by decoupling from Google ADK/Genkit.
  • verify-verdicts.md — adversarial fact-checks (38 claims) with corrections.
  • README.md — master overview + navigation.

Core finding (cross-confirmed by research + audit)

iroha has no native agent loop — it is outsourced to Google ADK's internal Flow.Run. Real Claude Code owns query()queryLoop() (one code path). A 1:1 replica therefore requires replacing the loop driver, not swapping types, reusing the ~85% of the codebase that is already framework-free.

Key verified facts that correct common assumptions:

  • CLAUDE.md is injected as a user message, not the system prompt.
  • Permission rule order is deny → ask → allow.
  • MCP protocol should be 2025-06-18 (iroha pins the old 2024-11-05).
  • Headless stream terminates with type:"result", not message_stop.

⚠️ Reviewer notes — scope & repo state

  1. This PR contains documentation only — no code changes. The 36 pre-existing modified tracked files in the working tree (+2119/−457 across pkg/agent, pkg/tui, pkg/llm) are unrelated WIP and were intentionally left uncommitted; they should be reviewed/committed separately.
  2. The branch carries 22 prior local commits that were already on main but not pushed to origin/main (test/feature work). This PR will propose merging those along with the docs.
  3. main has diverged from origin/main: origin has a539b02 (PR refactor: deslop coverage_boost_test.go + upgrade CI #4 "deslop + upgrade CI") which local main lacks, while local main has its own different deslop commit (78757fe). A merge of this PR may conflict on coverage_boost_test.go / CI files and will need reconciliation. Worth deciding separately how to align main with origin/main.

Next step (not in this PR)

Phase 0 of the refactor: additive pkg/engine/ (native message/event/tokenizer/Model types + genai↔native bridge), keeping the existing ADK loop compiling.

🤖 Generated with Claude Code

Akiwayne and others added 23 commits May 29, 2026 10:15
Test coverage improvements across all packages (agent, llm, tui, config):
- Agent: 90+ new test files covering runner, hooks, MCP, memory, compaction,
  subagent, watchdog, IPC, bridge, LSP, skills, team, web tools, permissions
- LLM: adapter tests, OpenAI/Anthropic continuation, retry, coverage boost
- TUI: component tests (chat, confirm, input, status, slash menu), view render
  tests, history tests, app table tests, raw input tests
- Config: config wizard tests, full config roundtrip tests

Feature additions aligned with Claude Code architecture research:
- Auto-continuation system (adapter-level max_tokens escalation, continuation prompts)
- Compaction 4-layer pipeline (toolResultBudget → snipCompact → microCompact → autoCompact)
- Subagent recursive spawn prevention + 30-iteration limit
- Hook recursive guard + event expansion (12 → 20 events)
- YoloClassifier LLM auto-approval with 3-layer defense against prompt injection
- MCPTransport interface extraction (StdioTransport + HTTPTransport over HTTP+SSE)
- OAuth 2.0 + PKCE flow (manual-copy primary, env var bypass, file-based token storage)
- Memory LLM side-query selection with per-file budget (4096 bytes)
- Tool pool change-signal rebuild (/mcp reload, plugins.json mtime detection)
- ADK state placeholder sanitization in prompt builder
- Runner cleanup: remove unused WithStateDelta, nil guards on hooks

Anti-slop cleanup: removed redundant ListTools RPC, fixed mtime to use time.Time,
cleaned test data leak in AGENTS.md.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
… skills, shell handlers

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
… stale coverage files

Extract 6 test helpers (sseServer, openAISSEServer, captureBodyServer,
capturePathServer, captureBodySSEServer, captureBodyOpenAISSE) to replace
25 inline httptest.NewServer boilerplate blocks. Remove AI section
dividers, empty test, and consolidate ioReadAll. Add *.out and
coverage.* to .gitignore. Delete 4 stale coverage output files.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Deep multi-dimensional research on real Claude Code (v2.1.x, mid-2026)
sourced via anysearch against docs.claude.com / code.claude.com /
anthropic.com / github.com/anthropics, plus a 6-area audit of the
current iroha codebase and adversarial verification of 38 load-bearing
claims (13/16 dimensions covered).

Contents (docs/claude-code-architecture/):
- research/  : 16 detailed CC architecture specs (agent loop, canonical
  tools, tool-exec engine, streaming protocol, session/transcript,
  context compaction, system-prompt assembly, memory/CLAUDE.md,
  permissions, hooks, MCP, subagents/Task, skills, slash-commands/plan,
  TUI/IDE/config, sandbox/security)
- audit/     : 6 capability inventories of iroha + ADK/Genkit coupling maps
- gap-analysis.md   : iroha-vs-CC delta, per cluster (present/partial/
  missing/divergent), with the structural ADK-coupling blocker called out
- refactor-plan.md  : native-engine rewrite roadmap (4 decisions + Phase
  0->4) to reach 1:1 fidelity by decoupling from Google ADK/Genkit
- verify-verdicts.md: 38 fact-checks with corrections (e.g. CLAUDE.md is
  injected as a USER message not system prompt; permission order is
  deny->ask->allow; MCP protocol should be 2025-06-18)
- README.md  : master overview + navigation + the core decision

Core cross-confirmed finding: iroha has NO native agent loop -- it is
outsourced to Google ADK's internal Flow.Run. A 1:1 replica therefore
requires replacing the loop driver (not swapping types), reusing the
~85% of the codebase that is already framework-free.

Note: this commit contains only the research/spec deliverable. The
existing modified tracked files in the working tree are unrelated WIP
and are intentionally left uncommitted.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Planckbaka Planckbaka enabled auto-merge (squash) June 14, 2026 02:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant