GitHub Copilot icon

GitHub Copilot

Use GitHub Copilot CLI for AI-powered code suggestions and explanations

Overview

This node integrates with the GitHub Copilot CLI to provide AI-powered code suggestions, explanations, and shell command recommendations directly within an n8n workflow. It leverages the official GitHub Copilot CLI tool (gh copilot) to generate helpful outputs based on user prompts.

Common scenarios where this node is beneficial include:

  • Generating code snippets or completing code blocks in various programming languages.
  • Getting explanations for existing code or commands to better understand their function.
  • Receiving shell command suggestions tailored to specific contexts like Git, Docker, npm/yarn, or file operations.

Practical examples:

  • A developer wants a quick JavaScript function to parse JSON data; they input a prompt describing the function, and the node returns a suggested implementation.
  • A user has a complex shell command and wants it explained; the node provides a detailed explanation.
  • A DevOps engineer needs Docker command suggestions for container management; the node offers relevant shell commands.

Properties

Name Meaning
Prompt The main request or question you want GitHub Copilot to assist with. For example, "Write a function to reverse a string."
GitHub Token (Optional) An optional authentication token generated by the GitHub CLI (gh auth token). Only tokens created via the GitHub CLI work with Copilot; personal access tokens from the GitHub website do not. If omitted, local CLI authentication is used.
Filter Output When enabled (default), removes GitHub Copilot CLI headers and footers from the response, leaving only the useful suggestion or explanation text.
Additional Context Optional extra information or constraints to provide more context for better suggestions. For example, specifying coding style preferences or environment details.

Output

The node outputs a JSON object per input item containing:

  • operation: The selected operation type (suggest, explain, or shell).
  • prompt: The original prompt provided.
  • context: Any additional context supplied (if any).
  • authMethod: Indicates whether authentication was done using a manual token or local CLI login.
  • tokenUsed: Boolean indicating if a manual token was used.
  • tokenPrefix: First few characters of the token used (for reference), or "none" if no token.
  • language: Programming language selected for code suggestions (only for suggest operation).
  • commandType: Type of shell command requested (only for shell operation).
  • output: The filtered or raw output from GitHub Copilot CLI, depending on the Filter Output setting.
  • cliRawOutput: The full raw standard output from the CLI command.
  • cliStderr: Standard error output from the CLI command, if any.
  • timestamp: ISO timestamp when the execution occurred.

No binary data is produced by this node.

Dependencies

  • Requires the GitHub Copilot CLI (gh copilot) installed and accessible at /usr/bin/gh.
  • Optionally requires a valid GitHub CLI-generated token for authentication, or prior local authentication via gh auth login.
  • Node.js child process execution capability to run CLI commands.
  • Environment variable HOME is set internally during execution to a fixed path for CLI compatibility.

Troubleshooting

Common Issues

  • Authentication failures: Using personal access tokens from the GitHub website will not work. Only tokens generated by the GitHub CLI (gh auth token) are accepted.
  • GitHub Copilot service errors: Temporary server issues may cause HTTP 500 errors.
  • Malformed requests: Incorrect prompts or parameters can lead to HTTP 400 errors.
  • Access denied: Lack of a valid Copilot subscription results in HTTP 403 errors.

Error Messages and Resolutions

  • HTTP 401 Unauthorized:
    Message indicates failed authentication.
    Resolution: Run gh auth login on the server or provide a token generated by gh auth token. Avoid using personal access tokens from the GitHub website.

  • HTTP 403 Forbidden:
    Access denied due to missing Copilot subscription.
    Resolution: Ensure your GitHub account has an active Copilot subscription.

  • HTTP 400 Bad Request:
    The request sent to Copilot is malformed.
    Resolution: Check the prompt and parameters for correctness.

  • HTTP 500 Internal Server Error:
    Temporary GitHub server issue.
    Resolution: Retry after some time.

  • General CLI errors:
    If no output is returned and an error message appears, verify that the GitHub Copilot CLI is installed correctly and accessible.

Links and References

Discussion