Updated on 2026-07-29 GMT+08:00

Code Fixing

CodeArts Agent IDE automatically fixes issues from various sources, such as manual commits, AI reviews, and tool alarms. It can fix both a single issue and multiple ones. It efficiently finds and resolves issues to significantly improve code quality and development efficiency.

Constraints

Table 1 Constraints

Category

Description

Environment requirements

  • Before running code fixing commands, ensure that the code to be fixed matches the JSON file from CodeArts Check.
  • The /fix-review-batch command depends on the review agent's review result review.json.
  • The /fix-codeartscheck-batch command depends on the check result provided by CodeArts Check.

Code Fixing Commands

The following describes how to use the four core commands.

/bugfix

Function: Automatically invokes the repair expert agent to fix code issues based on the trouble tickets submitted by users.

Syntax:

/bugfix <description>
Table 2 /bugfix command parameters

Parameter

Description

description

Issue description, for example, "A null pointer exception occurs during user login."

Example:

/bugfix "A null pointer exception occurs during user login."

/fix-review

Function: Fixes code based on a single review comment from the code review agent. This command processes only one comment at a time and is suitable for fine-tuning.

Syntax:

/fix-review <review_text>
Table 3 /fix-review command parameters

Parameter

Description

review_text

Description of an issue in the JSON file.

Example:
/fix-review " {
    "severity": "High",
    "ruleId": "G.CLS.06-CPP",
    "ruleDescription": "Do not call virtual functions in constructors or destructors.",
    "file": "src/Base.cpp",
    "line": "4",
    "issueDetails": "A base class constructor calls the virtual function Initialize(). When a derived object is constructed, the base constructor is called first. At this time, the object's derived part is not yet constructed, and the virtual function table still points to the base class. Therefore, Initialize() calls Base::Initialize() instead of Derived::Initialize(), resulting in the failure to implement polymorphic behavior. In addition, the Derived constructor calls Initialize() again (line 28), so Initialize() is called twice (the base version is called first, and then the derived version). This is not the expected behavior.",
    "fixSuggestion": "Extract the initialization logic required in the constructor as a non-virtual function (for example, private InitImpl). Alternatively, directly perform the initialization required by the base class in the Base constructor instead of calling a virtual function. For example:\n\n// Solution 1: Extract the initialization logic as a non-virtual private function. \nBase::Base(const std::string& n) : name(n) {\n    DoBaseInit(); // Non-virtual function \n}\n\nvoid Base::DoBaseInit() {\n    std::cout << \"Base Initialize for \" << name << \"\\n\";\n}\n\n// Solution 2: Directly perform initialization in each constructor without indirectly calling a virtual function. \nBase::Base(const std::string& n) : name(n) {\n    std::cout << \"Base Initialize for \" << name << \"\\n\";\n}\n\nDerived::Derived(const std::string& n, int v) : Base(n), value(v) {\n    std::cout << \"Derived Initialize for \" << name << \" with value \" << value << \"\\n\";\n}"
  }"

/fix-review-batch

Function: Fixes code based on multiple review comments from the code review agent. This command is suitable for resolving all review comments after code is committed in batches, which improves efficiency.

Syntax:

/fix-review-batch [filter] [file1.json file2.json file3.json ...]
Table 4 /fix-review-batch command parameters

Parameter

Description

filter

(Optional) Review comment level, which can be described in natural language, such as major, critical, high level, high risk, medium risk, and low risk.

file1.json file2.json file3.json ...

Path of the JSON file to be used for fixing. You can configure one or more paths. Use spaces to separate multiple paths.

A maximum of 100 review comments are allowed for each JSON file. As shown in Figure 1, the total number of review comments for Base.cpp cannot exceed 100 in the JSON file corresponding to Base.cpp.

Figure 1 Review comments for the Base.cpp file

Example:

  • Basic usage: Pointing to one or more JSON files
    /fix-review-batch /path/to/review.json
    /fix-review-batch /path/to/review1.json /path/to/review2.json
  • Filter by severity: Fixing only the issues marked as "High severity".
    /fix-review-batch High severity /path/to/review.json

/fix-codeartscheck-batch

Function: Fixes code based on the alarms generated by CodeArts Check.

Syntax:

/fix-codeartscheck-batch file_name1.json file_name2.json ...
Table 5 /fix-codeartscheck-batch command parameters

Parameter

Description

file_name1.json file_name2.json ...

CodeArts Check scans code and generates a JSON file that records all the issues found in the code. Set this parameter to the path of the JSON file. You can configure one or more paths and separate them with spaces.

Example:
/fix-codeartscheck-batch D:\TestCode\codecheck-result1.json codecheck-result2.json

Code Fixing Example

The following describes how to use the /fix-review-batch command to fix code.

  1. Log in to CodeArts Agent IDE as instructed in Quick Start.
  2. (Optional) Check whether there is a review comment file in JSON format. If yes, skip this step. If no, run the /review command to obtain the file.

    1. Click in the chat box and choose Shortcuts.
    2. Select /review from the displayed menu and click .
    3. After the command is run, the review comment file review.json is automatically generated.

      In the .codeartsdoer/review directory of the explorer's project root directory, a folder named in the format "year-month-day_hour-minute-second-millisecond_random string" is generated. View the review.json file in the report directory of this folder. For details about the /review command, see Code Review.

  3. Run /fix-review-batch to resolve the review comments in the review.json file.

    1. Click in the chat box, select Shortcuts, and choose /fix-review-batch from the displayed menu.
    2. Enter the path of a JSON file that contains code review comments, and click .
      Figure 2 Fixing code
    3. Wait until the command is run. The agent will display the number of issues fixed, their severities, and the fix content.

  4. Check whether the issues have been fixed based on the review comments.

    Run /review again to check whether the issues have been fixed.