Skip to content
Flows
Tier 1 · Claude Code internals Claude Code internals · fetched 2026-07-02

ClaudeCode-Source-Analysis (tammychurchly25)

A ~330-file markdown analysis of the leaked source (512,000+ lines, 1,906 files, TypeScript on Bun), organized module by module from the March 31, 2026 npm source-map leak. Its granularity makes it the best reference for looking up a specific subsystem.

View source on GitHub

Key takeaways

  • 01

    Module-by-module markdown makes subsystem lookup fast

  • 02

    Documents the TypeScript-on-Bun runtime foundation

  • 03

    Useful index into planning/todo machinery and prompt assembly

Flows built on this research

From the archive

Verbatim excerpts mined from our local archive of this repository — the prompts, schemas, and patterns worth stealing.

Prompt

A complete coding-agent system prompt in 40 lines

You are Claude Code, an AI coding assistant by Anthropic...

## Core principles
- Read files before editing them
- Prefer editing existing files over creating new ones
- Write clean, idiomatic, production-quality code matching the project's existing style
- Be concise - lead with the action or answer, not preamble
- Run tests after making changes when appropriate
- Security: never introduce SQL injection, XSS, command injection, or other vulnerabilities
- Don't add features or refactor beyond what was asked

## Workflow guidance
- Use Agent to delegate complex parallel sub-tasks
- Use TodoWrite to track multi-step plans
- Use EnterPlanMode before making significant architectural changes
- Use EnterWorktree to safely experiment on a separate git branch

A Rust reimplementation's distillation of the Claude Code prompt down to its load-bearing rules - a strong starting template for any coding agent.

claude-code-rust/src-rust/crates/cli/src/system_prompt.txt

Agent pattern

The agent main loop as pseudocode, compaction included

J = initialTurnState(input)
while (true):
  yield stream_request_start
  F = normalize(messages)
  F = applyContentReplacement(F)
  F = microcompact(F)          // old tool_result text -> '[Old tool result content cleared]'

  { compactionResult } = autocompact(F, cacheSafeSnapshot, tracking)
  if compacted:
    yield compact boundary / summary / attachments
    F = compacted transcript

  for await event from callModel(...):
    yield raw stream_event + assistant fragments + partial tool results
    if streaming fallback happened:
      yield tombstone for orphaned messages; reset tool runner

  if no tool_use in this turn:
    handle reactive compact / max_output_tokens

[translated] The clearest public reconstruction of a production agent loop: microcompact clears old tool results cheaply every turn, full autocompact only fires past a threshold.

HitCC/docs/01-runtime/04-agent-loop-and-compaction/01-main-loop-state-caches-and-yield-surface.md