# How OmniRoute Handles Claude-Style System Directives: Detection, Normalization, and Safety Injection

> OmniRoute processes Claude-style system directives with a three-stage pipeline detecting, normalizing, and injecting safety prompts to ensure API contract integrity across diverse LLM backends.

- Repository: [Diego Rodrigues de Sa e Souza/OmniRoute](https://github.com/diegosouzapw/OmniRoute)
- Tags: deep-dive
- Published: 2026-08-23

---

**OmniRoute processes Claude-style system directives through a three-stage pipeline that detects the "system" role, normalizes or bypasses translation for compatible providers, and injects safety prompts to maintain API contract integrity across heterogeneous LLM backends.**

OmniRoute is an open-source request translation layer that bridges Claude-formatted prompts with disparate LLM providers. When handling Claude-style system directives, the codebase implements a sophisticated normalization strategy that preserves directive intent while adapting payload structure to match target API expectations in [`open-sse/translator/helpers/claudeHelper.ts`](https://github.com/diegosouzapw/OmniRoute/blob/main/open-sse/translator/helpers/claudeHelper.ts).

## Detection and Identification of System Prompts

When a request arrives at OmniRoute, the translator scans the incoming message list for any item whose `role` is `"system"`. This detection logic resides in the Claude-specific helper `prepareClaudeRequest`, located in [`open-sse/translator/helpers/claudeHelper.ts`](https://github.com/diegosouzapw/OmniRoute/blob/main/open-sse/translator/helpers/claudeHelper.ts).

### The prepareClaudeRequest Helper

The `prepareClaudeRequest` function accepts the `incomingBody` and `targetProvider` parameters to determine whether the system directive requires transformation. It identifies the system message block and prepares it for downstream processing, either routing it through normalization or marking it for bypass.

## Normalization for Heterogeneous Providers

For providers that do not natively understand Claude's schema—such as OpenAI, Gemini, or DeepSeek—the helper normalizes the system block into the target's `systemInstruction` or equivalent field. During this process, the translator strips any orphaned tool-use blocks that might invalidate the payload for the downstream API.

## The Claude-to-Claude Passthrough Bypass

If the request originates from a Claude client and the target provider is a true Claude service (Anthropic-compatible), OmniRoute skips conversion entirely. This bypass is exercised in the "Claude → Claude" tests and guarded by the `interceptSearchOverride` flag in [`tests/unit/web-search-fallback-format.test.ts`](https://github.com/diegosouzapw/OmniRoute/blob/main/tests/unit/web-search-fallback-format.test.ts). The request body forwards untouched to preserve exact schema compatibility.

## Safety Prompt Injection and Antigravity Logic

For OpenAI-style providers, OmniRoute appends an internal "antigravity" system prompt to the user-provided system content. This internal directive handles safety and caching requirements. The combined text is then placed into the provider-specific `systemInstruction` field in the outbound request, as implemented in [`open-sse/translator/request/openai-to-gemini.ts`](https://github.com/diegosouzapw/OmniRoute/blob/main/open-sse/translator/request/openai-to-gemini.ts) at lines 721-728.

## Round-Trip Response Translation

When responses return from a Claude-compatible backend, the translator re-maps any Claude-style tool results back into the OpenAI/Responses format. This round-trip logic utilizes `openaiToClaudeResponse` and related helpers validated in [`tests/unit/translator-openai-to-claude.test.ts`](https://github.com/diegosouzapw/OmniRoute/blob/main/tests/unit/translator-openai-to-claude.test.ts).

## Implementation Examples

The following TypeScript examples demonstrate the core workflows for handling Claude-style system directives:

```typescript
// 1️⃣ Detect a Claude system prompt and prepare the request for a non-Claude target
import { prepareClaudeRequest } from '@/open-sse/translator/helpers/claudeHelper';
const outbound = prepareClaudeRequest(incomingBody, targetProvider);

```

```typescript
// 2️⃣ Forward a Claude-to-Claude request unchanged (bypass)
if (sourceProvider === 'claude' && targetProvider === 'claude') {
  // The request body is sent as-is – no translation needed
  await executor.execute(body);
}

```

```typescript
// 3️⃣ Append the internal antigravity system prompt when targeting OpenAI-style APIs
import { injectAntigravitySystem } from '@/open-sse/translator/helpers/claudeHelper';
const bodyWithSafety = injectAntigravitySystem(outbound);
await executor.execute(bodyWithSafety);

```

## Summary

- OmniRoute detects Claude-style system directives via `prepareClaudeRequest` in [`open-sse/translator/helpers/claudeHelper.ts`](https://github.com/diegosouzapw/OmniRoute/blob/main/open-sse/translator/helpers/claudeHelper.ts)
- Non-Claude targets receive normalized system blocks mapped to `systemInstruction` fields, with orphaned tool-use blocks removed
- Claude-to-Claude requests bypass translation entirely using the `interceptSearchOverride` guard in [`web-search-fallback-format.test.ts`](https://github.com/diegosouzapw/OmniRoute/blob/main/web-search-fallback-format.test.ts)
- OpenAI-style targets receive merged content including the antigravity safety prompt from [`openai-to-gemini.ts`](https://github.com/diegosouzapw/OmniRoute/blob/main/openai-to-gemini.ts) lines 721-728
- Round-trip translation preserves tool results via `openaiToClaudeResponse` and related helpers

## Frequently Asked Questions

### What happens to Claude system directives when targeting OpenAI-compatible APIs?

OmniRoute normalizes the `role: "system"` block into the target provider's `systemInstruction` field. It also appends an internal antigravity safety prompt to ensure compliance and caching efficiency, merging both into the final payload sent to the downstream API.

### Does OmniRoute modify system prompts for Claude-to-Claude requests?

No. When both the source and target providers are Claude-compatible, OmniRoute exercises a passthrough bypass that forwards the request body completely untouched. This behavior is validated in [`tests/unit/web-search-fallback-format.test.ts`](https://github.com/diegosouzapw/OmniRoute/blob/main/tests/unit/web-search-fallback-format.test.ts) and preserves exact schema fidelity.

### What is the antigravity system prompt in OmniRoute?

The antigravity system prompt is an internal safety and caching directive injected into system content when translating to OpenAI-style providers. According to the source code in [`open-sse/translator/request/openai-to-gemini.ts`](https://github.com/diegosouzapw/OmniRoute/blob/main/open-sse/translator/request/openai-to-gemini.ts) at lines 721-728, this prompt is appended to user-provided system content before placement in the `systemInstruction` field.

### How does OmniRoute handle tool-use blocks in system directives?

During normalization for non-Claude providers, the translator strips orphaned tool-use blocks from the system directive. This sanitization ensures the payload remains valid for downstream APIs that do not support Claude's native tool schema, preventing schema validation errors.