Skip to main content
In this lesson we cover Claude Code agents: what they are, how to create and edit them from the CLI, and how to run them programmatically with the Claude Code SDK (useful for CI/CD checks). You’ll get step-by-step examples for interactive CLI creation, agent editing, invoking agents, and a programmatic Python example for automation.
A presentation slide reading "Working with Claude Code Agents" with a large "Demo" label on a dark blue curved shape on the right. The background is light gray with a small "© Copyright KodeKloud" in the bottom-left.
Overview
  • Two common workflows:
    • Interactive: Create sub-agents from the Claude Code CLI and call them inside your development workflow.
    • Programmatic: Instantiate and run agents via the Claude Code SDK (Python, or other SDKs) for CI/CD automation.
When choosing a model for an agent, balance capability and cost. “Inherit-from-parent” keeps behavior consistent with the main conversation; “Sonnet” is a strong, general-purpose choice; “Haiku” is faster and cheaper for simpler checks.
CLI: Create and run a sub-agent interactively Quick flow
  1. Open Claude Code inside your repository (CLI shows your current working directory).
  2. Use the /agents command to list existing agents or start creating a new one.
  3. Choose a creation method: generate with Claude (recommended) or manual configuration.
  4. Select tools that the agent is allowed to use.
  5. Pick a model for the agent.
  6. Confirm and save the agent (stored under .claude/agents).
  7. Invoke the saved agent by name from the CLI.
Step-by-step example (condensed CLI transcript)
Creation method prompt
Tool selection (interactive UI) The CLI displays tool groups (All tools, Read-only, Edit, Execution, MCP, etc.). For a read-only reviewer you might enable only read-related tools such as Read, Grep, and WebFetch. Example selection prompt (condensed):
Model selection Pick a model that matches the complexity and cost trade-offs of your task:
Confirm and save When you confirm, the CLI shows a summary including the agent file path, tools, model, and description. Agents are saved as YAML/MD files under .claude/agents. Example agent summary (trimmed):
Editing an agent
  • Agents are stored in the repo (project-scoped) as files under .claude/agents. Open and edit them with your preferred editor to update name, description, tools, model, color, system prompts, and rules.
  • After saving edits the CLI may prompt to restart or reload to pick up changes.
  • Keep system prompts structured: clear rules, expected output format, and an examples section so agent outputs are consistent and actionable.
Example snippet from an agent file (metadata, system prompt, and rules). Note the YAML contains illustrative tags used by the agent file:
Using an agent from the CLI Once saved, call the agent by its name from the CLI. Example usage for a readability review:
Why agents are useful
  • Encode standard audits and rules (naming conventions, security checks) in an agent’s system prompt so you don’t re-write prompts.
  • Share agents in a repo for team consistency or keep them global/personal.
  • Run agents in CI to automate reviews before merges or deployments.
Programmatic use: Python SDK (CI/CD integration) Use cases
  • Automate readability/security/dependency checks in CI jobs.
  • Gate merges by failing the build on critical findings or by posting warnings to PRs.
  • Run reproducible, configurable inspections with consistent output formats.
Install the SDK in CI:
Example Node/Express snippet (context for what an agent might inspect)
Sample Python program using the Claude Code SDK
  • This example shows instantiating a Claude SDK client with a focused system prompt and a restricted set of allowed tools. It then queries the agent and streams the response, which is suitable for CI scripts that need structured output.
Model selection examples
  • Choose the right model identifier when configuring agents or clients. Below is a representative list of models (use the latest identifiers from the docs when available).
Other SDKs and language examples
  • SDKs are available in multiple languages (TypeScript, Java, Go, Ruby). Below is a compact Ruby example for reference (Anthropic client shown as a short snippet):
Be careful enabling write or execution tools (e.g., Bash, TodoWrite, KillBash) in CI. Execution-capable agents can change state or systems — prefer read-only tools for automated checks unless you have strict controls and audits in place.
Practical CI/CD recipe
  • Add a CI job that:
    1. Installs the Claude Code SDK (pip install claude-code-sdk) or other language SDK.
    2. Runs a script that instantiates a project-scoped agent with a deterministic system prompt and allowed tools.
    3. Parses agent output for structured results (e.g., JSON, line-tagged findings).
    4. Fails or warns the build based on severity thresholds.
Summary
  • Claude Code agents let you encode repeatable auditing rules (readability, security, dependency checks) into project-scoped or personal agents.
  • The CLI is ideal for iterative, interactive creation and local testing; agents are stored under .claude/agents.
  • The SDK supports programmatic execution in CI/CD for automated gating and reproducible checks.
  • Structure agent system prompts (rules + output format + examples) to get consistent actionable results.
Next steps
  • Try creating a lightweight code-readability-reviewer agent via the CLI, test it on a small file, then add a CI job that runs the agent on PRs.
  • In the next lesson we’ll cover test-driven development workflows with Claude agents and integrating them into your development lifecycle.

Watch Video