InkdownInkdown
Start writing

Claude-Code

62 filesยท4 subfolders

Shared Workspace

Claude-Code
codex

0300_codebase_modules_layers_state_models_and_schemas

Shared from "Claude-Code" on Inkdown

Module Boundaries, Layers, State Models, And Schema Contracts

Core Runtime Layers

  1. Entry and bootstrap layer Files: entrypoints/cli.tsx, main.tsx, entrypoints/init.ts, setup.ts. Responsibility: process boot, trust-sensitive initialization, and branch selection between interactive, headless, and bridge modes.
  2. Session state and config layer Files: , , , , . Responsibility: process-global counters, user and project settings, global config, and mutable AppState.
0000_start_here_index_and_recommended_reading_order.md
0100_project_overview_tech_stack_runtime_modes_and_folder_map.md
0200_startup_flow_entry_points_and_cold_start_sequence.md
0300_codebase_modules_layers_state_models_and_schemas.md
0400_system_architecture_and_design_rationale.md
0500_interactive_repl_request_flow_end_to_end.md
0600_headless_sdk_and_print_mode_request_flow_end_to_end.md
0700_mcp_integration_connection_and_tool_call_flow.md
0800_external_services_sdks_storage_and_local_dependencies.md
0900_environment_variables_settings_feature_flags_and_failure_modes.md
1000_non_obvious_patterns_gotchas_and_debugging_traps.md
1100_full_codebase_file_inventory_grouped_by_directory.md
kimi
00-overview.md
01-entrypoints.md
02-state-management.md
03-query-system.md
04-tools-system.md
05-tasks-system.md
06-ui-components.md
07-bridge-remote.md
08-services.md
09-skills-plugins.md
10-commands.md
11-testing-architecture.md
12-permission-system.md
13-build-system.md
14-ink-internals.md
15-git-internals.md
16-context-compaction.md
17-vim-mode.md
18-mailbox-notifications.md
19-session-persistence.md
20-hooks-system.md
21-error-recovery.md
README.md
qwen
00-overview.md
01-entry-points.md
02-query-engine.md
03-tools-and-tasks.md
04-commands-and-skills.md
05-state-management.md
06-ink-rendering.md
07-bridge-remote.md
08-mcp-services.md
09-services-overview.md
10-multi-agent.md
11-system-prompt-constants.md
12-tool-interface.md
13-memory-system.md
14-buddy-companion.md
15-keybindings.md
16-stop-hooks.md
17-vim-mode.md
18-upstreamproxy.md
19-cost-tracking-history.md
20-contexts-styles-onboarding.md
21-hooks.md
22-screens.md
tweets-explain
claude-code-memory-analysis.md
compact
memory-system
agentic-architecture
bootstrap/state.ts
state/AppStateStore.ts
state/store.ts
utils/config.ts
utils/settings/settings.ts
  • Command layer Files: commands.ts plus commands/*. Responsibility: human-triggered slash and local commands.
  • Tool layer Files: Tool.ts, tools.ts, tools/*. Responsibility: model-callable tool contracts, schemas, concurrency behavior, UI, and registration.
  • Query and execution layer Files: query.ts, QueryEngine.ts, services/tools/*, services/api/claude.ts. Responsibility: turn execution, streaming, compacting, retry behavior, tool orchestration, and provider interaction.
  • UI layer Files: screens/REPL.tsx, components/*, hooks/*, ink/*. Responsibility: interactive rendering, prompt input, dialogs, task views, and notifications.
  • Integration and service layer Files: services/*, bridge/*, remote/*, upstreamproxy/*. Responsibility: MCP, analytics, OAuth, remote managed settings, bridge and CCR, plugin operations, policy limits, and other integrations.
  • Platform and helper layer Files: utils/*, types/*, constants/*, schemas/*. Responsibility: filesystem, git, session storage, permissions, plugins, telemetry, text processing, and shared schemas.
  • Most Important Shared Data Models

    Tool Contract
    • Tool.ts defines the shared tool contract and ToolUseContext.
    • ToolUseContext carries the current tools, commands, MCP clients and resources, app state getters and setters, permission context, messages, and turn-scoped helpers.
    • ToolPermissionContext is the normalized permission state passed through the runtime.
    • Why it matters: every model-callable tool, permission handler, and tool execution path depends on this shape.
    AppState
    • state/AppStateStore.ts defines AppState.
    • It contains session settings, command and tool state, plugin and MCP state, notifications, tasks, attribution and file-history state, bridge and remote status, and many UI toggles.
    • Why it matters: it is the shared contract between runtime core and both surfaces, the interactive REPL and headless session-state notifications.
    Query Contracts
    • QueryEngineConfig in QueryEngine.ts describes the long-lived conversation owner for headless and SDK flows.
    • QueryParams in query.ts describes one low-level turn.
    • Why it matters: QueryEngine owns conversation persistence across turns; query.ts owns one agentic turn.
    Settings Schemas
    • utils/settings/types.ts defines SettingsJson, PermissionsSchema, environment variable schema, marketplace schema, and MCP allow and deny entries.
    • utils/settings/settings.ts loads, merges, caches, validates, and updates those settings across sources.
    Project And Global Config
    • utils/config.ts defines ProjectConfig and GlobalConfig.
    • These are file-backed client state rather than desired behavior settings. They hold onboarding, trust, worktree state, plugin metadata, preferences, and recorded session state.
    MCP Configuration And Connection Types
    • services/mcp/types.ts defines transport schemas such as stdio, sse, http, ws, and sdk, plus scope values and runtime connection states.
    • services/mcp/config.ts builds the merged MCP config set.
    • services/mcp/client.ts turns config into live connections plus tool, resource, and command exposure.

    Import Relationship Hotspots

    ModuleIncoming imports
    ink.ts429
    utils/debug.ts370
    services/analytics/index.ts264
    bootstrap/state.ts260
    utils/errors.ts248
    utils/log.ts243
    utils/envUtils.ts220
    utils/slowOperations.ts206
    utils/config.ts155
    utils/settings/settings.ts138
    utils/messages.ts134
    services/analytics/growthbook.ts131
    state/AppState.tsx108
    utils/cwd.ts104
    utils/auth.ts104
    utils/format.ts102
    utils/fsOperations.ts96
    utils/lazySchema.ts95
    keybindings/useKeybinding.ts94
    utils/stringUtils.ts82

    Interpretation:

    • ink.ts is the UI facade shared throughout the interactive client.
    • bootstrap/state.ts, Tool.ts, and commands.ts are system-wide contracts.
    • utils/debug.ts, utils/errors.ts, utils/log.ts, and utils/config.ts are pervasive platform helpers.
    • services/analytics/index.ts is cross-cutting because feature flags and telemetry are consulted all over the runtime.

    Circular Dependency Notes

    • Visible cycle: main.tsx -> dialogLaunchers.tsx -> interactiveHelpers.tsx -> main.tsx. This exists because startup helpers and one-off dialog launchers are split out of main.tsx but still need its deferred prefetch helper.
    • Visible cycle: utils/stats.ts <-> utils/statsCache.ts. Small helper and cache pair.
    • Several tool and UI pairs have local cycles, such as tools/RemoteTriggerTool/*, tools/SendMessageTool/*, tools/TeamCreateTool/*, and tools/TeamDeleteTool/*.
    • The larger dependency knot is mostly architectural density around shared command, UI, runtime, and state contracts rather than one startup-only bug.