engineer_prompt
Engineers and optimizes prompts for Claude Code with interactive refinement and automatic optimization to improve effectiveness.
Instructions
Intelligently engineers and optimizes prompts for Claude Code, with interactive refinement and automatic optimization for maximum effectiveness.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| prompt | Yes | The raw user prompt that needs engineering | |
| language | No | The programming language (optional, will be detected if not provided) | |
| context | No | Additional context about the codebase or project (optional) | |
| interactive | No | Whether to enable interactive Q&A refinement (default: false) |
Implementation Reference
- index.ts:583-623 (handler)Main handler for the engineer_prompt tool in the CallToolRequestSchema. Validates arguments, handles interactive and direct modes, manages sessions, and returns optimized prompts.case "engineer_prompt": { if (!isEngineerPromptArgs(args)) { throw new Error("Invalid arguments for engineer_prompt"); } const { prompt, language, context, interactive } = args; if (interactive) { // Start interactive session const sessionId = generateSessionId(); const detectedInfo = await detectLanguageAndTaskType(prompt); const questions = await generateClarifyingQuestions(prompt, language || detectedInfo.language, context); activeSessions.set(sessionId, { originalPrompt: prompt, context: context ? [context] : [], refinements: [], language: language || detectedInfo.language, complexity: detectedInfo.complexity as any, taskType: detectedInfo.taskType as any }); return { content: [{ type: "text", text: `Interactive prompt engineering session started (ID: ${sessionId}).\n\nTo help create the best prompt for Claude Code, please answer these questions:\n\n${questions.map((q, i) => `${i + 1}. ${q}`).join('\n')}\n\nUse the answer_questions tool with session ID "${sessionId}" to provide your answers.` }], isError: false, }; } else { // Direct prompt engineering const engineeredPrompt = await engineerPrompt(prompt, language, context); return { content: [{ type: "text", text: `**Optimized Prompt for Claude Code:**\n\n${engineeredPrompt}\n\n**Are you ready to proceed with this task?**` }], isError: false, }; } }
- index.ts:27-53 (schema)Tool definition including name, description, and input schema for engineer_prompt.const ENGINEER_PROMPT_TOOL: Tool = { name: "engineer_prompt", description: "Intelligently engineers and optimizes prompts for Claude Code, with interactive refinement and automatic optimization for maximum effectiveness.", inputSchema: { type: "object", properties: { prompt: { type: "string", description: "The raw user prompt that needs engineering" }, language: { type: "string", description: "The programming language (optional, will be detected if not provided)" }, context: { type: "string", description: "Additional context about the codebase or project (optional)" }, interactive: { type: "boolean", description: "Whether to enable interactive Q&A refinement (default: false)" } }, required: ["prompt"], title: "engineer_promptArguments" } };
- index.ts:570-572 (registration)Registers the engineer_prompt tool by including ENGINEER_PROMPT_TOOL in the ListTools response.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [ENGINEER_PROMPT_TOOL, ASK_CLARIFICATION_TOOL, ANSWER_QUESTIONS_TOOL, AUTO_OPTIMIZE_TOOL], }));
- index.ts:462-470 (helper)Internal helper function that performs the core prompt engineering by delegating to generateOptimizedPrompt.async function engineerPrompt( prompt: string, language?: string, context?: string, refinements: string[] = [] ): Promise<string> { // Always use built-in optimization - no external API calls return generateOptimizedPrompt(prompt, language, context, refinements); }
- index.ts:137-149 (schema)Type guard function for validating input arguments to the engineer_prompt tool.function isEngineerPromptArgs(args: unknown): args is { prompt: string; language?: string; context?: string; interactive?: boolean; } { return ( typeof args === "object" && args !== null && "prompt" in args && typeof (args as { prompt: string }).prompt === "string" ); }