Retext
Claude CodeIDESecurity Review

Claude Code Security Review Prompt Template

You get the real vulnerabilities in the code ranked by severity, each with how it could be exploited and a specific fix. This version is set up for Claude Code: name the files, commands and tests involved. Claude Code can read files and run commands in your project, asking permission as it goes. Below you'll find the prompt, how to run it in Claude Code, a worked example and answers to common questions.

Installs as a snippet — type ;secreview to paste this prompt anywhere on your Mac.
Prompt Template
Do a security review of the code below.

## Context
Language and framework: [e.g. Python, Flask]
What this code does: [e.g. public endpoint that looks up a user by name]
Who can reach it: [e.g. anyone on the internet, logged-in users only, internal only]
Data it handles: [e.g. emails, payment info, none sensitive]

## Code
[paste the code]

## Instructions
- Check for injection, broken access control, exposed secrets, unsafe deserialization, missing input validation and sensitive data leaks.
- For each finding, explain how an attacker would exploit it in one or two sentences.
- Show the fixed code for each finding.
- Do not list generic advice that does not apply to this code.
- Say clearly if you cannot judge something without seeing more code (e.g. auth middleware).

## Output format
Findings grouped as High, Medium, Low. Each with: issue, line, exploit, fix.

Context
- Files involved: [list the files, or reference them in the chat]
- How I build and test: [e.g. npm test]

How to use this prompt

  1. 1

    Open Claude Code

    Run claude in your project directory and paste the prompt.

  2. 2

    Give it context

    Name the files, commands and tests involved. Claude Code can read files and run commands in your project, asking permission as it goes.

  3. 3

    Review and iterate

    Approve or decline each edit and command, then reply in the same session to adjust.

  4. 4

    Save what you repeat

    Put project conventions (how to run tests, style rules, folders to avoid) in a CLAUDE.md file so every session starts with them.

Working in Claude Code

  • •Claude Code works in your terminal, so tell it the exact commands for building and testing.
  • •Ask it to explain its plan before large edits; you can stop it if the plan is wrong.
  • •Start a fresh session for an unrelated task so earlier context doesn't steer the new one.

Worked example

What you give it

Framework: Python, Flask, sqlite3
What it does: returns a user's id and email by name.
Who can reach it: anyone on the internet.

@app.route("/user")
def get_user():
    name = request.args.get("name")
    row = db.execute("SELECT id, email FROM users WHERE name = '" + name + "'").fetchone()
    return {"id": row[0], "email": row[1]}

What a good answer looks like (shortened)

High: SQL injection (the db.execute line)
Exploit: a request with name set to ' OR '1'='1 returns the first user, and crafted UNION payloads can read other tables.
Fix: use a parameterized query.
row = db.execute("SELECT id, email FROM users WHERE name = ?", (name,)).fetchone()

Medium: email exposed with no authentication
Exploit: anyone can collect user emails by guessing names.
Fix: require login and return email only to the account owner or an admin.

Low: unhandled missing user
If no row matches, row[0] raises and returns a 500 that may leak a stack trace in debug mode.
Fix: if row is None: return {"error": "not found"}, 404

Tips for better results

  • •Fill in "Who can reach it" and "Data it handles" honestly. They decide whether a finding is High or Low.
  • •Paste the auth middleware or permission checks if they live elsewhere. Otherwise the AI will rightly flag access control as unknown.
  • •Start a fresh session for an unrelated task so earlier context doesn't steer the new one.
  • •Avoid this: Leaving out who can reach the code, so the AI cannot tell an internal admin script from a public endpoint.

Get the free prompt pack

Our best coding prompts in one Markdown file, delivered by email. The templates here stay free either way — the pack just saves you the copying.

Variations

Threat model first

Add this line to Instructions: Before reviewing, list the three most likely attackers and what each would want from this code.

Dependency check

Add this section: ## Dependencies [paste package.json or requirements.txt] and flag packages that are commonly misconfigured or need pinning.

Checklist output

Change Output format to: A table with columns: check, pass or fail, line, fix.

Save it as a Retext snippet

Retext is a free text expander for Mac. Save this prompt once, then type ;secreview in any app (ChatGPT, Claude, your editor, a browser tab) and the full prompt is pasted in.

  1. Click Add to Retext. The prompt installs as a snippet with the trigger ;secreview.
  2. Change the trigger in Retext if you prefer a different one.
  3. Type the trigger wherever you want the prompt, then fill in the brackets.

Frequently asked questions

Is an AI security review enough before launch?

No. It is a useful first pass that catches common mistakes like injection and missing auth checks. Sensitive systems still need a dependency scan, a review by someone with security experience, and testing.

Will Claude Code run commands without asking?

By default it asks for permission before editing files or running commands. You approve each step, which is a good moment to check its plan against the prompt.

Is it safe to paste code into an AI for a security review?

Remove secrets, keys and customer data first, and follow your company's policy on sharing source code. The review works just as well with placeholder values.

How do I reuse this prompt without copying it every time?

Click Add to Retext to save it as a snippet. Then type ;secreview in any Mac app, including your AI tool, and the full prompt is pasted in.

Related Templates

Get the free prompt pack

Our best coding prompts in one Markdown file, delivered by email. The templates here stay free either way — the pack just saves you the copying.