Create a Legacy Module Reference Sheet for Coding Agents

Compresses messy legacy source files into a dense markdown cheat sheet capturing public methods, hidden state changes, and side effects for coding agent contexts.

Agent prompt for Claude Code and Cursor

Prompt

Prompt
Act as a software architect optimizing context efficiency for AI coding tools like Claude Code, Cursor, and Codex. Your job is to convert raw legacy source code into a dense, token-efficient reference document.

I will paste a legacy file or module after this prompt.

Follow these rules:
1. Extract only callable entry points, public signatures, and critical data models.
2. Explicitly flag hidden global mutations, unhandled exceptions, and background side effects (such as direct database writes or cache invalidations).
3. Keep the total output under 400 words without narrative padding or general descriptions.
4. Document input constraints and implicit assumptions that are not captured in the type signatures.

Output format:### Module Overview
- Primary responsibility: one short line
- Shared state & dependencies: list of tables, caches, or singletons touched

### Public Interfaces
- signature -> return type: exact behavior summary

### Implicit State Mutations & Side Effects
- Method name: specific mutation, uncommitted transaction, or emitted event

### Dangerous Edge Cases
- Concrete scenarios where this code fails silently or throws unexpected errors

Example output

Example for: a legacy Python session-handling and billing calculation script (session_manager.py).

Module Overview
  • Primary responsibility: Validates customer session tokens and aggregates unbilled feature usage units.
  • Shared state & dependencies: Direct read/write to global REDIS_CLIENT, writes to raw_billing_events table, reads environment flag FEATURE_BILLING_STRICT.
Public Interfaces
  • validate_and_charge(user_id: int, units: int) -> bool: Checks session key in Redis, deducts balance, and returns True on success.
  • drain_orphan_sessions(dry_run: bool = False) -> int: Scans keys matching sess:* older than 86400 seconds; returns deleted count.
  • get_tier_multiplier(org_id: str) -> float: Looks up custom billing overrides in memory fallback; returns 1.0 if not found.
Implicit State Mutations & Side Effects
  • validate_and_charge: Directly increments Redis key user:rate:hourly without an expiration check if key was missing. Appends uncommitted rows to thread-local DB transaction.
  • drain_orphan_sessions: Emits synchronous UDP metrics packets to localhost on port 8125, blocking thread on network stalls.
Dangerous Edge Cases
  • Passing negative units to validate_and_charge credits the user account; no upper or lower sanity checks exist.
  • Fails silently and returns True if REDIS_CLIENT raises a ConnectionError, resulting in unmetered usage during database failovers.
Written by AI from this prompt. Your results will vary.

Tips and common edits

Why this works

  • Focuses strictly on side effects and mutations that cause AI agents to break existing behavior during refactors.
  • Eliminates boilerplate syntax and explanations to preserve valuable context window tokens for the agent.
  • Highlights invisible runtime assumptions that standard type signatures fail to capture.

Paste your messy legacy file directly after this prompt in Claude Code, Cursor, Codex, or GitHub Copilot to create a reusable context card for future sessions.

Common edits

  • Add a section for critical mock fixtures if using the output primarily to generate unit tests.
  • Change the target output format to YAML if your agent system uses structured YAML system prompts.

Reuse it: Use in a workflowAdapt in the builder

Prompt details

By
Prompts-GPT editors
Published
How prompts are written and checked

Did this prompt work?

AI Coding AgentsClaude Code

Convert User Stories into Strict Acceptance Test Assertions

This prompt transforms vague business requirements into precise Given-When-Then test assertions with exact HTTP status codes and JSON payload structures for AI coding agents.

AI Coding AgentsClaude Code

Create Automated Verification Loops for Long-Running Coding Agents

Generate a deterministic shell pipeline that combines linting, isolated unit testing, and diff-budget monitoring to validate AI agent code changes.

AI Coding AgentsClaude Code

Design a Sandbox Security Policy for Autonomous Coding Agents

Generate a rigorous security policy for autonomous agents to define allowed shell commands, file access boundaries, and network restrictions.

AI Coding AgentsClaude Code

Generate Reproducible Bug Fix Specs for Coding Agents

Get a standalone reproduction test script and a precise technical plan to fix a bug, ensuring your AI agent stays focused and avoids unnecessary file changes.

AI Coding AgentsClaude Code

Create a Verification Loop Script for AI Coding Agents

Generate a lightweight bash verification pipeline that validates linters, scoped test suites, and git diff budgets before an agent declares a task complete.