Claude Code中英文系列教程23:通过Output styles 输出样式控制系统提示词并关闭编码技能

4 阅读6分钟

Adapt Claude Code for uses beyond software engineering 将Claude Code 用于软件以外的其它地方

Output styles allow you to use Claude Code as any type of agent while keeping its core capabilities, such as running local scripts, reading/writing files, and tracking TODOs. 输出样式允许你将 Claude Code 用作任何类型的agent,同时保留其核心功能,例如运行本地脚本、读取/写入文件以及跟踪待办事项。

一,Built-in output styles 内置输出样式

Claude Code’s Default output style is the existing system prompt, designed to help you complete software engineering tasks efficiently. Claude Code 的默认输出样式是现有的系统提示,旨在帮助您高效地完成软件工程任务。

There are two additional built-in output styles focused on teaching you the codebase and how Claude operates: 还有两种额外的内置输出样式专注于教您代码库以及 Claude 如何运行:

1.1,Explanatory: Provides educational “Insights” in between helping you complete software engineering tasks. Helps you understand implementation choices and codebase patterns.

解释性:在帮助您完成软件工程任务的同时提供教育性的“洞察”。帮助您理解实现选择和代码库模式。

1.2 Learning: Collaborative, learn-by-doing mode where Claude will not only share “Insights” while coding, but also ask you to contribute small, strategic pieces of code yourself. Claude Code will add TODO(human) markers in your code for you to implement.

学习:协作式、边做边学模式,Claude 不仅会在编码时分享“洞察”,还会请你贡献一些小的、策略性的代码片段。Claude Code 会为你添加 TODO(human) 标记,供你实现。

二,How output styles work 输出样式的工作原理

Output styles directly modify Claude Code’s system prompt. 输出样式会直接修改 Claude Code 的系统提示。

2.1 All output styles exclude instructions for efficient output (such as responding concisely). 所有输出样式都排除了高效输出的指令(例如简洁回应)。

2.2 Custom output styles exclude instructions for coding (such as verifying code with tests), unless keep-coding-instructions is true. 自定义输出样式会排除编码指令(例如通过测试验证代码),除非 keep-coding-instructions 为真。

2.3 All output styles have their own custom instructions added to the end of the system prompt. 所有输出样式都会在系统提示符末尾添加自己的自定义指令。

2.4 All output styles trigger reminders for Claude to adhere to the output style instructions during the conversation. 所有输出样式都会在对话中触发提醒,要求 Claude 遵循输出样式指令。

三,Change your output style 更改您的输出样式

You can either: 你可以通过以下2种进行选择:

3.1 Run /output-style to access a menu and select your output style (this can also be accessed from the /config menu) 运行 /output-style 访问菜单并选择你的输出样式(也可以从 /config 菜单访问)

3.2 Run /output-style [style], such as /output-style explanatory, to directly switch to a style 运行 /output-style [style] ,例如 /output-style explanatory ,直接切换到一种样式

These changes apply to the local project level and are saved in .claude/settings.local.json. You can also directly edit the outputStyle field in a settings file at a different level. 这些更改适用于本地项目级别,并保存在 .claude/settings.local.json 中。你也可以直接编辑不同的级别设置文件中的 outputStyle 字段。

四,Create a custom output style

创建自定义输出样式

Custom output styles are Markdown files with frontmatter and the text that will be added to the system prompt: 自定义输出样式是带有frontmatter前导内容的 Markdown 文件,其中包含将添加到系统提示词中的文本:


---
name: My Custom Style
description:
  A brief description of what this style does, to be displayed to the user #简要说明这种风格的作用,以供用户显示
---

# Custom Style Instructions  #自定义样式指令

You are an interactive CLI tool that helps users with software engineering
tasks. [Your custom instructions here...] #你是一个交互式命令行工具,帮助用户完成软件工程任务。[这里写你的自定义指令...] 

## Specific Behaviors #具体行为

[Define how the assistant should behave in this style...] #[定义助手在此样式下的行为...]

You can save these files at the user level (~/.claude/output-styles) or project level (.claude/output-styles). 您可以将这些文件保存在用户级别( ~/.claude/output-styles )或项目级别(或 .claude/output-styles )。

4.1 Frontmatter 前导内容

Output style files support frontmatter, useful for specifying metadata about the command: 输出样式文件支持frontmatter,可用于指定关于命令的元数据:

有以下3个字段

1,name:Name of the output style, if not the file name 输出样式的名称,如果不是文件名,默认 Inherits from file name 继承自文件名

2,description:Description of the output style. Used only in the UI of /output-style 输出样式的描述。仅在 /output-style 的 UI 中使用。

3,keep-coding-instructions:Whether to keep the parts of Claude Code’s system prompt related to coding. 是否保留 Claude Code 系统提示词中与编程相关的部分。 默认为false

五,Comparisons to related features

与其它相关功能的比较

5.1 Output Styles vs. CLAUDE.md vs. —append-system-prompt

输出样式与 CLAUDE.md 与 —append-system-prompt 的对比

Output styles completely “turn off” the parts of Claude Code’s default system prompt specific to software engineering. Neither CLAUDE.md nor --append-system-prompt edit Claude Code’s default system prompt. CLAUDE.md adds the contents as a user message following Claude Code’s default system prompt. --append-system-prompt appends the content to the system prompt. 输出样式完全“关闭”Claude Code 默认系统提示中特定于软件工程的部分。 CLAUDE.md 和 --append-system-prompt 都不会编辑 Claude Code 的默认系统提示。 CLAUDE.md 将内容作为用户消息添加到 Claude Code 默认系统提示之后。 --append-system-prompt 将内容附加到系统提示词。

5.2 Output Styles vs. Agents 输出样式与代理区别

Output styles directly affect the main agent loop and only affect the system prompt. Agents are invoked to handle specific tasks and can include additional settings like the model to use, the tools they have available, and some context about when to use the agent. 输出样式直接影响主代理循环,并且仅影响系统提示词。 agent被用来调用以处理特定任务,它包含额外的设置,如要使用的模型、可用的工具以及一些关于何时使用agent的上下文信息。

5.3 Output Styles vs. Skills 输出样式与技能区别

Output styles modify how Claude responds (formatting, tone, structure) and are always active once selected. Skills are task-specific prompts that you invoke with /skill-name or that Claude loads automatically when relevant. Use output styles for consistent formatting preferences; use skills for reusable workflows and tasks. 输出样式修改 Claude 的响应方式(格式、语气、结构),一旦选定就始终处于活动状态。 Skills是针对特定任务的提示,您可以使用 /skill-name 调用它们,或者当相关时 Claude 会自动加载。 使用输出样式以实现一致的格式偏好;使用skills以实现可重用的工作流程和任务。

小结: 所有输出样式都会在系统提示符末尾添加自己的自定义指令

输出样式完全“关闭”Claude Code 默认系统提示中特定于软件工程的部分。

/output-style [style

保存在~/.claude/output-styles 或 .claude/output-styles

CLAUDE.md 将内容作为用户消息添加到 Claude Code 默认系统提示之后。

--append-system-prompt 将内容附加到系统提示词。

输出样式修改 Claude 的响应方式(formatting, tone, structure) (格式、语气、结构)

Skills是针对特定任务的提示

使用skills以实现可重用的工作流程和任务