Dev Agent
The Task Agent with GitHub integration — reads your codebase via the GitHub API, sends context to Claude, generates code changes, and opens pull requests automatically.
Dev Agent
The Dev Agent is the production implementation of the Task Agent with full GitHub integration. While the Task Agent documentation covers the abstract architecture, this page documents how the Dev Agent actually works — from reading your codebase to opening pull requests.
What It Does
When you send a command like @codespar instruct add a health check endpoint, the Dev Agent:
- Searches your repository for relevant files
- Reads the file contents via the GitHub API
- Sends everything to Claude with a structured prompt
- Parses Claude's response for file changes
- Creates a branch, commits the changes, and opens a pull request
The entire flow is automated — from understanding the request to delivering a reviewable PR.
Characteristics
| Property | Value |
|---|---|
| Base type | Task Agent (ephemeral) |
| AI Model | Claude Sonnet (configurable via TASK_MODEL) |
| Code access | GitHub API (search, read, write) |
| Output | Pull request with file changes |
| Max files read | 5 per task |
| Max file size | 20 KB per file |
| Max output tokens | 4,000 from Claude |
The executeWithRepo Flow
The core of the Dev Agent is the executeWithRepo method. Here is each step in detail:
Step 1: Search for Relevant Files
The agent extracts keywords from the user's instruction and searches the repository using the GitHub Code Search API:
The keyword extraction strips common words ("add", "a", "the", "fix") and focuses on domain-specific terms that are likely to appear in code.
Step 2: Read File Contents
For each relevant file (up to 5), the agent reads the full content via the GitHub API, with a 20 KB size limit per file:
Step 3: Fallback — File Tree
If the code search returns no results (common for new features that don't match existing code), the agent falls back to browsing the repository tree:
Step 4: Build Context Prompt
The agent constructs a prompt that includes all file contents and the user's instruction:
Step 5: Send to Claude
The assembled prompt is sent to Claude Sonnet (or whichever model is configured via TASK_MODEL):
Step 6: Parse File Changes
The agent extracts file changes from Claude's response using a regex pattern that matches the ===FILE: path=== format:
If Claude returns no parseable file blocks, the agent reports this to the user and includes Claude's raw response for context.
Step 7: Create Branch
A new branch is created from the repository's default branch:
The branch naming convention is always codespar/<taskId>, making it easy to identify branches created by CodeSpar.
Step 8: Commit Changes
Each file change is committed to the new branch via the GitHub API:
Step 9: Open Pull Request
Finally, the agent opens a pull request with a descriptive body:
Smart File Picker
Instead of relying on keyword-based GitHub Code Search, the Dev Agent now uses Claude Haiku to intelligently select relevant files from the full repository tree. The flow works as follows:
- The agent fetches the complete file tree from the repository
- The tree (file paths only, not contents) is sent to Claude Haiku along with the user's instruction
- Claude Haiku evaluates which files are most relevant to the task and returns a ranked list
- The agent reads the selected files via the GitHub API
This approach is significantly more accurate than keyword extraction because it understands the intent behind the task. For example, given "add rate limiting to the login endpoint," Claude Haiku can identify the route file, the middleware directory, and the existing auth files without needing exact keyword matches.
If the user attaches an image (such as a screenshot showing a UI issue), the image is also included in the file picker prompt so that Claude Haiku can factor visual context into its file selection.
Image Vision
When a user attaches a screenshot or image in Slack, the Dev Agent can see and analyze it. The flow:
- Slack sends the image metadata (including
url_private_download) in the message event - The adapter downloads the image using the bot token for authentication
- The image is base64-encoded and included in the Claude API request as an image content block
- Claude analyzes the image alongside the text instruction
Supported formats: PNG, JPEG, GIF, WEBP (max 4 MB per image).
Use cases:
- "Fix this contrast issue" with a screenshot of the UI
- Bug reports that include error screenshots
- Design feedback with annotated mockups
Channel support: Currently available in Slack (requires files:read bot scope). WhatsApp, Discord, and Telegram support is planned.
For a detailed setup guide, see Image Vision.
Diff-Based Edits
Instead of outputting entire file contents, the Dev Agent now uses a SEARCH/REPLACE format for more precise edits:
This approach has several advantages:
- Smaller diffs: Only the changed lines are included, reducing token usage and improving readability
- Fewer conflicts: Unchanged lines are not rewritten, minimizing the chance of overwriting concurrent changes
- Better review experience: The resulting PR diffs are cleaner and easier to review
When creating new files, the agent still outputs full file contents using the ===FILE: path=== format.
Multi-Turn Continuation
If Claude's response is truncated due to the output token limit, the Dev Agent automatically requests a continuation. The agent detects truncation by checking the stop_reason field in the API response. When it finds max_tokens instead of end_turn, it sends a follow-up request asking Claude to continue from where it left off. The responses are concatenated before parsing.
This ensures that large code changes are not cut off mid-file, even when the output exceeds the token limit for a single response.
Merge Command
After reviewing a pull request, you can merge it directly from chat:
The merge command supports three strategies:
| Strategy | Syntax | Description |
|---|---|---|
| Default | merge PR #42 | Uses the repository's default merge strategy |
| Squash | merge PR #42 squash | Squashes all commits into a single commit |
| Rebase | merge PR #42 rebase | Rebases commits onto the base branch |
The command checks that the PR exists, that CI checks have passed (if configured), and that the user has the required permissions before proceeding.
Environment Variables
| Variable | Required | Default | Description |
|---|---|---|---|
ANTHROPIC_API_KEY | Yes | — | Anthropic API key for Claude access. Without it, the agent runs in simulation mode. |
GITHUB_TOKEN | Yes | — | GitHub personal access token with repo scope |
TASK_MODEL | No | claude-sonnet-4-20250514 | Claude model for code generation |
Example: End-to-End
Here is a complete example of the Dev Agent in action:
Command
What Happens
- Keyword extraction:
["health", "check", "endpoint", "api"] - Code search: Finds
src/routes/index.ts,src/server.ts,src/routes/status.ts - File read: Reads all 3 files (total 4.2 KB)
- Claude prompt: Sends files + instruction to Claude Sonnet
- Claude response: Returns modified
src/routes/index.tswith new route and newsrc/routes/health.ts - Branch: Creates
codespar/task-abc123 - Commits: 2 file changes committed
- PR: Opens PR #15
Agent Response
Follow-Up
After the PR is created, you can ask the Review Agent to analyze it:
Limitations
Understanding the Dev Agent's limitations helps set appropriate expectations:
| Limitation | Value | Reason |
|---|---|---|
| Max files read | 5 | Keeps context window manageable and API costs predictable |
| Max file size | 20 KB | Prevents loading large generated files or minified bundles |
| Max output tokens | 4,000 | Balances response quality with latency and cost |
| No binary files | — | Cannot read or generate images, compiled assets, etc. |
| No cross-repo changes | — | Each task operates on a single repository |
| No interactive mode | — | Cannot ask clarifying questions mid-task (uses best judgment) |
When the Dev Agent Struggles
- Very large refactors spanning more than 5 files — break these into smaller tasks
- Tasks requiring runtime testing — the agent generates code but cannot execute it
- Ambiguous instructions — be specific about file paths and expected behavior
- Framework-specific boilerplate — mention the framework explicitly (e.g., "using Fastify" or "in the Next.js app router")
Tips for Best Results
- Be specific: Instead of "fix the bug", say "fix the auth timeout in src/auth/session.ts — sessions expire after 30 seconds instead of 24 hours"
- Mention file paths: If you know which files need changes, include the paths in your instruction
- One task at a time: Keep instructions focused on a single, well-defined change
- Reference existing patterns: "Add a health check endpoint following the same pattern as src/routes/status.ts"
- Review the PR: Always review the generated PR before merging — the agent is a coding assistant, not a replacement for code review
Next Steps
- Task Agent — architecture and execution modes
- Review Agent — automated PR analysis
- Dev Agent PR Guide — practical guide for using the Dev Agent
- Commands — full command reference