Claude Code Security: How to Govern the Agent Running in Your Terminal
Nexus is an AI-agent governance and observability platform by Swfte. This guide covers what makes Claude Code a security concern, the six risk categories, where Anthropic's built-in controls stop, how hook-level enforcement works, and a checklist you can apply today.
What makes Claude Code a security concern
Claude Code is not a coding assistant that suggests. It is an agent that acts. In a normal session it executes bash commands, writes files across the repo, installs dependencies, and connects to MCP servers. Every one of those actions runs with the same permissions as the developer who launched it: their credentials, their SSH keys, their cloud access.
That is precisely what makes it productive, and precisely what makes it an endpoint-security problem. It is also a problem your existing stack cannot see. SaaS-side security tools watch OAuth grants and app traffic. Claude Code operates in a terminal, a plane where CASB, SSPM, and SSO logs have no visibility at all.
The six risk categories
| Risk | Why it matters |
|---|---|
| Destructive or exfiltrating commands | A single bash tool call can run rm -rf, pipe a remote script into a shell (curl | sh), or post data to an external host. The command executes with the developer's credentials, on the developer's machine. |
| Writes to sensitive paths | Agents edit files fast and broadly. Without guardrails, that includes .env files, private keys, CI configuration, and production infrastructure directories. |
| Unvetted dependency installs | An agent that decides it needs a package will install it (npm, pip, cargo) without the vetting a human PR reviewer would apply. That is a supply-chain door opened from inside your terminal. |
| Prompt injection via untrusted content | Claude Code reads files, web pages, and tool output. Malicious instructions embedded in that content can steer the agent into actions the developer never asked for. |
| Unaudited MCP servers | Every MCP server added to a local config is a new tool surface with its own credentials and its own trust assumptions, and Anthropic does not audit MCP servers. |
| Zero organizational visibility | Permission prompts happen on one developer's machine. No one else sees who ran what, where, or what it changed. SaaS-side security tooling is blind to terminal activity by construction. |
The MCP surface is large enough to deserve its own guide: MCP security best practices. The visibility gap is one face of a wider problem, shadow AI.
What Anthropic's built-in controls cover, and where they stop
Claude Code ships with real safety machinery: permission prompts before sensitive actions, configurable allow and deny rules, and read-only defaults. For an individual developer on an individual machine these are good controls, and you should use them.
Their limits are structural, not qualitative. Every setting is per-developer and per-machine. Nothing aggregates across terminals, nothing enforces a single policy org-wide, and no security team can see what was allowed or denied anywhere. Approval fatigue works against the model too. After the fiftieth prompt, "allow always" becomes the default reflex, and those decisions accumulate silently on each laptop.
Individual permission prompts are a seatbelt. They are not a fleet policy.
Enforcement at the hook level
Claude Code exposes a hook system, and its PreToolUse hook is the enforcement point that per-developer settings are not. Before any tool call executes, a local, synchronous policy check runs. If the action violates policy, the hook returns permissionDecision: deny with a stated reason, and the tool never acts. The agent sees the denial and the reason, then moves on.
This is where destructive bash commands, writes to protected paths, and installs from non-allow-listed registries get stopped, before execution rather than in a post-hoc log review.
Audit trails: prompt to change to why
Blocking handles the actions you predicted. Audit handles the ones you did not. Per-terminal session capture records who did what, in which repo, on which terminal: every file change with a protected-file flag when a policy-guarded path was touched, every dependency install, every blocked action with its reason, and token usage and cost per turn. When someone asks what the agent changed and why, the answer is a trail rather than an interview.
Privacy is a tier, not an afterthought. By default Nexus stores metadata-only fingerprints, meaning prompt fingerprint and length, never prompt text. Deeper capture is an explicit opt-in per repository. That is what makes per-terminal telemetry deployable in organizations where recording developer prompts would be a non-starter. This trail is one layer of a broader AI agent governance program, and the observability half is covered in agent observability.
A Claude Code security checklist
Ten controls, no gate. Apply them in order. The first four stop the highest-impact incidents.
- 01
Control 1
Define deny rules for destructive bash patterns (rm -rf on broad paths, curl | sh, dd against devices) and enforce them before execution, not in code review. - 02
Control 2
Declare protected paths (.env, *.pem, key material, CI config, production infrastructure directories) and block agent writes to them. - 03
Control 3
Maintain a registry allow-list for dependency installs; block installs from unapproved registries. - 04
Control 4
Vet MCP servers like dependencies before they reach any developer config, and keep an approved-server list in source control. - 05
Control 5
Choose a prompt-capture privacy tier deliberately: metadata-only fingerprints by default, deeper tiers as an explicit per-repo opt-in. - 06
Control 6
Capture every session with terminal, user, repo, and branch attribution so "who ran what where" has an answer. - 07
Control 7
Flag file changes that touch protected paths and dependency installs as first-class audit events. - 08
Control 8
Roll out in audit mode first (record would-be blocks as findings) then switch to enforce mode once policy fits real workflows. - 09
Control 9
Review audit trails on a defined cadence, and wire policy findings into your existing security review process. - 10
Control 10
Track per-terminal token usage and cost so runaway sessions surface as anomalies, not invoices.
How Nexus implements this
One command: nexus wrap claude. It installs the hooks, starts the collector, and runs Claude Code governed, either by default or opt-in per run. Policy modes are per repository: enforce (deny violations in-flight), audit (record would-be blocks as findings without blocking), or off. The audit-first path lets you fit policy to real workflows before turning enforcement on.
The capture and enforcement layer is open source, so you can verify exactly what is recorded. The Nexus console adds the org-wide view: agent inventory, identity graph, shadow-AI findings, and the audit ledger. For agent-generated failures you will meet along the way, the errors hub covers the common ones, and Swfte security describes our own practices.
Claude Code security FAQ
- Is Claude Code safe for enterprise use?
- Claude Code is safe to adopt when it is governed. It ships permission prompts and read-only defaults, but it ultimately runs with the developer's own privileges. Enterprises should add organization-level controls (policy enforcement on tool calls, protected-path rules, dependency allow-lists, and per-terminal audit trails), rather than relying on each developer's individual permission settings.
- What can Claude Code actually do on my machine?
- With granted permissions it can execute shell commands, read and modify files, install packages, and connect to MCP servers and external tools. That is what makes it productive, and also what makes it an endpoint-security concern. A bad command is executed with your credentials, on your machine, in your repo.
- How do I block Claude Code from touching secrets like .env files?
- The reliable way is a PreToolUse policy hook that inspects every file write and bash command before it runs and denies writes to protected paths such as .env, *.pem, or production infrastructure directories. Nexus enforces these rules synchronously and locally, so the block happens before the action and cannot be bypassed by a network failure.
- Does monitoring Claude Code mean recording developer prompts?
- No. Nexus's default privacy tier is metadata-only. It stores a fingerprint and length for each prompt, never the text, and never diff content. Teams that need deeper forensics can opt into hashed or full tiers per repository, so privacy is a configuration decision, not an accident.
- What's the difference between Claude Code's built-in permissions and an enforcement layer like Nexus?
- Built-in permissions are per-developer choices made in the moment, and "don't ask again" decisions accumulate silently on each machine. An enforcement layer applies one policy across every terminal, records every allowed and denied action in an audit ledger, and gives security teams the prompt-to-change trail that individual permission prompts cannot provide.
Govern Claude Code in one command
nexus wrap claude. Capture is open source, so you see every session and block what policy forbids.
Open-core CLI · Metadata-only privacy tier by default · Enforce, audit, or off, per repo