home/roleplay/pre-prompt-optimization

Pre Prompt Optimization

GPTClaudeGemini··1,076 copies·updated 2026-07-14
pre-prompt-optimization.prompt
> **ARCHIVED**: This chapter documents the custom pre-prompt hook skill matching system, which was superseded by Claude Code's native skill loading (v2.1.76+). Kept for historical reference only. See [Skills Activation System](/docs/skill-activation-system) for the current approach.

# Chapter 21: Pre-prompt Optimization (Entry #228)

> **DEPRECATED (Feb 2026)**: The UserPromptSubmit pre-prompt hook is no longer needed. Claude Code now natively discovers and loads skills from `~/.claude/skills/`. The optimization techniques described here are historical. This chapter is kept for reference.

**Status**: Deprecated (Feb 2026) -- was Production-Validated (Jan 1, 2026)
**Difficulty**: Intermediate
**Time**: 45 minutes
**ROI**: 68% reduction (28k→9k chars)

---

## Problem

As Claude Code projects grow, the pre-prompt hook output becomes bloated:

**Symptoms**:

- Pre-prompt exceeds 25k+ characters
- Context loading slow (2-3 seconds per query)
- Skills buried under branch instructions, roadmaps, agent lists
- Duplicate content (skills + agents + context all loaded)

**Root Causes**:

1. Loading full branch instructions (1,500+ chars each)
2. Injecting entire roadmap content (2,000+ chars)
3. Agent descriptions bloated (100+ chars each × 50 agents)
4. No filtering - everything loaded regardless of relevance

---

## Solution: Skills-First Ordering

### Core Principle

> **Show ONLY matched skills FIRST, minimize everything else**

### Key Optimizations

1. **Skills-first ordering** (50% reduction)
   - Move matched skills to TOP of output
   - User message visible immediately after skills
   - Context sections AFTER skills

2. **Branch instruction condensation** (62% reduction)
   - Full instructions: 1,500+ chars → Condensed: 500 chars
   - Keep only: Mission, key skills, quick commands
   - Remove: History, detailed explanations, examples

3. **Agent description trimming** (70% reduction)
   - 100+ chars → 30 chars per agent
   - Format: `agent-name: One-line purpose`
   - Remove: Examples, detailed workflows

4. **Keyword pattern optimization** (29 patterns)
   - Add domain-specific synonyms
   - Multi-word phrase detection
   - Stem matching with constraints

---

## Implementation

### Step 1: Update pre-prompt.sh Structure

when to use it

Community prompt sourced from the open-source GitHub repo ytrofr/claude-code-guide (MIT). A "Pre Prompt Optimization" style prompt — adapt the placeholders and specifics to your task. Imported as-is and not independently retested here, so check the output before relying on it.

tags

roleplaycommunitygeneral

source

ytrofr/claude-code-guide · MIT