Skip to main content

User prompt transformed hook

The userPromptTransformed hook runs after the runtime adds generated context to a submitted prompt, but before the resulting content is persisted to session history or sent to the model.

In this article

Use it when you need to inspect or replace the exact model-facing prompt. The prompt input contains the user prompt after any userPromptSubmitted hooks have run, while transformedPrompt also contains runtime-generated context such as <current_datetime>.

Input and output

Input fieldTypeDescription
sessionIdstringRuntime session ID
timestampdate/timeTime the hook was invoked
cwd / workingDirectorystringCurrent working directory
promptstringPrompt after userPromptSubmitted hooks
transformedPromptstringModel-facing prompt after runtime transformations

Return no value to leave the transformed prompt unchanged. Return modifiedTransformedPrompt to replace the content that is stored in session history and sent to the model.

Examples

Code languages navigation

TypeScript
const session = await client.createSession({
  hooks: {
    onUserPromptTransformed: async (input) => ({
      modifiedTransformedPrompt: redact(input.transformedPrompt),
    }),
  },
});

The replacement is persisted as the user message content, so resumed sessions replay the modified content unchanged.