Developer Reference · v4.0

Documentation

Everything you need to integrate, configure, and get the most from Prompt Control Plane.

Getting Started

Installation

Choose any of the four install methods below. The recommended approach is the MCP config, which requires zero global installs.

1 MCP Config (recommended)

Add the following to your .mcp.json or claude_desktop_config.json:

{ "mcpServers": { "prompt-optimizer": { "command": "npx", "args": ["-y", "claude-prompt-optimizer-mcp"] } } }

2 npx (no install)

npx -y claude-prompt-optimizer-mcp

3 npm global

npm install -g claude-prompt-optimizer-mcp

4 curl

curl -fsSL https://prompt-control-plane.pages.dev/install.sh | bash

Your First Optimization

Once installed, use the optimize_prompt tool in any MCP-compatible client (Claude Code, Cursor, Windsurf). Here is a step-by-step walkthrough:

1 Send a raw prompt to optimize_prompt:

// In your MCP client, call: optimize_prompt({ raw_prompt: "Write something about our product launch", target: "claude" })

2 Review the PreviewPack response. It contains:

3 Answer blocking questions (if any) using refine_prompt:

refine_prompt({ session_id: "abc-123", answers: { "q_audience": "existing customers" } })

4 Approve the final result:

approve_prompt({ session_id: "abc-123" })

Key principle: All analysis is deterministic. The same input always produces the same output. Zero LLM calls happen inside the MCP — all intelligence comes from the host model (Claude, GPT, etc.).

Architecture

Prompt Control Plane processes your prompts before they reach any LLM. It is a pre-LLM quality gate — every prompt is scored, analyzed, compiled, and policy-checked before execution. Zero LLM calls inside.

User writes a prompt raw prompt Prompt Control Plane All processing happens here — before the prompt reaches any LLM Policy Gate Enterprise only 1. Analyze Intent 2. Score Quality (0–100) 3. Run 14 Rules + Custom Rules* 4. Compute Risk Score (0–100) 5. Compile → Claude / OpenAI / MD 6. Estimate Cost (4 providers) 7. Route to Optimal Model Audit Log Enterprise only *Enterprise PreviewPack compiled_prompt + quality_score + risk_score + cost_estimate + model_recommendation User reviews / refines / approves approved prompt LLM Execution

The pipeline analyzes intent, scores quality, detects risks, compiles to your target format, estimates cost across providers, and routes to the optimal model. The result is packaged into a PreviewPack for human review — nothing reaches the LLM until the user approves.

What’s in a PreviewPack?

Every call to optimize_prompt, refine_prompt, or pre_flight returns a PreviewPack — a complete analysis bundle for human review before anything is sent to an LLM.

Field Type Description Tier
request_id string Unique ID for traceability All
session_id string Session identifier for iterative refinement All
quality_before QualityScore Multi-dimensional quality score (0–100) with traceable deductions All
compiled_prompt string The optimized prompt in target format (Claude XML, OpenAI, or Markdown) All
intent_spec IntentSpec Decomposed intent: task type, audience, tone, constraints, definition of done All
compilation_checklist object 9-item structural coverage checklist (role, goal, constraints, etc.) All
blocking_questions Question[] Questions that must be resolved before the prompt is ready All
assumptions Assumption[] Assumptions made during compilation (review & override) All
cost_estimate CostEstimate Token counts + cost across 11 models from 4 providers All
model_recommendation string Optimal model based on task complexity, risk, and budget All
changes_made string[] List of modifications applied during compilation All
target OutputTarget claude (XML), openai (system/user), or generic (Markdown) All
storage_health "ok" | "degraded" Storage status — pipeline continues in degraded mode with fail-open semantics All

Enterprise-only pipeline stages that influence the PreviewPack:

Verification

Prompt Control Plane is designed to be trustworthy by default. Here’s what that means in practice.

Guarantee What It Means For You
Reproducible results Run the same prompt twice — get the same score, same routing, same cost estimate. No randomness, ever.
Accurate cost estimates Pricing verified against live provider rates for Anthropic, OpenAI, Google, and Perplexity. Updated regularly.
Reliable quality scores Multi-dimensional scoring catches vagueness, missing constraints, scope creep, and hallucination risk — before the prompt reaches an LLM.
Safe compression Guaranteed to never increase token count. Code blocks, tables, and structured content are always preserved.
Stable contracts Output shapes are locked and versioned. Integrations won’t break across updates.
Fully offline Zero external calls. Your prompts never leave your machine. No API keys required for analysis.
Tamper-evident audit Cryptographically chained log of every decision. If any entry is modified, the chain breaks. (Enterprise)

Extensively tested. Run the suite yourself to verify — completes in under 5 seconds.

Tool Reference

Prompt Control Plane exposes 19 tools via MCP. Three are metered (count against your plan); the rest are free and unlimited. Every response includes a request_id for traceability.

All 19 Tools at a Glance

Tool Category Cost Plan
optimize_promptAnalysisMeteredAll Plans
check_promptAnalysisFreeAll Plans
classify_taskAnalysisFreeAll Plans
route_modelRoutingFreeAll Plans
pre_flightRoutingMeteredAll Plans
refine_promptRefinementMeteredAll Plans
approve_promptRefinementFreeAll Plans
estimate_costCostFreeAll Plans
compress_contextCostFreeAll Plans
prune_toolsCostFreeAll Plans
configure_optimizerConfigFreeAll Plans*
get_usageConfigFreeAll Plans
prompt_statsConfigFreeAll Plans
set_licenseLicenseFreeAll Plans
license_statusLicenseFreeAll Plans
list_sessionsSessionsFreeEnterprise
export_sessionSessionsFreeEnterprise
delete_sessionSessionsFreeEnterprise
purge_sessionsSessionsFreeEnterprise

*configure_optimizer: Enterprise settings (policy_mode, audit_log, config lock, session_retention_days) require Enterprise tier.

🔍 Analysis 3 tools
optimize_prompt Metered All Plans

The main entry point. Analyzes a raw prompt, detects ambiguities, compiles an optimized version, scores quality, and estimates cost across providers. Returns a PreviewPack for review.

Parameters
raw_prompt string required The raw user prompt to optimize (max 100KB)
context string Optional context: repo info, file contents, preferences
target "claude" | "openai" | "generic" Output target format (default: "claude")
Returns

PreviewPack — Contains session_id, quality_before (0–100), compiled_prompt, blocking_questions, assumptions, cost_estimate, model_recommendation, compilation_checklist, and changes_made.

check_prompt Free All Plans

Quick pass/fail check of a prompt. Returns a quality score, the top issues detected, and a suggestion for improvement. No compilation, no session. Ideal for CI gates or lightweight checks.

Parameters
raw_prompt string required The prompt to check
context string Optional context
Returns

Quality score (0–100), pass/fail verdict based on configured strictness threshold, top 2 issues, and an improvement suggestion.

classify_task Free All Plans

Classifies a prompt by task type (13 types), reasoning complexity (6 levels), dimensional risk score, and suggests an optimization profile. Useful for understanding a prompt before committing to optimization.

Parameters
prompt string required The prompt to classify
context string Optional context
Returns

taskType, complexity (simple_factual / analytical / multi_step / creative / long_context / agent_orchestration), riskScore (0–100), riskDimensions (underspec, hallucination, scope, constraint), suggestedProfile, and signals.

🧭 Routing 2 tools
route_model Free All Plans

Routes to the optimal model based on task complexity, risk, budget, and latency preferences. Returns a full recommendation with a decision_path audit trail showing every routing decision. Two-step routing: (1) complexity + risk determine the default tier, (2) budget/latency overrides produce the final tier.

Parameters
prompt string Raw prompt text for auto-classification
context string Optional context
taskType TaskType Override auto-detected task type
complexity ReasoningComplexity Override auto-detected complexity
profile OptimizationProfile One of: cost_minimizer, balanced, quality_first, creative, enterprise_safe
budgetSensitivity "low" | "medium" | "high" Budget constraint
latencySensitivity "low" | "medium" | "high" Latency constraint
target OutputTarget Provider preference (default: "claude")
Returns

ModelRecommendation — Contains primary (model, provider, temperature, maxTokens), fallback, confidence (0–100), costEstimate, rationale, tradeoffs, savings_vs_default, and decision_path array.

pre_flight Metered All Plans

Full pre-flight analysis in a single call: classifies task, assesses risk, routes model, and scores quality. Returns a complete decision bundle. Counts as 1 metered use (does NOT call optimize_prompt internally).

Parameters
prompt string required The prompt to analyze
context string Optional context
profile OptimizationProfile Optimization profile
budgetSensitivity "low" | "medium" | "high" Budget constraint
latencySensitivity "low" | "medium" | "high" Latency constraint
target OutputTarget Output target
Returns

Task classification, complexity result, risk score with dimensions, model recommendation with decision_path, quality score, cost estimate, and pre-flight deltas (estimated token savings from compression and pruning).

✏️ Refinement 2 tools
refine_prompt Metered All Plans

Refines a prompt by answering blocking questions or providing manual edits. Re-runs the full analysis pipeline and returns an updated PreviewPack.

Parameters
session_id string required Session ID from optimize_prompt
answers Record<string, string> Answers to blocking questions: { question_id: answer }
edits string Manual edits or additional context
target OutputTarget Change output target
Returns

Updated PreviewPack with re-scored quality, re-compiled prompt, and reduced blocking questions.

approve_prompt Free All Plans

Sign-off gate. Approves the compiled prompt and returns the final optimized prompt ready for use. Fails if blocking questions remain. In Enterprise enforce mode, runs a policy enforcement check before allowing approval.

Parameters
session_id string required Session ID from optimize_prompt
Returns

The final compiled prompt, quality score before compilation, and the compilation checklist summary.

💰 Cost & Compression 3 tools
estimate_cost Free All Plans

Estimates token count and cost across all supported providers for any prompt text. No session needed. Covers 11 models from Anthropic, OpenAI, Google, and Perplexity.

Parameters
prompt_text string required The prompt text to estimate
target OutputTarget Target platform for model recommendations
Returns

CostEstimate — Contains input_tokens, estimated_output_tokens, per-model costs array (model, provider, input/output cost in USD), recommended_model, and recommendation_reason.

Pricing covers models across Anthropic, OpenAI, Google, and Perplexity. Updated regularly. See Models for supported models.

compress_context Free All Plans

Compresses context (code, docs) by removing irrelevant sections while respecting protected zones (fenced code, tables, lists, JSON, YAML). Multi-stage pipeline intelligently removes boilerplate while preserving meaningful content.

Parameters
context string required The context text to compress
intent string required What the task is about (used to determine relevance)
Returns

compressed_context, removed_sections, original_tokens, compressed_tokens, tokens_saved, savings_percent, and mode.

prune_tools Free All Plans

Scores and ranks MCP tools by relevance to a task intent. In prune mode, marks the lowest-scoring tools for removal to save context tokens. Respects mention protection and the always-relevant tool set (search, read, write, edit, bash).

Parameters
intent string required Task description or user intent
tools ToolDefinition[] required Array of { name, description } (max 500)
mode "rank" | "prune" rank: score all. prune: also mark bottom-M for removal (default: "rank")
prune_count number Number of lowest-scoring tools to prune (default: 5, prune mode only)
Returns

Ranked tool list with relevance_score (0–100), signals, and tokens_saved_estimate per tool. Plus pruned_count, pruned_tools, and total tokens_saved_estimate.

⚙️ Configuration 3 tools
configure_optimizer Free All Plans

Configures optimizer behavior. Supports mode, threshold, strictness, default target, ephemeral mode, session limits, and Enterprise features (policy mode, audit log, config lock with passphrase protection).

Parameters
mode "manual" | "always_on" Optimization mode
threshold number (0-100) Quality threshold
strictness "relaxed" | "standard" | "strict" Strictness level (maps to threshold: relaxed=40, standard=60, strict=75)
auto_compile boolean Auto-compile prompts
default_target OutputTarget Default output target
ephemeral_mode boolean Ephemeral mode: sessions in-memory only
max_sessions number (1-10000) Max session count
max_session_size_kb number (1-1024) Max session size in KB
max_session_dir_mb number (1-100) Max session directory size in MB
session_retention_days number (1-365) Auto-purge sessions older than N days Enterprise
policy_mode "advisory" | "enforce" Policy enforcement mode Enterprise
audit_log boolean Enable append-only JSONL audit trail Enterprise
lock boolean Lock config (requires lock_secret) Enterprise
unlock boolean Unlock config (requires same lock_secret) Enterprise
lock_secret string (4-128) Passphrase for lock/unlock (stored as SHA-256 hash only)
Returns

The full OptimizerConfig object and list of applied_changes.

get_usage Free All Plans

Returns current usage count, plan limits, remaining quota, tier information, and first/last used timestamps.

Parameters
No parameters required.
Returns

total_optimizations, limits (TierLimits), remaining (lifetime + monthly), tier, first_used_at, last_used_at.

prompt_stats Free All Plans

Returns aggregated optimization statistics: total optimized, total approved, average quality score, top task types, blocking question frequency, and estimated cost savings in USD.

Parameters
period "7d" | "30d" | "lifetime" Stats period (default: "lifetime")
Returns

total_optimized, total_approved, average_score_before, task_type_counts, blocking_question_counts, estimated_cost_savings_usd.

🔑 License 2 tools
set_license Free All Plans

Activates a Pro, Power, or Enterprise license key. Uses Ed25519 asymmetric signature verification (public key only, offline, zero dependencies). The license payload contains tier, issued_at, expires_at, and license_id — no PII.

Parameters
license_key string required License key string (starts with pcp_)
Returns

status ("activated"), tier, expires_at, license_id, and limits for the activated tier.

license_status Free All Plans

Checks current license status, tier, and expiry. Re-validates expiry on every read. Returns purchase URLs if no license is active.

Parameters
No parameters required.
Returns

LicenseData (or null with purchase links if inactive): tier, issued_at, expires_at, license_id, valid, validation_error (if expired).

📂 Sessions 4 tools
list_sessions Free Enterprise

Lists all optimization sessions with metadata (no raw prompts). Returns newest-first, with task type, quality score, state, and prompt hash.

Parameters
createdAfter number Only sessions after this Unix timestamp
createdBefore number Only sessions before this Unix timestamp
limit number (1-100) Max sessions to return (default: 100)
Returns

SessionListResponse — Array of SessionRecord (session_id, state, task_type, quality_before, prompt_hash, target) plus total_sessions and storage_path.

export_session Free Enterprise

Exports full session details including raw prompt, compiled prompt, and reproducibility metadata. Auto-calculates rule_set_hash, rule_set_version, risk_score, and custom_rules_applied.

Parameters
session_id string required Session ID to export
Returns

SessionExport — Contains raw_prompt, compiled_prompt, quality_before/after, rule_set_hash, rule_set_version, and metadata (target, task_type, complexity, risk_score, custom_rules_applied, engine_version, policy_mode, policy_hash).

delete_session Free Enterprise

Deletes a single optimization session by ID. Audit-logged in Enterprise tier.

Parameters
session_id string required Session ID to delete
Returns

deleted: true and session_id, or a not_found error.

purge_sessions Free Enterprise

Bulk-purges optimization sessions by age policy or deletes all. Safe-by-default: requires explicit parameters. Supports dry_run preview, keep_last protection, and config-based session_retention_days fallback.

Parameters
older_than_days number (1-365) Delete sessions older than N days
keep_last number (0-1000) Always protect the N newest sessions
purge_all boolean Explicit opt-in to delete ALL sessions
dry_run boolean Preview what would be deleted (default: false)
Returns

PurgeResultdeleted_count, retained_count, scanned_count, deleted_session_ids (capped at 100), dry_run, cutoff_date, effective_older_than_days.

Enterprise Features

Enterprise tier unlocks governance features designed for regulated environments. All features are local-only, deterministic, and require no external services.

Policy Enforcement Enterprise

Switch from advisory mode (issues are reported but never block) to enforce mode, where BLOCKING rules gate every prompt operation.

Setup

configure_optimizer({ policy_mode: "enforce" })

Advisory vs Enforce

When violations are found

In enforce mode, approve_prompt returns an error with policy_violations listing each triggered BLOCKING rule (rule_id, description, severity, risk_dimension). The user must resolve the issues via refine_prompt or adjust the prompt before re-attempting approval.

Audit Logging Enterprise

Append-only, tamper-evident JSONL audit trail. Every significant action generates an entry with SHA-256 hash chaining.

Enable

configure_optimizer({ audit_log: true })

JSONL format

Each line is a JSON object with these fields:

{ "timestamp": "2026-03-01T10:30:00.000Z", "event": "optimize", // optimize | approve | delete | purge | configure | license_activate "session_id": "abc-123", "request_id": "req_xyz", "task_type": "code_change", "risk_score": 42, "routing_tier": "mid", "policy_mode": "enforce", "outcome": "success", // success | blocked | error "integrity_hash": "a3f2..." // SHA-256: hash(prev_hash + JSON(entry)) }

Verify integrity

If any line in the JSONL file is deleted or modified, the hash chain breaks. To verify: iterate the log, recompute SHA-256(prev_hash + line) for each entry, and compare against the stored integrity_hash. A mismatch indicates tampering.

Privacy invariant: The audit log never stores raw_prompt, compiled_prompt, or prompt_preview content. Only metadata (event type, session ID, risk score, outcome) is recorded.

Config Lock Enterprise

Lock your governance configuration with a passphrase. Once locked, no one can change policy, strictness, or audit settings without the correct secret.

Lock

configure_optimizer({ lock: true, lock_secret: "your-admin-passphrase" })

Unlock

configure_optimizer({ unlock: true, lock_secret: "your-admin-passphrase" })

The passphrase is stored as a SHA-256 hash only — never in plaintext. Every lock/unlock attempt (successful or blocked) is audit-logged if the audit trail is enabled.

Custom Rules Enterprise

Define organization-specific prompt governance rules that run alongside the built-in rule engine.

JSON Schema

Place your rules in ~/.prompt-control-plane/custom-rules.json:

{ "schema_version": 1, "created_at": 1709280000, "rules": [ { "id": "require_error_handling", "description": "Code prompts must mention error handling", "pattern": "error|exception|try|catch|handle", "negative_pattern": "ignore errors", "applies_to": "code", "severity": "BLOCKING", "risk_dimension": "underspec", "risk_weight": 15 } ] }

Rule fields

FieldTypeConstraints
idstringsnake_case, max 64 chars, regex: ^[a-z][a-z0-9_]{0,63}$
descriptionstringMax 200 chars
patternstringJavaScript regex, max 500 chars
negative_patternstringOptional exclusion regex, max 500 chars
applies_tostring"code" | "prose" | "all"
severitystring"BLOCKING" | "NON-BLOCKING"
risk_dimensionstring"hallucination" | "constraint" | "underspec" | "scope"
risk_weightnumber1–25

Hard cap: 25 rules per configuration. Invalid regex patterns are skipped with a warning (skip-on-error pattern).

Validate custom rules

prompt-lint --validate-custom-rules

Session Retention Enterprise

Configure automatic session cleanup by age policy.

Set retention

configure_optimizer({ session_retention_days: 90 })

Manual purge with dry_run

// Preview what would be deleted purge_sessions({ older_than_days: 30, keep_last: 10, dry_run: true }) // Execute the purge purge_sessions({ older_than_days: 30, keep_last: 10, dry_run: false })

Purge only touches session files. Config, audit log, and license data are never deleted.

CLI Linter (prompt-lint)

A standalone CLI for linting prompt files. Reuses the same scoring, rules, and analysis engine. No MCP dependency — works in any CI pipeline or terminal.

All Flags

FlagDescription
--file <glob>Glob pattern for prompt files to lint (e.g., "prompts/**/*.txt")
--jsonOutput results as JSON (for machine consumption)
--strictUse strict threshold (75)
--relaxedUse relaxed threshold (40)
--threshold NSet a custom threshold (0–100). Overrides --strict/--relaxed.
--validate-custom-rulesValidate the custom rules JSON file and exit

Exit Codes

CodeMeaning
0All files pass the quality threshold
1One or more files fail the threshold
2Error (invalid args, file not found, etc.)

CI Usage Example

# In your CI pipeline npx claude-prompt-optimizer-mcp prompt-lint --file "prompts/**/*.md" --strict --json

Reads from stdin if no --file is provided:

echo "Write a blog post" | npx claude-prompt-optimizer-mcp prompt-lint --threshold 70

GitHub Action

Run prompt linting as a GitHub Actions check. Fails the workflow if any prompt file scores below the threshold.

Workflow Example

# .github/workflows/prompt-lint.yml name: Prompt Lint on: [push, pull_request] jobs: lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Lint prompts uses: rishiatlan/Prompt-Optimizer-MCP@v4 with: files: "prompts/**/*.md" strictness: strict # or: standard, relaxed # threshold: 80 # overrides strictness if set # version: "4.0.0" # pin to specific npm version

Action Inputs

InputRequiredDefaultDescription
filesYesGlob pattern for prompt files
thresholdNoMinimum score (0–100). Overrides strictness.
strictnessNostandardPreset: standard (60), strict (75), relaxed (40)
versionNotag refnpm version to install

Programmatic API

Import the optimization pipeline directly into your Node.js application. Pure, synchronous, deterministic. No I/O, no side effects, no MCP server required.

Quick Start

import { optimize } from 'claude-prompt-optimizer-mcp'; const result = optimize('Write a blog post about AI governance'); console.log(result.quality.total); // 0-100 quality score console.log(result.compiled); // Structured prompt (XML/system-user/markdown) console.log(result.cost.costs); // Per-model cost breakdown

optimize() Signature

function optimize( prompt: string, context?: string, target: OutputTarget = 'claude' ): OptimizeResult

OptimizeResult Shape

interface OptimizeResult { intent: IntentSpec; // Parsed intent from raw prompt quality: QualityScore; // Quality score (0-100, multi-dimensional) compiled: string; // Optimized prompt for target LLM changes: string[]; // Structural changes applied checklist: CompilationChecklist; // 9-item structural coverage cost: CostEstimate; // Token + cost estimates }

Available Exports

The barrel export at claude-prompt-optimizer-mcp provides access to all core functions:

CategoryWhat’s Available
Convenienceoptimize() — one-call pipeline
AnalysisIntent parsing, task detection, complexity classification
ScoringQuality scoring, structural checklist generation
CompilationMulti-target prompt compilation, context compression
CostToken estimation, cost calculation, model routing
RiskRule evaluation, risk scoring, risk level derivation
ProfilesOptimization profile resolution and suggestions
EnterprisePolicy evaluation, audit logging, session management
Custom RulesCustomRulesManager, customRules
TypesAll TypeScript interfaces and types (see types.ts)

Dual Entry Points

ImportEffect
import { optimize } from 'claude-prompt-optimizer-mcp'Pure API — no side effects, no server
import 'claude-prompt-optimizer-mcp/server'Starts MCP stdio server (side-effect import)

Environment Variables

VariableDefaultPurpose
PROMPT_CONTROL_PLANE_PROunsetSet to true to enable pro tier via environment variable. Tier priority: license key (cryptographically verified) > env var > default free.
PROMPT_CONTROL_PLANE_LOG_LEVELinfoLog verbosity: debug, info, warn, error
PROMPT_CONTROL_PLANE_LOG_PROMPTSunset (false)Set to true to enable raw prompt logging. Never enable in shared environments.

Security: Prompt logging (PROMPT_CONTROL_PLANE_LOG_PROMPTS) writes raw prompt content to stderr. Never enable this in production, CI, or any shared environment where logs are aggregated.

Storage

All data is stored locally in ~/.prompt-control-plane/. No cloud services, no telemetry, no data leaves your machine.

Directory Layout

~/.prompt-control-plane/ config.json # OptimizerConfig (mode, threshold, strictness, etc.) usage.json # Usage counters (total, period, tier) stats.json # Aggregated statistics license.json # License data (chmod 600 on POSIX) audit.jsonl # Append-only audit trail (Enterprise) custom-rules.json # Custom governance rules (Enterprise) sessions/ {session-id}.json # Individual session files

Storage Health

Every metered tool response includes a storage_health field: "ok" or "degraded". In degraded mode, the pipeline continues with fail-open semantics (no data loss, but usage may not persist to disk). This design ensures zero downtime even if the filesystem is temporarily unavailable.

Session Limits

SettingDefaultDescription
max_sessions200Maximum number of session files
max_session_size_kb50Maximum size per session file
max_session_dir_mb20Absolute cap on session directory size

When limits are exceeded, the oldest sessions are automatically cleaned up.

Phase A / Phase B

The current release (Phase A) uses local file-based storage. All tool handlers use an async StorageInterface that abstracts the backend. Phase B will swap to Cloudflare Worker + Supabase without changing any tool handler code, test contracts, or interfaces.