
- 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.
- Open Claude Code inside your repository (CLI shows your current working directory).
- Use the
/agentscommand to list existing agents or start creating a new one. - Choose a creation method: generate with Claude (recommended) or manual configuration.
- Select tools that the agent is allowed to use.
- Pick a model for the agent.
- Confirm and save the agent (stored under
.claude/agents). - Invoke the saved agent by name from the CLI.
.claude/agents.
Example agent summary (trimmed):
- 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.
- 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.
- 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.
- 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.
- 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.
- Add a CI job that:
- Installs the Claude Code SDK (
pip install claude-code-sdk) or other language SDK. - Runs a script that instantiates a project-scoped agent with a deterministic system prompt and allowed tools.
- Parses agent output for structured results (e.g., JSON, line-tagged findings).
- Fails or warns the build based on severity thresholds.
- Installs the Claude Code SDK (
- 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.
- Try creating a lightweight
code-readability-revieweragent 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.