Skip to main content
The Code Writer action lets your agent propose and apply code changes in GitHub by creating or updating pull requests. Use it when you want agents to automate code edits as part of a workflow, while still keeping human review and merge in GitHub. When you add Code Writer to an agent, the agent can:
  • Read context from earlier steps (tickets, logs, stack traces, code search results).
  • Plan a targeted change.
  • Open a draft pull request in the right repository and branch.
  • Return the pull request URL and a summary to later steps in the workflow.

Usage examples

Jira bug‑fix agent

Use Code Writer to automatically propose a fix when a bug ticket arrives.

Example flow

  1. Trigger: Jira issue created or updated.
  2. Steps:
    • Read the Jira issue summary and description.
    • Optional: use code search to find relevant files.
    • Code Writer: generate a fix and open a draft pull request.
    • Respond with the pull request URL in Assistant or post it back to Jira or Slack.

What Code Writer does here

  • Uses the issue text and any attached context from earlier steps as instructions.
  • Targets the configured repository and branch.
  • Returns the draft pull request link and a short summary to downstream steps.

Escalation channel helper

Use Code Writer in an incident or escalation channel workflow to propose quick fixes.

Example flow

  1. Trigger: message posted in a specific Slack escalation channel.
  2. Steps:
    • Read the message and any attached logs or stack traces.
    • Optional: run code search based on the error.
    • Code Writer: propose a fix as a draft pull request.
    • Post the pull request URL and summary in the channel for engineers to review.

What Code Writer does here

  • Uses the message text and any attached logs or stack traces as instructions.
  • Targets the configured repository and branch.
  • Returns the draft pull request link and a short summary to downstream steps.

Configuration

Prerequisites
  • The Code Writer feature is enabled and configured by an admin.
  • A GitHub data source is connected and indexing the repositories where the agent will propose changes.
  • The Glean GitHub App is installed in your GitHub organization, with read/write access to the relevant repositories.
  • The Code Writer action is configured in the Admin console.
  • Access to Code Writer granted to you or your group in the action pack settings.
  • For agent users, GitHub OAuth must be completed on first use so Code Writer can run on their behalf.
  1. Open Agent Builder and select the agent you want to edit.
  2. Choose the step after you have collected enough context (for example, after reading a Jira issue, logs, or running code search).
  3. Click Add step.
  4. In Select step, go to ActionsBy datasourceGitHub / Code generation and select Code Writer.
You should now see the Code Writer step in your workflow.

Configure step inputs

In the Code Writer step, configure:
  • Instructions Describe what you want Code Writer to do, in plain language. For example:
    • “Propose a fix that resolves the bug described in the issue_description field.”
    • “Update the function documented in stack_trace so it handles null inputs gracefully.”
    You can reference values from earlier steps or fields using the agent’s expression syntax.
  • Target repository and branch
    • Choose or map the GitHub repository where Code Writer should open a pull request.
    • Select or map the branch to base the work on (for example a staging branch).
    These may be constant for the agent, or come from fields (such as a Jira custom field that names the repo).
  • Additional context (optional) Depending on your design, you can pass:
    • Ticket titles and descriptions.
    • Stack traces or logs.
    • File paths, function names, or code snippets from Read or code search steps.
    • User‑provided fields, such as a “change description”.
Give Code Writer enough detail to keep the change small and focused.

Outputs available to later steps

After Code Writer runs successfully, it returns:
  • Pull request URL: link to the draft pull request in GitHub.
  • Summary: a short description of what changed (if configured).
  • Status information: whether the operation succeeded or failed.
You can use these outputs to:
  • Respond to the user in Assistant with a link and explanation.
  • Post the pull request URL back to Jira or Slack.
  • Trigger follow‑up checks or notifications.
Check the step output schema in Agent Builder for the exact field names available in your environment.

Best practices

  • Keep changes small Use instructions that focus on a fix or a narrow update, rather than broad refactors.
  • Insert human‑in‑the‑loop steps Combine Code Writer with a “wait for user input” or review step where appropriate.
  • Use upstream context Feed Code Writer with structured context from earlier steps (tickets, logs, code search results) rather than pasting long free‑form prompts into the step configuration.
  • Handle errors gracefully Plan how your agent should respond when:
    • The pull request cannot be created.
    • The user does not have permission on the target repository.
By combining Code Writer with triggers, actions, and human‑in‑the‑loop steps, you can build agents that automate repetitive engineering work while keeping code review and deployment under your team’s control.