MCPcopy
hub / github.com/codeaashu/claude-code / contextModifier

Function contextModifier

src/tools/SkillTool/SkillTool.ts:775–839  ·  view source on GitHub ↗
(ctx)

Source from the content-addressed store, hash-verified

773 },
774 newMessages,
775 contextModifier(ctx) {
776 let modifiedContext = ctx
777
778 // Update allowed tools if specified
779 if (allowedTools.length > 0) {
780 // Capture the current getAppState to chain modifications properly
781 const previousGetAppState = modifiedContext.getAppState
782 modifiedContext = {
783 ...modifiedContext,
784 getAppState() {
785 // Use the previous getAppState, not the closure's context.getAppState,
786 // to properly chain context modifications
787 const appState = previousGetAppState()
788 return {
789 ...appState,
790 toolPermissionContext: {
791 ...appState.toolPermissionContext,
792 alwaysAllowRules: {
793 ...appState.toolPermissionContext.alwaysAllowRules,
794 command: [
795 ...new Set([
796 ...(appState.toolPermissionContext.alwaysAllowRules
797 .command || []),
798 ...allowedTools,
799 ]),
800 ],
801 },
802 },
803 }
804 },
805 }
806 }
807
808 // Carry [1m] suffix over — otherwise a skill with `model: opus` on an
809 // opus[1m] session drops the effective window to 200K and trips autocompact.
810 if (model) {
811 modifiedContext = {
812 ...modifiedContext,
813 options: {
814 ...modifiedContext.options,
815 mainLoopModel: resolveSkillModelOverride(
816 model,
817 ctx.options.mainLoopModel,
818 ),
819 },
820 }
821 }
822
823 // Override effort level if skill specifies one
824 if (effort !== undefined) {
825 const previousGetAppState = modifiedContext.getAppState
826 modifiedContext = {
827 ...modifiedContext,
828 getAppState() {
829 const appState = previousGetAppState()
830 return {
831 ...appState,
832 effortValue: effort,

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected