You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
• Add a new AI handler that routes completions through local Claude Code or Codex CLIs.
• Resolve the AI handler per request after repo settings are merged, avoiding stale config.
• Document and test CLI model selection, invocation behavior, and output parsing.
The following are alternative approaches to this PR:
1. LiteLLM provider adapter for the CLIs
➕ Keeps a single handler path (LiteLLM) for all models
➕ May reuse existing retry/logging/usage plumbing
➖ Not feasible unless CLIs expose an HTTP/OpenAI-compatible endpoint (they currently don’t)
➖ Would still require subprocess wrapping somewhere, just hidden behind a provider shim
2. Pluggable handler registry (entry points)
➕ Allows third-party handler implementations without editing core factory
➕ Makes adding future backends (more CLIs/local runners) cleaner
➖ More moving parts and packaging complexity than needed for two backends
➖ Harder to debug in monorepo installs; overkill for current scope
Recommendation: Current approach is appropriate: the CLIs are subprocess-only, so a dedicated handler is the cleanest integration point, and resolving the handler per request correctly accounts for repo-level config/model overrides. If more handlers/backends are expected to proliferate, consider evolving handler_factory into a registry to reduce conditional imports and centralize validation.
Files changed (6) +734 / -5
Enhancement (2) +435 / -0
cli_agent_ai_handler.pyAdd cli_agent AI handler that shells out to Claude/Codex CLIs+374/-0
Add cli_agent AI handler that shells out to Claude/Codex CLIs
• Introduces a new BaseAiHandler implementation that delegates chat completions to local 'claude' or 'codex exec' subprocesses using stdin (avoiding argv size limits). Adds backend/model parsing, safe/isolated invocation defaults, timeouts + retries, Claude JSON output parsing with usage capture, and optional structured-output unwrapping.
handler_factory.pyAdd handler factory with model-based auto-detection+61/-0
Add handler factory with model-based auto-detection
• Adds a lazy-import resolver that selects handlers by 'config.ai_handler', or infers 'cli_agent' from a 'cli/' model prefix, otherwise defaulting to LiteLLM. Encapsulates handler selection so entry points can call it after repo config is known.
pr_agent.pyResolve AI handler after settings merge (per request)+14/-5
Resolve AI handler after settings merge (per request)
• Defers AI handler selection until after CLI args and repo '.pr_agent.toml' are applied, preventing stale model/handler inference. Switches from a hardcoded LiteLLM default to using a handler factory when no explicit handler is injected.
test_cli_agent_ai_handler.pyAdd unit tests for cli_agent and handler selection+234/-0
Add unit tests for cli_agent and handler selection
• Covers 'cli/<backend>' model parsing, argv construction, Claude output parsing, stderr diagnostics, fenced-structured unwrapping, factory selection logic, and basic chat_completion flows for both Claude and Codex using mocks.
changing_a_model.mdDocument running models via local Claude Code/Codex CLIs+37/-0
Document running models via local Claude Code/Codex CLIs
• Adds a new section describing the 'cli/<backend>[/<model>]' model syntax and how it auto-selects the 'cli_agent' handler. Documents cli_agent configuration knobs, limitations (no images, no temperature), and expected best-fit commands.
configuration.tomlExpose ai_handler and cli_agent settings in default config+14/-0
Expose ai_handler and cli_agent settings in default config
• Documents 'config.ai_handler' including auto-detect behavior and adds a new '[cli_agent]' section covering binaries, timeouts, codex config isolation, extra args, and structured-output unwrapping.
1. Single quotes in data.get()📘 Rule violation⚙ Maintainability
Description
cli_agent_ai_handler.py uses single-quoted string literals ('result', 'subtype') inside
data.get(...), violating the double-quotes convention. This can cause style/lint noncompliance and
inconsistent codebase formatting.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
The new CLI agent handler uses single-quoted string literals, but the project requires double quotes for Python string literals.
## Issue Context
This is in newly added code and should be aligned with the repo's enforced quoting style.
## Fix Focus Areas
- pr_agent/algo/ai_handlers/cli_agent_ai_handler.py[234-236]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
The newly added module docstring begins with descriptive phrasing (AI handler that delegates...)
instead of imperative mood. This violates the docstring/comment phrasing requirement.
+"""AI handler that delegates completions to a locally installed coding-agent CLI+(Claude Code's `claude`, or Codex's `codex exec`) instead of an HTTP endpoint.
Relevance
●●● Strong
Imperative phrasing for comments/docstrings has been enforced and accepted recently.
ⓘ Recommendations generated based on similar findings in past PRs
Evidence
PR Compliance ID 2694688 requires newly added docstrings/comments to use imperative phrasing. The
module docstring starts with a descriptive clause rather than an imperative verb.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
Newly added docstrings/comments should use imperative phrasing (e.g., "Delegate...", "Return...") rather than descriptive phrasing.
## Issue Context
This rule applies to new/modified docstrings in the PR.
## Fix Focus Areas
- pr_agent/algo/ai_handlers/cli_agent_ai_handler.py[1-5]
- pr_agent/algo/ai_handlers/cli_agent_ai_handler.py[70-75]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
3. Overlong line in docs 📘 Rule violation⚙ Maintainability
Description
A newly added Markdown line exceeds the 120-character maximum. This reduces readability and violates
the repository line-length rule.
+If you already have [Claude Code](https://claude.com/claude-code) or [Codex](https://developers.openai.com/codex/cli) installed and logged in, PR-Agent can run its completions through those CLIs instead of calling a model API. Requests then bill against that CLI's existing login (e.g. a Claude or ChatGPT subscription) and no API key is configured in PR-Agent at all.
Relevance
●●● Strong
Team has accepted docs rewraps to satisfy line-length conventions in Markdown.
ⓘ Recommendations generated based on similar findings in past PRs
Evidence
PR Compliance ID 2694690 requires that modified source files do not contain lines longer than 120
characters. The added documentation line at 92 is a single long sentence exceeding that limit.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
At least one newly added line exceeds the 120-character limit.
## Issue Context
The compliance checklist requires a maximum line length of 120 characters for modified files.
## Fix Focus Areas
- docs/docs/usage-guide/changing_a_model.md[92-92]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
View medium (3) 4. Overlong TOML config line 📘 Rule violation⚙ Maintainability
Description
A newly added configuration.toml line (with an inline comment) exceeds the 120-character maximum.
This violates the line-length requirement for modified files.
ⓘ Recommendations generated based on similar findings in past PRs
Evidence
PR Compliance ID 2694690 requires that modified source files do not contain lines longer than 120
characters. The ai_handler line includes a long inline comment that pushes the line over the
limit.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
A modified TOML line exceeds the 120-character maximum due to a long inline comment.
## Issue Context
The compliance checklist enforces a 120-character max line length across modified files.
## Fix Focus Areas
- pr_agent/settings/configuration.toml[11-12]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
5. .pr_agent.toml missing new keys 📘 Rule violation≡ Correctness
Description
New configuration keys/sections were added under pr_agent/settings/configuration.toml but the root
.pr_agent.toml was not updated to reflect them. This violates the requirement to keep these
configuration locations in sync when behavior/config keys change.
+[cli_agent]+# Settings for the "cli_agent" AI handler, which runs completions through a locally+# installed coding-agent CLI instead of an HTTP API. Selected by a "cli/<backend>[/<model>]"+# model, e.g. config.model = "cli/claude/opus" or "cli/codex/gpt-5.1-codex-max".
Relevance
●● Moderate
Config consistency is valued, but no close precedent that .pr_agent.toml must mirror every new
configuration.toml key.
ⓘ Recommendations generated based on similar findings in past PRs
Evidence
PR Compliance ID 2694685 requires config key/behavior changes to be reflected consistently in both
.pr_agent.toml and pr_agent/settings/*.toml. This PR adds a new [cli_agent] section in
pr_agent/settings/configuration.toml, while .pr_agent.toml contains no corresponding
cli_agent/ai_handler configuration.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
Configuration keys/sections were added/changed in `pr_agent/settings/configuration.toml` without corresponding updates in the root `.pr_agent.toml`.
## Issue Context
The checklist requires keeping `.pr_agent.toml` and `pr_agent/settings/*.toml` in sync for configuration-key/behavior changes.
## Fix Focus Areas
- pr_agent/settings/configuration.toml[367-378]
- .pr_agent.toml[1-30]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
6. Auto actions bypass handler 🐞 Bug≡ Correctness
Description
GitHub Action runner auto paths call PRReviewer/PRDescription/PRCodeSuggestions without passing an
AI handler, so they always use the tools’ default LiteLLM handler and ignore both
config.ai_handler and cli/... model inference. This makes the new CLI-agent configuration
ineffective (and potentially breaks runs) for GitHub Action auto_review/auto_describe/auto_improve
flows.
ⓘ Recommendations generated based on similar findings in past PRs
Evidence
The config now documents auto-selection of cli_agent, but GitHub Action auto-actions still
construct tools with default handler values. The tools’ constructors default ai_handler to
LiteLLMAIHandler, so these call sites ignore the new handler selection logic entirely.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
### Issue description
GitHub Action runner auto-actions instantiate PR tools without providing an `ai_handler`, so the tools fall back to `LiteLLMAIHandler` regardless of `config.ai_handler` or a `cli/...` model.
### Issue Context
This PR introduces handler inference (`cli/...` -> `cli_agent`) and an explicit `config.ai_handler` knob, but that inference is only used where `get_ai_handler_class()` is called (currently via `PRAgent`). The GitHub Action runner has auto paths that bypass `PRAgent` and call tool constructors directly.
### Fix Focus Areas
- pr_agent/servers/github_action_runner.py[229-240]
- pr_agent/servers/github_action_runner.py[337-342]
Suggested change: after repo settings are applied (and after any env/config overrides are loaded), resolve `handler_cls = get_ai_handler_class()` and pass `ai_handler=handler_cls` into `PRDescription`, `PRReviewer`, and `PRCodeSuggestions` in both auto-action blocks (pull_request and workflow_run). Alternatively, route these auto-actions through `PRAgent().handle_request(...)` so they share the same resolution path.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Review mode: ⚖️ Balanced: Downgraded extended -> standard: change is below the extended eligibility bar (hunks 10/18, lines 739/200; both must reach the floor). Router rationale: This adds a substantial new subprocess-based handler, handler selection/configuration, CLI security and timeout behavior, parsing/retry paths, and integration changes across multiple independent code paths where subtle defects are plausible.
Author self-review: I have reviewed the code review findings, and addressed the relevant ones.
Tip of the day
💡 Did you know, you can add REVIEW.md to your repo root and Qodo follows it on every PR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.