Skip to content

Instantly share code, notes, and snippets.

@gwythyr
Last active February 4, 2026 12:02
Show Gist options
  • Select an option

  • Save gwythyr/eb23f36f3cf7b58b1c5b5a85f467ba1c to your computer and use it in GitHub Desktop.

Select an option

Save gwythyr/eb23f36f3cf7b58b1c5b5a85f467ba1c to your computer and use it in GitHub Desktop.
Customize prompt for Claude Code compatibility
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
const PI_TO_SDK_TOOL_NAME: Record<string, string> = {
read: "Read",
write: "Write",
edit: "Edit",
bash: "Bash",
grep: "Grep",
find: "Glob",
glob: "Glob",
};
const toolDescriptions: Record<string, string> = {
read: "Read file contents",
bash: "Execute bash commands (ls, grep, find, etc.)",
edit: "Make surgical edits to files (find exact text and replace)",
write: "Create or overwrite files",
grep: "Search file contents for patterns (respects .gitignore)",
find: "Find files by glob pattern (respects .gitignore)",
ls: "List directory contents",
};
function buildGuidelines(tools: string[]): string[] {
const guidelines: string[] = [];
const hasBash = tools.includes("bash");
const hasEdit = tools.includes("edit");
const hasWrite = tools.includes("write");
const hasGrep = tools.includes("grep");
const hasFind = tools.includes("find");
const hasLs = tools.includes("ls");
const hasRead = tools.includes("read");
if (hasBash && !hasGrep && !hasFind && !hasLs) {
guidelines.push("Use bash for file operations like ls, rg, find");
} else if (hasBash && (hasGrep || hasFind || hasLs)) {
guidelines.push("Prefer grep/find/ls tools over bash for file exploration (faster, respects .gitignore)");
}
if (hasRead && hasEdit) {
guidelines.push("Use read to examine files before editing. You must use this tool instead of cat or sed.");
}
if (hasEdit) {
guidelines.push("Use edit for precise changes (old text must match exactly)");
}
if (hasWrite) {
guidelines.push("Use write only for new files or complete rewrites");
}
if (hasEdit || hasWrite) {
guidelines.push(
"When summarizing your actions, output plain text directly - do NOT use cat or bash to display what you did",
);
}
guidelines.push("Be concise in your responses");
guidelines.push("Show file paths clearly when working with files");
return guidelines;
}
function buildCustomSystemPrompt(selectedTools: string[] = ["read", "bash", "edit", "write"]): string {
const tools = selectedTools.filter((t) => t in toolDescriptions);
const toolsList = tools.map((t) =>
`- ${PI_TO_SDK_TOOL_NAME[t]}: ${toolDescriptions[t]}`).join("\n");
const guidelines = buildGuidelines(tools);
const guidelinesText = guidelines.map((g) => `- ${g}`).join("\n");
// Customize this prompt to your needs
return `You are Claude Code, Anthropic's official CLI for Claude. You are an expert coding assistant.
Available tools:
${toolsList}
In addition to the tools above, you may have access to other custom tools depending on the project.
Guidelines:
${guidelinesText}
`;
}
const extension = (pi: ExtensionAPI) => {
pi.on("before_agent_start", async (_event) => {
// Return systemPromptAppend instead of systemPrompt
// This preserves Claude Code SDK's built-in CLAUDE.md handling
return {
systemPrompt: buildCustomSystemPrompt(),
};
});
return { name: "custom-prompt" };
};
export default extension;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment