MCPcopy Index your code
hub / github.com/codeaashu/claude-code / getAttachments

Function getAttachments

src/utils/attachments.ts:743–1003  ·  view source on GitHub ↗
(
  input: string | null,
  toolUseContext: ToolUseContext,
  ideSelection: IDESelection | null,
  queuedCommands: QueuedCommand[],
  messages?: Message[],
  querySource?: QuerySource,
  options?: { skipSkillDiscovery?: boolean },
)

Source from the content-addressed store, hash-verified

741 * TODO: Generate attachments when we create messages
742 */
743export async function getAttachments(
744 input: string | null,
745 toolUseContext: ToolUseContext,
746 ideSelection: IDESelection | null,
747 queuedCommands: QueuedCommand[],
748 messages?: Message[],
749 querySource?: QuerySource,
750 options?: { skipSkillDiscovery?: boolean },
751): Promise<Attachment[]> {
752 if (
753 isEnvTruthy(process.env.CLAUDE_CODE_DISABLE_ATTACHMENTS) ||
754 isEnvTruthy(process.env.CLAUDE_CODE_SIMPLE)
755 ) {
756 // query.ts:removeFromQueue dequeues these unconditionally after
757 // getAttachmentMessages runs — returning [] here silently drops them.
758 // Coworker runs with --bare and depends on task-notification for
759 // mid-tool-call notifications from Local*Task/Remote*Task.
760 return getQueuedCommandAttachments(queuedCommands)
761 }
762
763 // This will slow down submissions
764 // TODO: Compute attachments as the user types, not here (though we use this
765 // function for slash command prompts too)
766 const abortController = createAbortController()
767 const timeoutId = setTimeout(ac => ac.abort(), 1000, abortController)
768 const context = { ...toolUseContext, abortController }
769
770 const isMainThread = !toolUseContext.agentId
771
772 // Attachments which are added in response to on user input
773 const userInputAttachments = input
774 ? [
775 maybe('at_mentioned_files', () =>
776 processAtMentionedFiles(input, context),
777 ),
778 maybe('mcp_resources', () =>
779 processMcpResourceAttachments(input, context),
780 ),
781 maybe('agent_mentions', () =>
782 Promise.resolve(
783 processAgentMentions(
784 input,
785 toolUseContext.options.agentDefinitions.activeAgents,
786 ),
787 ),
788 ),
789 // Skill discovery on turn 0 (user input as signal). Inter-turn
790 // discovery runs via startSkillDiscoveryPrefetch in query.ts,
791 // gated on write-pivot detection — see skillSearch/prefetch.ts.
792 // feature() here lets DCE drop the 'skill_discovery' string (and the
793 // function it calls) from external builds.
794 //
795 // skipSkillDiscovery gates out the SKILL.md-expansion path
796 // (getMessagesForPromptSlashCommand). When a skill is invoked, its
797 // SKILL.md content is passed as `input` here to extract @-mentions —
798 // but that content is NOT user intent and must not trigger discovery.
799 // Without this gate, a 110KB SKILL.md fires ~3.3s of chunked AKI
800 // queries on every skill invocation (session 13a9afae).

Callers 1

getAttachmentMessagesFunction · 0.85

Calls 15

isEnvTruthyFunction · 0.85
createAbortControllerFunction · 0.85
maybeFunction · 0.85
processAtMentionedFilesFunction · 0.85
processAgentMentionsFunction · 0.85
featureFunction · 0.85
getDateChangeAttachmentsFunction · 0.85

Tested by

no test coverage detected