> ## Documentation Index
> Fetch the complete documentation index at: https://kiro.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Prompt optimizer

> Cmd+Shift+Enter to rewrite a vague prompt into a scoped, actionable one before you send it. Two-to-five second overhead. LLM-driven with strict rules.

The prompt optimizer rewrites a vague or hedged prompt into a specific, scoped, actionable one — before you send it to the agent. Trigger it with **Cmd+Shift+Enter** (macOS) / **Ctrl+Shift+Enter** (Linux), or click the **✨** sparkle button in the input toolbar.

## The flow

1. Type a prompt in the dashboard textarea
2. Press **Cmd+Shift+Enter** (or click ✨)
3. Dark overlay appears: "✨ Optimizing prompt…" — textarea becomes read-only and dimmed
4. The rewritten text replaces the textarea content — review before sending
5. Press **Enter** to send (no auto-send)

On error or unchanged text, the original is restored silently. Typical overhead: **2–5 seconds**.

## When to use it

Optimization helps most when the original is:

- **Vague** — "fix that thing" → gets scope, files, and constraints added
- **Under-specified** — "add auth" → gets required components and edge cases
- **Missing structure** — a wall of text → gets numbered steps
- **Uncertain** — hedged with "maybe" or "if you could" → replaced with direct verbs

Optimization is unnecessary when the prompt is already:

- Specific and scoped
- Short and unambiguous ("What's 2+2?")
- Referencing a specific file the agent should already understand

The optimizer knows this — it returns the original unchanged when there's nothing worth adding.

## The rules the optimizer follows

The optimizer's system prompt encodes six rules (earlier wins on conflict):

1. **Never change your intent** — no added requirements, no invented values
2. **Return unchanged** if the prompt is already specific, scoped, and actionable
3. **When rewriting, add** what you skipped: scope, constraints, structure, uncertainty handling
4. **Replace hedging** ("maybe", "if you could") with direct verbs
5. **Add "preserve existing behavior"** when the change is to existing work
6. **Never exceed** `min(3 × original length, 250 words)`

## Example

Before:

```
fix the zoom bug in the dashboard
```

After:

```
Fix the zoom bug in the dashboard chat input.

Scope:
- `website/src/hooks/useZoom.ts` — cleanup CSS custom properties on unmount
- `website/src/components/ChatInput.tsx` — cache the `effectiveVh()` result per render

Constraints:
- Preserve existing zoom-in and zoom-out gestures
- Do not change the public API of `useZoom`
- Run `npm run build` and `npm run test` before completing

If you find related issues while fixing this, list them but do not fix them in this change.
```

Same intent, but the agent now knows the files, the constraints, and where to stop.

## What context the optimizer sees

The optimizer receives:

- Your prompt in `<original_prompt>` tags
- The last ~10 conversation messages (truncated to 2,000 chars)

Context makes the optimizer smarter when you're mid-conversation: it picks up file names, error messages, and prior scope from the recent history. In a fresh session, it works from the prompt alone.

## Under the hood

The optimizer runs on a **dedicated `_optimizer` session** with the `kirocrew-lite` agent — a small, tools-disabled agent tuned for single-shot rewrites.

- Independent from the shared `_bg` session (which handles title generation and folder categorization)
- No tool calls — any tool permission request during optimization is rejected outright
- 30-second `asyncio.wait_for` wraps the entire operation (session claim + stream + release)
- LLM output has "UNCHANGED" detection built in — if the LLM decides the prompt is fine, the original is returned

On timeout or error, the original text is silently restored. The optimizer never fails loudly.

## Security

Output is passed through `redact_credentials()` and `redact_exfiltration_urls()` before it reaches your textarea. If the optimizer ever surfaces a credential pattern from context, it's redacted.
