UnblockDevs

How to Share Code with AI Safely — Complete Secure AI Coding Workflow

AI coding assistants — ChatGPT, Claude, GitHub Copilot, Gemini, Cursor — are now core developer tools. They write boilerplate, find bugs, optimize queries, and generate tests. But every paste of real code exposes secrets, proprietary logic, and personal data to third-party AI infrastructure. This guide gives you a complete, repeatable workflow for getting full AI help without exposing a single credential or proprietary identifier.

3 steps

Scan → Mask → Send to AI → Restore. Under 60 seconds for any code snippet

18

Languages supported: JS, TS, Python, Go, Java, SQL, Ruby, Swift, Kotlin, Bash, YAML, and more

9

AI prompt templates: code review, bug report, security audit, performance, docs, refactor, tests, explain

1

The Core Problem: AI Tools Receive Everything You Send

When you paste code into ChatGPT or Claude, the entire text of that prompt — including any API keys, database URLs, emails, IP addresses, and function names — is transmitted to the AI provider's servers. The AI does not need your real credentials to help you. It only needs the structure and logic of your code. The fix is to replace real values with safe placeholders before sending, then restore them after.

This is code masking, and it works with any AI tool — ChatGPT, Claude, Copilot Chat, Gemini, Codeium, Tabnine, or any future assistant. The masking happens in your browser. The AI never sees your real identifiers.

2

The Complete Secure Workflow

1

Step 1 — Open Code Prompt Shield

Go to unblockdevs.com/code-prompt-shield. The tool runs entirely in your browser — nothing is sent to any server, including this one. All masking and restore logic executes in your local browser tab.

2

Step 2 — Select language and masking options

Select your programming language from 18 options (JavaScript, TypeScript, Python, Go, Java, SQL, JSON, C#, PHP, Rust, Ruby, Swift, Kotlin, Bash, YAML, TOML, C/C++, XML). Enable "Identifiers" to mask variable/function names, "Secrets" to mask API keys and credentials, and "PII" to mask emails, phone numbers, and IP addresses.

3

Step 3 — Click "Scan first" (optional but recommended)

Before masking, click "Scan first" to see exactly what sensitive content is in your code. The scanner lists every detected secret, PII item, and schema reference with severity level (critical/high/medium/low) and occurrence count. No masking happens yet — this is purely an audit step.

4

Step 4 — Add custom patterns if needed

Open Advanced Options to add custom regex patterns. If your company uses internal token formats (e.g., CORP-[A-Z]{4}-[0-9]{8}) or proprietary ID schemes, add the pattern here. It will be detected and masked as SECRET_XXXX along with the built-in patterns.

5

Step 5 — Click "Mask code"

Click Mask code (or press Cmd/Ctrl+Enter). Every identifier, secret, and PII item is replaced with a deterministic placeholder — VAR_XXXX for variables/functions, SECRET_XXXX for credentials, PII_XXXX for personal data, TABLE_XXXX for SQL tables, KEY_XXXX for JSON/YAML keys. The stat badges show exactly how many of each type were masked.

6

Step 6 — Choose an AI prompt template

Select a template from the dropdown: Code review, Bug report, Security audit, Performance, Documentation, Refactor, Write tests, or Explain code. The template prepends a context-setting instruction that tells the AI to use the same placeholder names in its response — which is essential for clean restoration.

7

Step 7 — Copy and paste into your AI tool

Click ChatGPT, Claude, Copilot, or Gemini to copy the masked code (with template). Paste into your AI tool. Ask your question. The AI responds with full logic help using the masked placeholder names — it never sees your real identifiers.

8

Step 8 — Restore original identifiers

Copy the AI's response. Paste it into the Restore panel in Code Prompt Shield. Click Restore. Every VAR_XXXX, SECRET_XXXX, and PII_XXXX placeholder is replaced back with the original real name. The restored code is production-ready.

3

What Gets Masked — By Category

textMasking categories and placeholder formats
Category         Placeholder format   Examples detected
────────────────────────────────────────────────────────
Identifiers      VAR_XXXX            getUserOrders, fetchPaymentData, calculateChurn
                 FN_XXXX             (Bash function names)
Secrets          SECRET_XXXX         sk-proj-abc123, AKIA..., eyJh..., postgres://...
                                     ghp_tokens, xox-Slack-tokens, AIza-Google-keys
PII              PII_XXXX            user@example.com, +1-555-123-4567, 192.168.1.100
SQL tables       TABLE_XXXX          production.users, analytics.events
SQL columns      COL_XXXX            customer_email, lifetime_value, churn_risk_score
JSON/YAML keys   KEY_XXXX            "apiKey": ..., database_url: ...
XML tags         TAG_XXXX            <UserProfile>, <ApiConfig>
TOML sections    SEC_XXXX            [database], [production]

Same identifier → same placeholder everywhere

The masking is deterministic: getUserOrders always becomes the same VAR_XXXX in every occurrence — in function definitions, calls, imports, and JSDoc comments. This is what makes restoration lossless: every occurrence of the placeholder in the AI response maps back to the same original name.

4

Choosing the Right AI Prompt Template

The prompt template matters. Telling the AI upfront that it is working with masked code and should preserve placeholder names in its response prevents the AI from renaming variables or using generic names that break restoration. Here are when to use each:

🔍 Code review

Best for: general quality feedback, catching bugs, suggesting better patterns. The AI reviews the masked code and gives feedback referencing VAR_XXXX names. After restoration, the feedback references your real function names.

🐛 Bug report

Best for: a specific bug or unexpected behavior. Describe the bug after the masked code. The AI diagnoses the issue using placeholder names. Restore to get a diagnosis that references your real code.

🛡️ Security audit

Best for: checking for injection vulnerabilities, insecure patterns, missing input validation, or authentication flaws. The AI audits structure and logic — real credentials don't need to be present for a meaningful security review.

⚡ Performance

Best for: database query optimization, algorithm complexity analysis, identifying N+1 problems, suggesting caching strategies. Structural analysis works identically with masked names.

📝 Documentation

Best for: generating docstrings, JSDoc comments, README sections, or API documentation. The AI writes docs using placeholder names; restore to get docs with your real function and parameter names.

🧪 Write tests

Best for: generating unit tests, integration test stubs, or mock data. The AI writes test cases using masked names. After restoration, the tests reference your real functions and classes — ready to run.

5

Advanced: Custom Patterns for Company-Specific Secrets

The built-in detection covers all major public API key formats. But your company may use internal token formats, proprietary ID schemes, or custom authentication headers that the general patterns do not match. The Advanced Options panel lets you add custom regex patterns:

textCustom pattern examples (one per line in the Advanced Options)
# Internal session token format
SESS-[A-Za-z0-9]{32}

# Company service account credential
svc-[a-z]+-[0-9]{8}-[a-zA-Z0-9]{16}

# Internal API endpoint with sensitive subdomain
https://[a-z]+-internal.company.com/[a-zA-Z0-9/]+

# Legacy auth token format
AUTH:[A-Z]{2}[0-9]{6}:[a-zA-Z0-9+/]{44}==

# Custom payment reference
PAY-[A-Z]{3}-[0-9]{4}-[A-Z0-9]{8}

Any string matching a custom pattern is masked as SECRET_XXXX and fully restored after AI processing.

6

Team Workflow: Sharing Mapping Files

For team-based AI workflows — where one developer masks code, another asks the AI, and a third restores — the mapping file enables collaboration without breaking the security model:

Download the mapping file for team workflows

After masking, click .maskmap or Mapping to download the mapping as a JSON file. Share this file (via secure internal channels — not email or Slack) with anyone who needs to restore AI responses. The mapping file contains the full placeholder-to-original-name table. Anyone with the file can restore any AI response back to real names.

Cross-session consistency

Load a saved mapping file at the start of a new session to continue where you left off. Subsequent masks of related code will use the same placeholder assignments for identifiers that appeared in previous sessions — ensuring consistency across multi-session AI workflows.

Mapping file security

The mapping file contains your real function names, variable names, and secret values. Treat it with the same access controls as the secrets themselves. Store it in a secrets manager or encrypted file store — not in a shared Google Drive or Slack channel.

CI/CD integration

For automated code review workflows, the masking logic can be incorporated into pre-commit hooks or CI pipelines. Strip secrets before code reaches any AI-powered analysis tool — treat it as a pre-processing step in your pipeline.

Onboarding developers to the workflow

Add Code Prompt Shield to your developer onboarding documentation alongside your secrets management guidelines. The four-step workflow (paste → scan → mask → send) takes under 60 seconds once learned.

7

What the AI Can Still Do With Masked Code

The most common concern is that masking reduces AI help quality. It does not. Here is a complete list of what AI tools do equally well with masked code:

AI quality: masked vs. unmasked

What you think AI needs — your real names

❌ Bad
// Concern: AI won't help without real names
// WRONG — AI sees this as equivalent structure:
function getUserOrders(userId: string): Promise<Order[]> {
  return db.query('SELECT * FROM orders WHERE user_id = $1', [userId]);
}

What AI actually needs — just the structure and pattern

✅ Good
// What AI actually receives — structurally identical:
function VAR_ABCD(VAR_EFGH: string): Promise<VAR_IJKL[]> {
  return VAR_MNOP.VAR_QRST('SELECT * FROM VAR_UVWX WHERE VAR_YZAB = $1', [VAR_EFGH]);
}
// AI can: type this correctly, optimize the query,
// add error handling, suggest indexes, write tests
// — all without seeing getUserOrders or the real table name.

AI tools work equally well with masked code for all of the following:

Logic and algorithm improvements

AI identifies inefficient loops, suggests better data structures, spots unnecessary complexity — all from code structure alone.

Security vulnerability detection

SQL injection patterns, missing input validation, insecure random number usage, hardcoded values — structural issues detectable without real names.

Test generation

AI writes unit tests, edge case tests, and mock data for masked functions. After restoration, tests reference real function names and are immediately runnable.

Documentation generation

Docstrings, JSDoc, type annotations, README sections — all generated from masked code and restored to use real names.

Frequently Asked Questions