Skip to main content
In this lesson, we’ll walk through creating and using agents in Claude Code. You’ll see both interactive CLI workflows (great for developer iteration) and programmatic SDK examples (ideal for CI/CD automation). The examples below show how to create, configure, and run agents for code review or incident diagnosis, and how to persist those agent definitions in a repository.
A presentation slide titled "Working with Claude Code Agents" with a dark curved design on the right containing the word "Demo" in blue. A small "© Copyright KodeKloud" appears in the bottom-left corner.
Overview: two common approaches
  • CLI sub-agents: Create sub-agents you can call interactively from the CLI during development and reviews.
  • SDK-driven agents: Create and invoke agents programmatically (Python, JS/TS, Go, Ruby, etc.) to automate checks in CI/CD pipelines.
Table: When to use CLI vs SDK CLI: listing agents and creating one The CLI shows whether any project agents exist and offers a guided flow for creating new agents. Example CLI output when no agents are present:
Create an agent: generation vs manual configuration You can either generate a draft agent from a description (recommended) or build the agent manually. Generation uses Claude to produce a starting configuration you can edit. Example selection UI showing the generation option:
When generating, provide a clear description of the agent’s responsibilities — the tool will create a draft configuration (metadata, system prompt, and rule set) that you can refine. Tool selection and model selection Agents can be granted fine-grained tool permissions (e.g., read-only, edit, execution) and you choose the model that balances reasoning capability and cost. Example tool-selection UI:
Example model-selection UI:
Confirm and save the agent After generation and selection, the CLI shows a confirmation summary. Review and save (or save-and-edit) the generated agent:
Agent created and listed Once saved, the agent appears in the project agent list and can be invoked interactively:
Editing an agent’s configuration Agent definitions are stored as files in your repo (YAML-style metadata plus the system prompt and rules). Open and edit them in your preferred editor. Example agent metadata:
System prompt and review rules (summary)
  • Role: Senior Code Quality Specialist focused on readability and maintainability.
  • Review checklist:
    • Assess variable and function naming clarity.
    • Flag vague or misleading names (e.g., data, temp, x).
    • Check naming consistency (camelCase vs snake_case).
    • Suggest descriptive alternatives and refactors.
    • Analyze function length, logic flow, and comment quality.
    • Identify magic numbers and hardcoded values.
    • Provide a readability score (1–10) with reasoning and prioritized fixes.
Using the agent via CLI Invoke a saved agent from the CLI to run a review. Example interaction and a cleaned-up sample report:
Example Express route (cleaned-up) Below is a sample Express route that demonstrates the quality improvements an agent might recommend: validation, shorter handler, and clear structure.
Typical recommendations from the agent
  • Define constants for database error codes.
  • Extract authentication logic to helper functions for testability.
  • Move hardcoded SQL queries into named constants or query builders.
  • Add unit tests for extracted functions.
Programmatic use: Python SDK for CI/CD integration Create and run agents programmatically using the Claude Code SDK. This integrates agents into CI/CD pipelines and automates code-quality checks on pull requests. Example Python SDK usage (async):
You can commit agent definitions (YAML) into your repository and call them from CI pipelines to enforce automated checks before merge. Example agent definition (commit to repo):
Supported models and language SDKs Claude Code supports multiple model families (examples): Example listing (illustrative):
There are SDKs and example snippets available for many languages. Two short illustrative examples:
Automating agents in CI/CD is a common pattern: run code-readability and security agents on pull requests, prevent merges when critical issues are found, and surface recommended fixes for developers to review before deployment.
Summary and best practices
  • CLI: Use the interactive CLI to quickly generate, iterate, and run agents during development.
  • SDK: Use language SDKs (Python, JS/TS, Go, Ruby, etc.) to integrate agents into CI/CD and automate checks.
  • Agent files: Commit agent YAMLs to the repository so teams share the same audit and review rules.
  • Permissions: Grant agents only the specific tools they need (read-only vs edit vs exec) to reduce risk.
  • Model selection: Balance model capability vs. cost by selecting appropriate Sonnet/Haiku/Opus variants or inheriting the parent conversation model.
Links and references

Watch Video