Skip to main content

Code writer

The Code Writer tool lets agents propose and apply code changes in connected GitHub or Bitbucket Cloud repositories. Add it to an agent when a workflow must create or update a draft pull request while keeping human review and merge in the source control system.

With Code Writer, you can:

  • Use issue details, logs, stack traces, Code Search results, and other earlier step outputs as context
  • Plan a targeted change in a configured repository and branch
  • Create or update a draft pull request for review
  • Return the pull request URL and a summary to later workflow steps

Inputs​

Configure Code Writer in agent builder with instructions, a target repository, and a base branch. You can also pass context from earlier steps.

Input or settingWhat to provideExample
InstructionsDescribe the focused code change that Code Writer must makeResolve the bug described in issue_description
Target repositoryChoose or map the repository where Code Writer must open the pull requestcompany/service-api
Base branchChoose or map the branch that the pull request must targetmain
Additional context (optional)Pass ticket details, logs, stack traces, file paths, function names, or code snippets from earlier stepsstack_trace

Give Code Writer enough detail to keep the change small and focused. The inputs can use fixed values or fields from earlier steps.

Outputs​

Code Writer returns the draft pull request URL, a summary of the change when configured, and status information. Later steps can show the link in Glean, post it to Jira or Slack, or use the status to start follow-up checks and notifications.

Check the step output schema in agent builder for the field names available in your environment.

Usage examples​

  • Propose a fix from a Jira issue: Read the issue summary and description, use Code Search to find relevant files, and pass that context to Code Writer. A later step can return the draft pull request URL in Glean or post it to Jira.
  • Respond to an escalation: Read a Slack escalation message and its logs or stack traces, then use Code Writer to propose a fix. A later step can post the draft pull request URL and summary in the channel for review.

Prerequisites​

  • An admin has configured Code Writer for your code host and granted access to you or your group. See Code Writer tool setup
  • A GitHub or Bitbucket Cloud connector is indexing the repositories where the agent will propose changes
  • For GitHub, the Glean GitHub App has read and write access to the target repositories
  • For Bitbucket Cloud, an admin has created a Code generation (Bitbucket) configuration, and each user authenticates the tool on first use
  • The agent uses a Think step because Code Writer runs only in Thinking mode

Configuration​

To add Code Writer to an agent:

  1. Open Agent Builder and select the agent you want to edit.
  2. Choose a point in the workflow after the agent has collected the issue, logs, or other context for the change.
  3. Click Add step.
  4. In Select step, go to Tools → By connector and select the code generation tool for your provider:
    • For GitHub, select GitHub / Code generation → Code Writer.
    • For Bitbucket Cloud, select Bitbucket / Code generation → Code Writer.
  5. Enter the instructions, target repository, base branch, and any additional context.
  6. Add a Respond step or another downstream step to use the pull request URL, summary, and status.

Limitations​

  • Code Writer runs only in Thinking mode through a Think step. It isn't available directly from a Respond step or normal chat without Thinking mode.
  • Code Writer supports connected GitHub and Bitbucket Cloud repositories.
  • The configured connector, provider identity, and running user's access determine which repositories Code Writer can use.
  • Code Writer creates or updates a draft pull request. Review and merge remain in the source control system.

Troubleshooting​

FAQ​

See also​

  • Code search — find relevant files, code, commits, and pull request diffs before proposing a change
  • Code Writer security — review Code Writer's security model, permissions, and controls
  • Code Generation — learn how users propose code changes from Glean