Is Claude Code safe? A security guide for Claude Code projects
Claude Code runs in your terminal or IDE with access to your files and shell. By default it asks before it edits files or runs most commands, and you decide how much to loosen or tighten that. This guide covers both sides: locking down the agent, and checking the app it builds.
Is Claude Code safe to use?
Anthropic's documentation describes a permission-based design: in manual mode Claude Code starts read-only and asks before it edits files or runs commands, and network commands like curl and wget are not auto-approved. It is as safe as your approvals, your deny rules and your isolation. No safeguard removes prompt injection risk entirely, so review what it proposes.
How to lock down Claude Code
- Keep approvals on for anything that writes files or reaches the network, and add allow rules sparingly. Audit them any time with
/permissions. - Add deny rules for secrets and risky commands in
.claude/settings.jsonunderpermissions.deny. A deny rule matches the command as written, so pair it with the sandbox when you need real network enforcement. - Turn on the sandbox with
/sandboxto isolate bash commands at the filesystem and network level. - Trust folders deliberately. Claude Code shows a trust dialog for folders you have not trusted, and servers in a project's
.mcp.jsonhave their own approval prompt. - Vet MCP servers. Write your own or use providers you trust: Anthropic does not security-audit MCP servers.
- For untrusted code or content, run Claude Code in a VM or dev container.
{
"permissions": {
"deny": [
"Read(./.env)",
"Read(./.env.*)",
"Read(./secrets/**)",
"Bash(curl *)",
"Bash(wget *)"
]
}
}Before you ship what Claude Code built
Claude Code has a built-in /security-review command that reviews the changes on your current branch. It reads code, though. A scan of the deployed site shows what the outside world sees: what is in the JavaScript bundle, which headers are sent and which endpoints answer without a login.
Common security risks in Claude Code apps
1. Secrets committed during quick fixes
A key pasted into code or a prompt to get something working tends to stay in the file, in Git history and sometimes in the front-end bundle. Move it to an environment variable that only server code reads, and rotate it.
2. Checks on the page but not the endpoint
Generated auth often hides a button without protecting the route behind it. Every API route and server action has to verify the session and the user's permission itself.
3. Packages added without a second look
Coding agents sometimes suggest packages that do not exist or whose names resemble popular ones. Check the name, publisher and history before you install, and commit the lockfile.
4. Missing or permissive security headers
No Content-Security-Policy, HSTS or clickjacking protection, or a CSP with
unsafe-inlineandunsafe-eval, leaves an injected script much easier to run.5. Debug output and exposed files in production
Stack traces, verbose errors, public source maps and deployed
.envor.gitpaths reveal your stack and sometimes your keys.
What a FixPrompt scan checks
Passive checks on your public site, the same way a visitor's browser loads it. No attacks, no logins, no data queried.
- Secret key patterns for 30+ providers in JavaScript bundles and HTML
- Content-Security-Policy strength, HSTS, clickjacking and Permissions-Policy
- Session cookie flags and lifetime
- Common API paths that answer anonymous requests, plus rate-limit headers
- Debug headers, server banners, error pages, internal hostnames and HTML comments
- Public
.git,.env, source maps and backup files
Copy-paste fix prompt
Paste this into Claude Code, Cursor, Codex or any coding agent with access to your repository. A scan gives you a prompt tailored to the issues found on your live site.
Fix prompt
Review this project like a security engineer and fix issues in priority order. You can start with /security-review on the current branch, then go further: 1. Search the code and git history for hard-coded secrets. Move them to environment variables that only server code reads, and list the keys I must rotate. 2. Check every API route and server action: it must verify the session and the user's permission before reading or changing data. 3. Add a strict Content-Security-Policy (no unsafe-inline or unsafe-eval for scripts), plus HSTS, frame-ancestors, X-Content-Type-Options and Referrer-Policy. 4. Set session cookies with Secure, HttpOnly and SameSite=Lax, and add rate limiting to routes that call paid APIs. 5. Remove debug output and source maps from production, and list any dependency you added that I should double-check. Make small, reviewable commits and tell me how to verify each fix.
Want rules your agent follows on every task? Get security rules for Cursor, CLAUDE.md and AGENTS.md.
FAQ
- Does Claude Code have a built-in security review?
- Yes. The `/security-review` command runs a security pass over the changes on your current branch. It reviews code, so it complements a scan of the deployed site rather than replacing it.
- How do I stop Claude Code from reading my .env file?
- Add deny rules such as `Read(./.env)` under `permissions.deny` in `.claude/settings.json`. Keep real secrets out of the repository as well, and rotate any key the agent has already seen.
- Does this work with Cursor, Codex or Copilot too?
- Yes. The fix prompt is plain text for any coding agent with access to your repository, and the scan only looks at the public, deployed site.
Check your Claude Code app in minutes
Paste your URL and get a plain-English report with prioritized risks and a fix prompt for your AI. Your first scan is free.
Scan my app free