MCPcopy
hub / github.com/claude-code-best/claude-code / processInitialMessage

Function processInitialMessage

src/screens/REPL.tsx:3854–3962  ·  view source on GitHub ↗
(initialMsg: NonNullable<typeof pending>)

Source from the content-addressed store, hash-verified

3852 initialMessageRef.current = true;
3853
3854 async function processInitialMessage(initialMsg: NonNullable<typeof pending>) {
3855 // Clear context if requested (plan mode exit)
3856 if (initialMsg.clearContext) {
3857 // Preserve the plan slug before clearing context, so the new session
3858 // can access the same plan file after regenerateSessionId()
3859 const oldPlanSlug = initialMsg.message.planContent ? getPlanSlug() : undefined;
3860
3861 const { clearConversation } = await import('../commands/clear/conversation.js');
3862 await clearConversation({
3863 setMessages,
3864 readFileState: readFileState.current,
3865 discoveredSkillNames: discoveredSkillNamesRef.current,
3866 loadedNestedMemoryPaths: loadedNestedMemoryPathsRef.current,
3867 getAppState: () => store.getState(),
3868 setAppState,
3869 setConversationId,
3870 });
3871 haikuTitleAttemptedRef.current = false;
3872 setHaikuTitle(undefined);
3873 bashTools.current.clear();
3874 bashToolsProcessedIdx.current = 0;
3875
3876 // Restore the plan slug for the new session so getPlan() finds the file
3877 if (oldPlanSlug) {
3878 setPlanSlug(getSessionId(), oldPlanSlug);
3879 }
3880 }
3881
3882 // Atomically: clear initial message, set permission mode and rules
3883 setAppState(prev => {
3884 // Build and apply permission updates (mode + allowedPrompts rules)
3885 let updatedToolPermissionContext = initialMsg.mode
3886 ? applyPermissionUpdates(
3887 prev.toolPermissionContext,
3888 buildPermissionUpdates(initialMsg.mode, initialMsg.allowedPrompts),
3889 )
3890 : prev.toolPermissionContext;
3891 // For auto, override the mode (buildPermissionUpdates maps
3892 // it to 'default' via toExternalPermissionMode) and strip dangerous rules
3893 if (feature('TRANSCRIPT_CLASSIFIER') && initialMsg.mode === 'auto') {
3894 updatedToolPermissionContext = stripDangerousPermissionsForAutoMode({
3895 ...updatedToolPermissionContext,
3896 mode: 'auto',
3897 prePlanMode: undefined,
3898 });
3899 }
3900
3901 return {
3902 ...prev,
3903 initialMessage: null,
3904 toolPermissionContext: updatedToolPermissionContext,
3905 };
3906 });
3907
3908 // Create file history snapshot for code rewind
3909 if (fileHistoryEnabled()) {
3910 void fileHistoryMakeSnapshot((updater: (prev: FileHistoryState) => FileHistoryState) => {
3911 setAppState(prev => ({

Callers 1

REPLFunction · 0.85

Calls 14

getPlanSlugFunction · 0.85
clearConversationFunction · 0.85
setPlanSlugFunction · 0.85
getSessionIdFunction · 0.85
applyPermissionUpdatesFunction · 0.85
buildPermissionUpdatesFunction · 0.85
fileHistoryEnabledFunction · 0.85
fileHistoryMakeSnapshotFunction · 0.85
createAbortControllerFunction · 0.85
getStateMethod · 0.80
setAppStateFunction · 0.50

Tested by

no test coverage detected