Automatically triggers code simplification after non-markdown code changes, using the simplify-code prompt template.
- Auto-Trigger: Automatically runs after non-markdown code changes
- Project Standards: Applies patterns from your
AGENTS.md(ES modules, type annotations, etc.) - Smart Detection: Skips if only markdown files were changed
- Manual Trigger: Use
/simplify-codecommand anytime
The extension tracks file changes during an agent session:
- Path Tracking: Every time
write,edit, orapply_patchtools are called, the extension records the modified file paths - Auto-Trigger Check: At
agent_end, the extension checks:- Whether any files were modified
- Whether any non-markdown files were modified (
.md,.mdx,.markdownare skipped) - Whether the trigger came from the extension itself (to avoid loops)
- Follow-up Message: If conditions are met, sends a follow-up message like:
/simplify-code The following code paths have changed: - src/api/client.ts - src/utils/helpers.ts - tests/example.test.ts
The simplification behavior is defined in prompts/simplify-code.md. This prompt template:
- Contains the refinement instructions for the LLM
- Can be invoked manually with
/simplify-code [context] - Applies project-specific best practices from
AGENTS.md
Manually trigger code simplification with optional context:
/simplify-code
/simplify-code Focus on the auth module
/simplify-code The following files need review: src/auth.ts src/session.tsThe context is appended to the prompt instructions and provides additional guidance to the LLM.
The prompt template refines code to improve:
- Clarity: Reduces unnecessary complexity and nesting
- Consistency: Applies project-wide coding standards
- Maintainability: Improves variable/function names and structure
- Balance: Avoids over-simplification that harms readability
- Preserves exact functionality (never changes behavior)
- Prefers
functionkeyword over arrow functions - Uses explicit return type annotations
- Avoids nested ternary operators (use switch/if-else instead)
- Removes redundant comments for obvious code
- Chooses clarity over brevity
The extension automatically triggers after agent_end events when:
- At least one file was modified
- At least one non-markdown file was modified (
.md,.mdx,.markdownare skipped) - The trigger didn't come from the extension itself (prevents loops)
Customize simplification behavior by editing prompts/simplify-code.md:
- Adjust refinement priorities
- Add project-specific rules
- Modify the balance between simplicity and clarity
Extension (pi-extensions/simplify-code/index.ts)
↓
Tracks file changes via tool_call events
↓
At agent_end, sends: /simplify-code [paths]
↓
Prompt Template (prompts/simplify-code.md)
↓
Expanded and sent to LLM
↓
LLM simplifies the changed code
This separation of concerns allows:
- Extension: Handles state tracking and timing
- Prompt: Defines simplification behavior
- Users: Can invoke
/simplify-codemanually with custom context
- Skips markdown-only changes ([ref: simplify_code_skip_markdown_only])
- The
/simplify-codecommand is a prompt template, not an extension command - Changes are committed after simplification by the LLM