How OmniRoute Handles Claude-Style System Directives: Detection, Normalization, and Safety Injection
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.
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.
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. 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 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.
Implementation Examples
The following TypeScript examples demonstrate the core workflows for handling Claude-style system directives:
// 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);
// 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);
}
// 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
prepareClaudeRequestinopen-sse/translator/helpers/claudeHelper.ts - Non-Claude targets receive normalized system blocks mapped to
systemInstructionfields, with orphaned tool-use blocks removed - Claude-to-Claude requests bypass translation entirely using the
interceptSearchOverrideguard inweb-search-fallback-format.test.ts - OpenAI-style targets receive merged content including the antigravity safety prompt from
openai-to-gemini.tslines 721-728 - Round-trip translation preserves tool results via
openaiToClaudeResponseand 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 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 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.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →