Skip to main content

Example Prompt

Example Prompt is a predefined prompt template feature provided by Codely CLI that lets you quickly execute common tasks without manually entering complete prompts each time.

Overview

Example Prompts are TOML files stored in the example-prompts directory, each file containing:

  • description: A description of the prompt (optional but recommended)
  • prompt: The actual prompt content
  • append_args: Whether to append user input (optional, defaults to false)
tip

Example Prompts can significantly improve efficiency for repetitive tasks and are particularly suitable for team collaboration scenarios.

Built-in Example Prompts

Codely CLI provides the following Example Prompts by default:

  • git-commit - Review Git staged changes, generate commit message and commit
  • analyze - Analyze complex topics across large codebases
  • explain-code - Analyze and explain code functionality in detail

Non-Interactive Mode Usage

In non-interactive mode, use the --example-prompt parameter to execute predefined prompts.

Basic Usage

# Execute git-commit example prompt
codely --example-prompt git-commit -y

# Execute explain-code example prompt
codely --example-prompt explain-code -y

Viewing Available Example Prompts

Use the --list-example-prompts parameter to view all available Example Prompts:

codely --list-example-prompts

Sample output:

Available example prompts:

- git-commit: Review Git staged changes, generate commit message and commit
- analyze: Analyze an open/complex topic across a very large codebase
- explain-code: Analyze and explain code functionality in detail

Combining with Other Parameters

# Use yolo mode (auto-confirm all operations)
codely --yolo --example-prompt git-commit

# Specify model
codely --model gpt-4 --example-prompt analyze

# Specify working directory
codely --path /path/to/project --example-prompt explain-code

Limitations

The --example-prompt parameter cannot be used simultaneously with the following parameters:

  • --prompt or -p: Directly specify a prompt
  • --prompt-interactive or -i: Interactive prompt input

Using them together will result in an error:

Cannot use both --example-prompt and --prompt (-p) together

warning

Be aware of parameter conflicts and avoid using incompatible parameter combinations simultaneously.

Interactive Mode Usage

In interactive mode, use the /example-prompt slash command to execute predefined prompts.

Starting Interactive Mode

codely

Listing Available Example Prompts

In interactive mode, directly enter /example-prompt (without parameters):

/example-prompt

Sample output:

Available example prompts:

git-commit: Review Git staged changes, generate commit message and commit
analyze: Analyze an open/complex topic across a very large codebase
explain-code: Analyze and explain code functionality in detail

Usage: /example-prompt <subcommand>

Executing a Specific Example Prompt

Use /example-prompt <name> to execute a specific prompt:

# Execute git-commit
/example-prompt git-commit

# Execute explain-code
/example-prompt explain-code

# Execute analyze
/example-prompt analyze

Example Prompts with Parameters

Some Example Prompts (such as explain-code) support appending user input:

# Append code snippet after the prompt
/example-prompt explain-code

Then enter the code to analyze...

If the Example Prompt content contains an {input} placeholder, user input will replace that placeholder. If append_args = true is set, user input will be appended to the end of the prompt.

Using Tab Auto-Completion

In interactive mode, after entering /example-prompt , press the Tab key to auto-complete available Example Prompt names.

Creating Custom Example Prompts

You can create your own Example Prompt files to automate common tasks.

File Location

In a development environment, place custom TOML files in:

packages/cli/example-prompts/

In packaged versions, Example Prompts are located in:

bundle/example-prompts/

TOML File Format

description = "Brief description of this prompt's purpose" prompt = """ Your prompt content... Can span multiple lines """

Optional: Whether to append user input to the end of the prompt

append_args = false

Example: Creating a Code Review Prompt

Create file code-review.toml:

description = "Review code for best practices, bugs, and improvements"
prompt = """
You are an expert code reviewer. Please review the following code and provide:

1. **Bug Detection**: Identify any potential bugs or logic errors
2. **Best Practices**: Check if the code follows best practices for the language/framework
3. **Performance**: Suggest any performance improvements
4. **Security**: Identify any security vulnerabilities
5. **Code Style**: Suggest improvements to code readability and maintainability
6. **Testing**: Recommendations for test coverage

Code to review: {input}
"""
append_args = true

Using Custom Prompts

Non-interactive mode

codely --example-prompt code-review

Interactive mode

/example-prompt code-review

Advanced Usage

Combining Multiple Prompts

While you cannot use multiple --example-prompt parameters simultaneously, you can use them sequentially in interactive mode:

/example-prompt git-commit

Wait for completion...

/example-prompt analyze

As Part of a Script

You can use Example Prompts in automation scripts:

#!/bin/bash

Auto-commit changes

codely --yolo --example-prompt git-commit

Analyze codebase

codely --example-prompt analyze > analysis.txt

Using in CI/CD

Example Prompts can be integrated into CI/CD workflows:

GitHub Actions example

  • name: Auto commit run: | git add . codely --yolo --example-prompt git-commit git push

Frequently Asked Questions

Q: How can I view the specific content of an Example Prompt?

A: Example Prompt files are in TOML format and can be opened directly in an editor:

View in example-prompts directory

cat packages/cli/example-prompts/git-commit.toml

Q: Can I use environment variables in Example Prompts?

A: Example Prompt files themselves do not support environment variable substitution. If you need dynamic content, it's recommended to:

  1. Use the --prompt parameter when calling to directly pass a prompt containing environment variables
  2. Or append dynamic input after using /example-prompt in interactive mode

Q: Do Example Prompts support multiple languages?

A: Yes. The prompt field of an Example Prompt can use any language. Built-in Prompts use English, but you can create Chinese versions of Example Prompts.

Q: How do I debug Example Prompts?

A: When using /example-prompt in interactive mode, Codely CLI displays execution results. If you encounter errors:

  1. Check if the TOML file format is correct
  2. Ensure the prompt field exists and is not empty
  3. Check error messages in console output

Q: How can I share Example Prompts?

A: There are several ways:

  1. Commit the TOML file to your project's example-prompts directory
  2. Share the TOML file with team members so they can place it in the corresponding directory
  3. Create a custom Codely CLI version containing Example Prompts

Best Practices

  1. Clear Descriptions: Provide clear description for each Example Prompt
  2. Keep it Simple: Prompts should focus on a single task
  3. Use Placeholders: Use {input} placeholders for scenarios requiring user input
  4. Version Control: Include custom Example Prompts in version control
  5. Document: Provide additional documentation for complex Example Prompts
  • --prompt or -p: Directly specify a prompt
  • --prompt-interactive or -i: Interactive prompt input
  • --list-example-prompts: List all available Example Prompts
  • /example-prompt: Example Prompt command in interactive mode