CodeVetter · Repo Unpack · Behavior traces
anthropics/claude-code
Three product flows and two repo-ops flows are fully readable in-tree. Session start for agents-md only logs and then waits for prompt.context. /diff binds a host, registers the command, probes git lazily, and draws on ui.render. Telemetry attaches in engine.create and flushes on a timer or session.end. A new GitHub issue fans out to triage, dedupe, and an optional repository_dispatch. A file edit under security-guidance is pattern-matched before any LLM call.
- agents-md startup: register() calls Modes.modeOf(options.instructionFiles) and Modes.legacyModeOf(options.projectInstructions). If the legacy key is set and the named mode is DEFAULT_MODE, the legacy mode wins. on('session.start') calls Telemetry.quietly($.telemetry.log(Telemetry.modeRowOf(...))) and maybe $.ui.log about projectInstructions, then next(e). Mode claude-md returns immediately. Mode managed-only registers one prompt.context filter and returns.
- agents-md primary load, in order: prompt.context reads e.instructionFiles; if isFallback, $.session.root(); $.fs.ancestors({names: Names.CLAUDE_NAMES}) to decide isClaudeProject; if not a Claude project, $.fs.ancestors({names: Names.AGENTS_NAMES}); Files.filesOf then Files.unseenFiles; once per load Telemetry.loadCountsOf, $.telemetry.log(loadRow), $.telemetry.mark(loadMark); $.ui.log the root files; Files.withProjectFiles; next({...e, instructionFiles}). Later Read calls attachesOnRead ($.env.get CLAUDE_CODE_SIMPLE and CLAUDE_CODE_DISABLE_ATTACHMENTS) then homeOf, Frames.absoluteOf, two ancestors walks, Frames.nestedFrame.
- Diff session start, in order: on('session.start') builds a Host wrapping $.clock.now/after/every, $.process.run, $.fs.stat/list/read, $.store.get/set, isCheckpointing($.settings.read + $.env.get('CLAUDE_CODE_DISABLE_FILE_CHECKPOINTING')), $.session.messages/id/usage, $.ui.*, $.command.register, $.telemetry.mark/log. bind() sets sessionStartMs from usage().startedAt or clock.now(), sets pin.cwd, and $.command.register(COMMAND_SPEC). If the error matches Names.BUILTIN_HOLDS_PATTERN the plugin stays idle; other errors $.ui.log a sanitized reason. If host bound, openOnRestore runs unawaited, then next(e).
- /diff command run, in order: command.run matcher Names.COMMAND_NAME; if no host, next(e); pinBackend (probeBackend -> Backend.backendOf -> Git.gitBackendOf -> Probes.repositoryOf); if no backend, return NOT_IN_REPOSITORY_TEXT or GIT_UNANSWERED_TEXT; read e.presentation.isFullscreen and columns; PaneToggle.paneToggleOf; too-narrow returns RESIZE_TERMINAL_TEXT; openPane or closePane; fullscreen stores Names.STORE_OPEN_KEY and returns PANEL_SHOWN_TEXT or PANEL_HIDDEN_TEXT; inline open returns {}. Drawing is a later ui.render Pane: $.ui.resolve then Views.paneView.
- Diff after an edit, in order: tool.call matcher EDITING_TOOLS plus SHELL_TOOLS; result = await next(e); finally afterTool. afterTool counts a landed edit only when deny is unset and isError is not true. If the pane is open, scheduleRefresh. If the edit is on the main loop (e.agentId undefined), openOnFirstEdit. clear/resume calls next first, then unpin (drops backend, bumps pin.epoch, cancels the poll timer), resets model via PaneState.afterNewSession, and on resume calls openOnRestore.
- Telemetry startup and send, in order: on('telemetry.*') Gate.served, with .catch Gate.caught; session.start stores e.isInteractive and next(e); engine.create awaits next(e), calls telemetryOf(deps), returns {...beneath, telemetry}. A log() runs checkedFields then queued(): push {fields, crypto.randomUUID(), ISO time}; if pending.length >= 100, flush(); else clock.after(5000). flush() calls sendingEnvironment -> isAnalyticsOff; deps.authorize(); gathered() context; postedWithRetry; session.end awaits sender.flush() then next(e).
- sec-default tool.register order: if next.origin.tier is prepend or append, next.to(e, 'append'). Else if tier is user and Policy.decidedByPolicy(readPolicy(() => $.settings.read({source:'policy'})), Policy.hasMcpAllowlist) is true, return {deny: 'allowedMcpServers (managed): plugins outside policy may not add tools'}. Otherwise next(e). readPolicy is Policy.createPolicyMemo(POLICY_MEMO_MS). An unreadable policy fails closed. tool.list merges Policy.managedToolsRestored(policy, next.to(e,'append'), next(e)).
- security-guidance PostToolUse order inside main(): if SECURITY_GUIDANCE_DISABLED, emit_metrics skip_reason -1 and exit 0. Parse stdin. extensibility.load_for_session(cwd). On PostToolUse, _maybe_bootstrap_agent_sdk_async. UserPromptSubmit -> handle_user_prompt_submit and return. Stop -> handle_stop_hook and return. Bash -> require _GIT_COMMIT_RE or _GIT_PUSH_RE, then _claim_bash_hook_once; commit is checked before push so 'git commit && git push' still reviews the commit once. Edit/Write/MultiEdit/NotebookEdit -> skip ~/.claude/plans, record_touched_path, extract_content_from_input, check_patterns, suppress baseline matches on Write, atomic_check_and_mark_warning, print metrics plus additionalContext.
- New-issue GitHub path: issues.opened triggers, in separate workflows, claude-issue-triage.yml (prompt /triage-issue, concurrency group issue-triage-<number>, cancel-in-progress), claude-dedupe-issues.yml (prompt /dedupe), and issue-opened-dispatch.yml which calls gh api repos/${ISSUE_OPENED_DISPATCH_TARGET_REPO}/dispatches event_type issue_opened and exits 0 even when that call fails. Triage must not comment; it only adds or removes labels through edit-issue-labels.sh. Dedupe may comment only via comment-on-duplicates.sh, which reads the issue number from GITHUB_EVENT_PATH and hardcodes REPO=anthropics/claude-code.
- Stale close path: sweep markStale computes cutoff from the stale lifecycle days, pages open issues sorted updated asc (max 10 pages), skips PRs, locked, assigned, already stale/autoclose, and +1 >= 10, then POSTs label stale. closeExpired for each lifecycle entry reads issue events for the last labeled time, skips if a non-bot comment arrived after the label, else POSTs CLOSE_MESSAGE and PATCHes state closed, state_reason not_planned. --dry-run logs only.