The Complete Production SOP: How to Deploy and Run NestJS Interceptors Request Transformation & Logging in Autonomous AI Agents
Step-by-step SOP to install and run NestJS Interceptors Request Transformation & Logging in Codex, Claude Code, and Cursor. Includes verified prompts and fixes.
Technical Overview & Architectural Context
When autonomous coding agents generate NestJS interceptors without deterministic guardrails, they frequently introduce critical anti-patterns. Common agent regressions include breaking RxJS streams by omitting `return next.handle()`, blocking the event loop with synchronous latency measurements, mutating immutable response payloads, or attempting to write global interceptors using standard Express middleware conventions. Additionally, agents often confuse NestJS ExecutionContext with standard Express Request/Response objects, resulting in type errors during WebSocket or microservice transport transitions. `nestjs-interceptors-logging-transform` resolves these issues by mounting explicit procedural standards into the autonomous agent's runtime. The skill forces the agent to implement standard `NestInterceptor` interfaces, apply functional stream transformations using RxJS operators (`map`, `tap`, `catchError`), and decouple logging instrumentation from business logic. By strictly scoping file writes to the local project workspace and enforcing execution timing metrics via non-mutating RxJS streams, agents reliably generate clean, typed, and composable NestJS middleware.
Prerequisites & Environment Requirements
Verified Search Intents & Long-Tail Queries Solved
This operational tutorial is engineered to provide deterministic solutions for these developer search queries:
Step-by-Step Execution Playbook
Local Environment Setup & SKILL.md Mounting
Create the local skill manifest directory and inject verified procedural rules.
Agent runtimes such as Claude Code and Codex parse procedural behaviors from workspace-mounted manifests. By creating a standardized `.agents/skills` directory in your workspace and mounting the `nestjs-interceptors-logging-transform` definition, the AI agent dynamically registers frontmatter triggers (`write nestjs interceptor`, `transform response nestjs interceptor`, `log execution time interceptor`) and enforces strict NestInterceptor interface requirements.
mkdir -p .agents/skills/nestjs-interceptors-logging-transform && cat <<'EOF' > .agents/skills/nestjs-interceptors-logging-transform/SKILL.md
---
name: "nestjs-interceptors-logging-transform"
description: "Intercept execution flow to log execution timing, transform responses, and handle caching."
metadata:
author: "NestJS"
version: "1.0.0"
runtime_compatibility:
- "codex"
- "claude-code"
- "cursor"
- "windsurf"
triggers:
- "write nestjs interceptor"
- "transform response nestjs interceptor"
- "log execution time interceptor"
permissions:
fs_read: true
fs_write: "workspace"
shell_exec: false
net_access: false
---
# NestJS Interceptors Request Transformation & Logging
Authors NestJS Interceptors implementing NestInterceptor: transforming response data with RxJS map, measuring endpoint latency with tap, overriding exceptions with catchError, and implementing Redis caching interceptors.
## Execution SOP & Rules
1. Implement intercept(context: ExecutionContext, next: CallHandler): Observable<any> interface.
2. Transform response streams using RxJS pipe(): return next.handle().pipe(map(data => ({ data })))
3. Record execution duration: const now = Date.now(); return next.handle().pipe(tap(() => Logger.log(`${now}ms`))).
4. Apply interceptor via @UseInterceptors() or globally via APP_INTERCEPTOR provider.
EOFimport {
CallHandler,
ExecutionContext,
Injectable,
NestInterceptor,
} from '@nestjs/common';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
export interface Response<T> {
data: T;
statusCode: number;
timestamp: string;
}
@Injectable()
export class TransformInterceptor<T> implements NestInterceptor<T, Response<T>> {
intercept(context: ExecutionContext, next: CallHandler): Observable<Response<T>> {
const ctx = context.switchToHttp();
const response = ctx.getResponse();
const statusCode = response.statusCode;
return next.handle().pipe(
map((data) => ({
data,
statusCode,
timestamp: new Date().toISOString(),
})),
);
}
}Place the SKILL.md inside `.claude/skills` or `.agents/skills` at the repository root to ensure all submodules inherit the interceptor transformation rules without repeatedly injecting instructions into user prompts.
Ensure `shell_exec` is set to false in the frontmatter if running in restricted CI/CD pipelines, forcing the agent to rely strictly on deterministic workspace file editing rather than running ad-hoc installation scripts.
Environment Secrets & Dependency Validation
Inject required environment variables safely without leaking secrets into conversation history.
Verify that your runtime environment has the required RxJS operators and NestJS core packages installed. For interceptors handling structured log shipping or caching, ensure destination URLs or Redis credentials are configuration-driven via `ConfigService` rather than hardcoded.
pnpm add @nestjs/common @nestjs/core rxjs && test -f .env || echo "LOG_LEVEL=debug" >> .envNever instruct the agent to print runtime environment tokens. Instead, prompt the agent to reference `process.env.LOG_LEVEL` or inject `ConfigService` directly into the interceptor constructor.
Do not commit `.env` containing production logging endpoints or telemetry keys to git tracking; add `.env` and `.env.local` to `.gitignore`.
Intent Matching & Trigger Invocation
Verify deterministic activation using tested natural language prompts.
When invoking Codex, Claude Code, or Cursor, use triggering terms matching the skill's declared triggers: 'write nestjs interceptor', 'transform response nestjs interceptor', or 'log execution time interceptor'. This instructs the agent to read the SOP rules and generate standard RxJS piping instead of procedural Express middleware.
Phrase prompts around explicit data envelopes (e.g., 'transform response nestjs interceptor wrapping payloads in { data, timestamp }') to minimize conversational clarification cycles.
Agents without this skill often use standard `console.time()` inside the interceptor function body rather than RxJS `tap` inside `next.handle().pipe()`, measuring controller initialization time rather than actual asynchronous request resolution.
Verification, Linting & Output Quality Gate
Execute automated self-healing checks before accepting agent deliverables.
Run TypeScript compilation and unit tests on the generated interceptor. The skill enforces that the agent validates its own changes against existing controller specs to ensure response shapes match expected contracts.
npx tsc --noEmit && pnpm test -- test/common/interceptors/transform.interceptor.spec.tsInspect the git diff (`git diff src/common/interceptors/`) to verify that the agent did not accidentally modify root module providers unnecessarily when registering global interceptors.
Registering global interceptors via `app.useGlobalInterceptors()` in `main.ts` breaks dependency injection for interceptors requiring dependencies. Verify the agent uses `APP_INTERCEPTOR` provider tokens in `app.module.ts` when dependencies are needed.
Real-World Scenario: Unified API Response Packaging and Latency Observability
“write nestjs interceptor to log execution time interceptor and transform response nestjs interceptor wrapping output into { data, executionTimeMs, timestamp }. Apply it globally across the application with DI support.”
Runtime Troubleshooting & Failure Modes
Root Cause: The agent attempted to invoke Express middleware conventions (req, res, next) instead of NestJS CallHandler pattern `next.handle()`.
Ensure the interceptor method signature strictly follows: `intercept(context: ExecutionContext, next: CallHandler): Observable<any> { return next.handle().pipe(...); }`Root Cause: The agent instantiated the interceptor globally in `main.ts` using `app.useGlobalInterceptors(new LoggingInterceptor(dependency))` without DI resolution.
Register the interceptor as a multi-provider in `app.module.ts`: `{ provide: APP_INTERCEPTOR, useClass: LoggingInterceptor }`Frequently Asked Questions (NestJS Interceptors Request Transformation & Logging SOP)
Q:Can I use NestJS Interceptors Request Transformation & Logging across Codex, Claude Code, and Cursor simultaneously?
Yes. The skill conforms to the universal SKILL.md specification supported across all modern agent runtimes. Simply commit the manifest into `.agents/skills/` or `.claude/skills/` and any compatible IDE assistant will execute against the same SOP.
Q:How does NestJS Interceptors Request Transformation & Logging prevent context window overflow during long agent sessions?
By establishing concise procedural boundaries and deterministic validation gates rather than polluting system prompts with redundant rules. The agent receives exact RxJS piping instructions and validation criteria only when interceptor-related triggers match.
Q:Does this skill require escalated root or container permissions?
No. It is audited with a security score of 98/100 and runs safely within workspace-scoped sandboxes with `shell_exec: false` and `net_access: false`.
Ready to equip your autonomous agent with NestJS Interceptors Request Transformation & Logging?
Copy the complete audited SKILL.md specification or download the 1-click zip bundle directly from our verified registry.