Claude Code & Automation for Security Teams
Claude Code for security scripting
Claude Code (F1) is a terminal-native agentic tool that reads your codebase, writes files, executes commands, and manages git workflows. For security teams, this means generating and maintaining PowerShell scripts, Python automation, KQL detection rules in version-controlled repositories, and infrastructure configuration files.
The difference between using Claude.ai for code generation and using Claude Code is agency. In Claude.ai, Claude generates a script as text in a conversation — you copy it, save it, and run it manually. In Claude Code, Claude writes the script directly to your filesystem, runs it in a test environment, checks the output, fixes errors, and commits the result to git. The workflow is closer to delegating a coding task to a junior developer than to asking a chatbot to write code.
For a security-specific use case: you tell Claude Code “audit all inbox rules across the tenant using the Microsoft Graph API, flag any rules that forward to external addresses or contain financial keywords, and output a report as a CSV.” Claude Code plans the implementation, writes the PowerShell script using the Graph PowerShell SDK, handles authentication and pagination, creates the CSV output, and runs a test. You review the script, verify the output, and approve the commit.
Cowork for delegated security tasks
Cowork (F1) executes multi-step tasks autonomously on your desktop. For security teams, Cowork handles tasks that are important but do not require real-time analyst attention: organizing evidence folders from an investigation (renaming, categorizing, and structuring files according to your case folder template), processing KAPE output files (reading multiple CSVs and producing a unified summary), compiling a weekly security metrics report from multiple data sources, and formatting investigation notes into the IR report template.
You describe the outcome, share the relevant folder, and check back when Cowork is done. The output is delivered directly to your filesystem — not as a conversation response but as actual files you can open, review, and use.
Computer Use extends Cowork’s reach to applications that do not have APIs. Claude can control your mouse and keyboard to navigate web portals, fill in forms, export data from dashboards, and automate browser-based workflows in security tools. For security teams, this means automating tasks in portals that only have a GUI — exporting reports from tools that lack an API, navigating compliance platforms to submit documentation, or extracting data from legacy security tools.
Scheduled automation
Both Claude Code and Cowork support scheduled tasks — automation that runs on a recurring basis without manual prompting.
Security-relevant scheduled tasks include: a weekly inbox rule audit that checks all tenant mailboxes for suspicious forwarding rules and sends a summary to the SOC channel, a Monday morning PR review that checks your detection rule repository for pending changes, a monthly compliance report that compiles metrics from multiple sources and formats them into your board report template, a daily sign-in anomaly check that runs a predefined KQL query and flags any results for analyst review, and a weekly dependency audit on your security tooling repository that checks for outdated packages with known vulnerabilities.
Scheduled tasks in Claude Code run while your machine is connected. They execute the defined workflow at the specified interval, save the output to the designated location, and can be configured to notify you (via Slack Connector or email) when results require attention.
Worked artifact — scheduled security audit task:
# Claude Code scheduled task definition # Run weekly: Monday 07:00 # Task: Audit tenant inbox rules for financial keyword forwarding Description: Connect to Microsoft Graph, enumerate all inbox rules across the tenant, flag any rule that forwards to an external address or contains keywords (invoice, payment, wire, bank, transfer, remittance). Output a CSV report to /reports/weekly-inbox-audit/. If any rules are flagged, send a summary to the #soc-alerts Slack channel. Requirements: - Use Microsoft Graph PowerShell SDK - Authenticate using the service principal in .env - Include: mailbox, rule name, conditions, forward address - Compare forward addresses against the corporate domain list - Save CSV with timestamp: inbox-audit-YYYY-MM-DD.csv - Slack notification only if flagged rules foundThis task definition is what you provide to Claude Code when setting up the scheduled task. Claude Code implements the script, tests it, and schedules the execution. You review the script before approving the schedule.
The human-in-the-loop requirement
Agentic AI in security operations requires a clear boundary between what Claude can do autonomously and what requires human approval.
Claude can generate autonomously: scripts, queries, reports, documentation, analysis, and file organization. These produce output that the analyst reviews before action.
Claude must not execute autonomously: account disabling, token revocation, firewall rule changes, email purges, device isolation, or any containment action that affects production systems. These are destructive actions that require human judgment about business impact, timing, and scope.
The boundary is simple: Claude can create and recommend. Claude must not execute destructive actions without explicit human approval. When setting up Claude Code or Cowork for security tasks, configure the tool permissions to restrict write access to approved directories and block execution of commands that modify production infrastructure.
MCP integration for security tools
MCP Connectors (F1, F2) extend Claude’s reach to external systems. For security teams, custom MCP servers can connect Claude to proprietary security tools — your SIEM, your ticketing system, your threat intelligence platform, your CMDB.
The built-in Connectors (Gmail, Slack, GitHub, Google Drive) cover many security workflows out of the box. For organizational tools that lack built-in Connectors, custom MCP servers bridge the gap. Building a custom MCP server requires development effort, but the result is a Claude that can query your SIEM data, create tickets in your incident management system, and pull enrichment from your threat intelligence platform — all within the conversation.
Try it: Generate and review a security script
If you have Claude Code installed, navigate to a test directory and ask Claude Code to write a PowerShell script that lists all conditional access policies in your Entra ID tenant using the Microsoft Graph PowerShell SDK, including the policy name, state (enabled/disabled/report-only), and target users/groups. Review the generated script line by line: does it use the correct Graph cmdlets? Does it handle authentication properly? Does it include error handling? Run it in your dev tenant. This exercise practices the generate → review → test workflow with a read-only script that carries no production risk.
Knowledge checks
Check your understanding
1. What is the key difference between generating code in Claude.ai versus using Claude Code?
2. You want to automate a weekly inbox rule audit that flags suspicious forwarding rules and notifies the SOC team. Which Claude surface and capability should you use?
3. Claude Code generates a containment script that disables a compromised user account and revokes their sessions. Should you configure this to run autonomously?
Key takeaways
Claude Code acts, Claude.ai describes. Use Claude Code for security scripting that needs to be written, tested, and maintained in a repository.
Cowork handles delegated tasks. Evidence organization, report compilation, data processing — describe the outcome and check back when done.
Scheduled tasks automate recurring operations. Weekly audits, daily checks, monthly reports — configured once, run automatically.
Generate → review → test → deploy is non-negotiable. The discipline applies to every piece of AI-generated automation, regardless of the surface.
Destructive actions require human approval. Claude generates and recommends containment. Humans approve and execute.