graphite-skill
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGraphite Skill - Context-Efficient Git/Graphite Workflows
Graphite Skill - 上下文高效型Git/Graphite工作流
Stop drowning in verbose git/Graphite output. This skill automatically enables context-efficient workflows for all git and Graphite CLI operations in Claude Code through automatic delegation patterns.
告别冗长的Git/Graphite输出。本技能通过自动委托模式,为Claude Code中的所有Git和Graphite CLI操作自动启用上下文高效工作流。
Core Principles
核心原则
- Automatic Delegation: Verbose git/Graphite operations are automatically delegated to Task subagents
- Context Isolation: Raw CLI output (15KB+) is processed in isolated context, summaries (<50 tokens) returned
- Zero Friction: SessionStart hooks inject patterns automatically - no manual invocation needed
- Team-Ready: Git-trackable configuration for team-wide distribution
- 225x Efficiency: Dramatic context window improvements (4,108 tokens → 18 tokens)
- 自动委托:冗长的Git/Graphite操作会自动委托给Task子代理
- 上下文隔离:原始CLI输出(15KB+)在独立上下文中处理,仅返回摘要(<50 tokens)
- 零摩擦:SessionStart hooks自动注入模式,无需手动调用
- 团队适配:可通过Git追踪的配置,支持团队全域分发
- 225倍效率提升:大幅优化上下文窗口(4108 tokens → 18 tokens)
Problem Statement
问题背景
Before Graphite Skill (Context Pollution)
使用Graphite Skill之前(上下文污染)
bash
You: "Check my Graphite stack"
Claude: [Returns 15KB of JSON → 4,000+ tokens consumed]
Result: Context polluted, reasoning degraded, 2-3 operations maxTraditional git/Graphite operations flood context:
- → 15KB JSON (4,108 tokens)
gt stack - → 50KB output (12,000+ tokens)
git log --graph - → 20KB JSON (5,000+ tokens)
gt pr info - Multiple queries → Context window exhaustion
bash
你:"查看我的Graphite栈"
Claude:[返回15KB的JSON → 消耗4000+ tokens]
结果:上下文被污染,推理能力下降,最多仅能执行2-3次操作传统Git/Graphite操作会充斥上下文:
- → 15KB JSON(4108 tokens)
gt stack - → 50KB输出(12000+ tokens)
git log --graph - → 20KB JSON(5000+ tokens)
gt pr info - 多次查询 → 上下文窗口耗尽
After Graphite Skill (Context Efficiency)
使用Graphite Skill之后(上下文高效)
bash
You: "Check my Graphite stack"
Claude: [Automatically delegates to Task subagent]
Subagent: [Processes 15KB in isolated context]
Claude: "✓ feature/auth | 3 PRs | Review #456"
Result: Clean context, 18 tokens used, 100+ operations possiblebash
你:"查看我的Graphite栈"
Claude:[自动委托给Task子代理]
子代理:[在独立上下文中处理15KB内容]
Claude:"✓ feature/auth | 3个PR | 待审核#456"
结果:上下文整洁,仅使用18 tokens,可执行100+次操作Installation
安装
Auto-Detection (Recommended)
自动检测(推荐)
The skill automatically detects if setup is needed!
When you have the carbon-flow plugin installed globally but haven't set up Graphite Skill in your project, the SessionStart hook will automatically prompt you with:
⚠️ Graphite Skill Setup Required
Would you like to set up Graphite Skill in this project now?
If yes, run: bash ~/.claude/plugins/mad-skills/graphite-skill/install.sh --projectSimply run the provided command and the skill activates immediately. No need to remember or look up installation steps.
本技能会自动检测是否需要配置!
当你全局安装了carbon-flow插件但尚未在项目中配置Graphite Skill时,SessionStart hook会自动提示:
⚠️ 需要配置Graphite Skill
是否现在在本项目中配置Graphite Skill?
若是,请运行:bash ~/.claude/plugins/mad-skills/graphite-skill/install.sh --project只需运行提供的命令,技能立即激活。无需记忆或查找安装步骤。
Prerequisites
前置条件
- Git repository
- Claude Code 2.0+
- (Optional) Graphite CLI for Graphite-specific workflows
- (Optional) jq for JSON processing in hooks
- Git仓库
- Claude Code 2.0+ -(可选)Graphite CLI(用于Graphite专属工作流) -(可选)jq(用于hooks中的JSON处理)
Manual Installation
手动安装
bash
undefinedbash
undefinedNavigate to your project
进入你的项目目录
cd /path/to/your/project
cd /path/to/your/project
Run the installer
运行安装脚本
bash ~/.claude/plugins/mad-skills/graphite-skill/install.sh --project
bash ~/.claude/plugins/mad-skills/graphite-skill/install.sh --project
The installer will:
安装脚本会:
- Copy hooks to .claude/plugins/graphite-skill/
- 将hooks复制到.claude/plugins/graphite-skill/
- Configure SessionStart hook
- 配置SessionStart hook
- Set up agent templates
- 设置代理模板
- Make scripts executable
- 为脚本添加可执行权限
undefinedundefinedManual Installation
手动安装(另一种方式)
bash
undefinedbash
undefinedIn your project
在你的项目中
mkdir -p .claude/plugins/graphite-skill/hooks
mkdir -p .claude/plugins/graphite-skill/hooks
Copy files from the carbon skill directory
从carbon skill目录复制文件
cp ~/.claude/plugins/mad-skills/graphite-skill/hooks/session-start.sh .claude/plugins/graphite-skill/hooks/
cp ~/.claude/plugins/mad-skills/graphite-skill/settings.json .claude/plugins/graphite-skill/
cp ~/.claude/plugins/mad-skills/graphite-skill/hooks/session-start.sh .claude/plugins/graphite-skill/hooks/
cp ~/.claude/plugins/mad-skills/graphite-skill/settings.json .claude/plugins/graphite-skill/
Make hook executable
为hook添加可执行权限
chmod +x .claude/plugins/graphite-skill/hooks/session-start.sh
chmod +x .claude/plugins/graphite-skill/hooks/session-start.sh
Optional: Copy agent template
可选:复制代理模板
mkdir -p .claude/agents
cp ~/.claude/plugins/mad-skills/graphite-skill/agents/graphite-ops-template.md .claude/agents/
undefinedmkdir -p .claude/agents
cp ~/.claude/plugins/mad-skills/graphite-skill/agents/graphite-ops-template.md .claude/agents/
undefinedVerification
验证
bash
undefinedbash
undefinedTest hook execution
测试hook执行
bash .claude/plugins/graphite-skill/hooks/session-start.sh
bash .claude/plugins/graphite-skill/hooks/session-start.sh
Should output JSON with hookSpecificOutput
应返回包含hookSpecificOutput的JSON
Test in Claude Code
在Claude Code中测试
claude --debug hooks
claude --debug hooks
Look for:
应看到:
[SessionStart] Executing hook: session-start.sh
[SessionStart] 正在执行hook: session-start.sh
[SessionStart] Hook completed successfully
[SessionStart] Hook执行成功
undefinedundefinedHow It Works
工作原理
SessionStart Hook Mechanism
SessionStart Hook机制
The skill uses a SessionStart hook to inject context-optimization patterns automatically:
1. Session starts → SessionStart hook fires
2. Hook detects: git repo, project setup status, Graphite CLI, custom agent
3a. If not set up → Prompts user to run install.sh (auto-detection)
3b. If set up → Hook injects ~800 tokens of delegation patterns into context
4. Claude knows: Use Task delegation for verbose operations automatically
5. User benefits: Automatic context efficiency, zero manual effortAuto-Detection Logic:
The hook intelligently detects whether per-project setup has been completed by checking for the existence of in your project directory.
.claude/plugins/graphite-skill/hooks/session-start.sh- Not set up: Hook displays setup prompt with installation instructions
- Set up: Hook injects delegation patterns and activates context optimization
This means you never have to remember installation steps - the skill tells you exactly what to do.
本技能使用SessionStart hook自动注入上下文优化模式:
1. 会话启动 → SessionStart hook触发
2. Hook检测:git仓库、项目配置状态、Graphite CLI、自定义代理
3a. 未配置 → 提示用户运行install.sh(自动检测)
3b. 已配置 → Hook向上下文注入约800 tokens的委托模式
4. Claude知晓:自动对冗长操作使用Task委托
5. 用户获益:自动实现上下文高效,无需手动操作自动检测逻辑:
Hook通过检查项目目录中是否存在,智能判断是否已完成项目级配置。
.claude/plugins/graphite-skill/hooks/session-start.sh- 未配置:Hook显示配置提示及安装说明
- 已配置:Hook注入委托模式并激活上下文优化
这意味着你永远无需记住安装步骤——技能会明确告知你该做什么。
Automatic Delegation Pattern
自动委托模式
When you request git/Graphite operations, Claude automatically:
- Recognizes the operation will return verbose output
- Delegates to Task subagent with explicit instructions:
- Use flags for structured output
--json - Redirect errors with
2>/dev/null - Parse and summarize results
- Use
- Subagent executes in isolated context (absorbs verbose output)
- Subagent returns concise summary (<50 tokens)
- You receive actionable summary without context pollution
No manual invocation needed - patterns apply automatically!
当你请求Git/Graphite操作时,Claude会自动:
- 识别该操作会返回冗长输出
- 委托给Task子代理并附带明确指令:
- 使用标志获取结构化输出
--json - 通过重定向错误
2>/dev/null - 解析并总结结果
- 使用
- 子代理在独立上下文中执行(吸收冗长输出)
- 子代理返回简洁摘要(<50 tokens)
- 你收到可操作的摘要,无上下文污染
无需手动调用——模式自动生效!
Workflows
工作流示例
Basic Git Operations
基础Git操作
Checking status:
bash
You: "Check git status"
Claude: [Delegates automatically]
→ "3 modified, 2 staged, 1 untracked | Ready to commit"Viewing commit history:
bash
You: "Show me recent commits"
Claude: [Delegates automatically]
→ "Last 10: abc123 Feature, def456 Fix, ... | 3 authors, 2 days"Reviewing changes:
bash
You: "Show git diff"
Claude: [Delegates automatically]
→ "+47/-12 across 3 files | auth.ts, api.ts, tests/ | No conflicts"查看状态:
bash
你:"查看git状态"
Claude:[自动委托]
→ "3个已修改,2个已暂存,1个未跟踪 | 可提交"查看提交历史:
bash
你:"显示最近的提交"
Claude:[自动委托]
→ "最近10条:abc123 功能开发,def456 Bug修复,... | 3位作者,2天内"查看变更:
bash
你:"显示git diff"
Claude:[自动委托]
→ "+47/-12 涉及3个文件 | auth.ts, api.ts, tests/ | 无冲突"Graphite Workflows
Graphite工作流
Stack status:
bash
You: "Check my Graphite stack"
Claude: [Delegates automatically]
→ "✓ feature/auth | 3 PRs | #456 (needs review), #457 (approved), #458 (draft)"PR management:
bash
You: "Show PRs needing review"
Claude: [Delegates automatically]
→ "📋 2 PRs: #456 (Auth - awaiting review), #459 (Docs - changes requested)"Submitting stack:
bash
You: "Submit my stack for review"
Claude: [Delegates automatically]
→ "✓ 3 PRs created | CI running on all | Ready for review"Stack navigation:
bash
You: "Navigate to next branch in stack"
Claude: [Delegates automatically]
→ "Switched to feature/auth-ui (3/5 in stack)"栈状态:
bash
你:"查看我的Graphite栈"
Claude:[自动委托]
→ "✓ feature/auth | 3个PR | #456(待审核),#457(已批准),#458(草稿)"PR管理:
bash
你:"显示待审核的PR"
Claude:[自动委托]
→ "📋 2个PR:#456(Auth - 待审核),#459(文档 - 需要修改)"提交栈:
bash
你:"提交我的栈以供审核"
Claude:[自动委托]
→ "✓ 创建3个PR | 所有PR已启动CI | 待审核"栈导航:
bash
你:"导航到栈中的下一个分支"
Claude:[自动委托]
→ "已切换到feature/auth-ui(栈中第3/5个分支)"Supported Operations
支持的操作
Git Commands (auto-delegated):
- - Commit history with summarization
git log --graph - - Changes with statistics
git diff - - Status with file grouping
git status - - Branch listing with current indicator
git branch - All other verbose git commands
Graphite CLI Commands (auto-delegated):
- - Stack status with PR summaries
gt stack - - PR listing with filtering
gt pr list - - Detailed PR data with parsing
gt pr info - - Submission with confirmation
gt submit - - Stack history with formatting
gt log - All other verbose gt commands
Git命令(自动委托):
- - 提交历史及摘要
git log --graph - - 变更及统计
git diff - - 状态及文件分组
git status - - 分支列表及当前分支标识
git branch - 所有其他冗长Git命令
Graphite CLI命令(自动委托):
- - 栈状态及PR摘要
gt stack - - PR列表及过滤
gt pr list - - 详细PR数据及解析
gt pr info - - 提交及确认
gt submit - - 栈历史及格式化
gt log - 所有其他冗长gt命令
Two Approaches: Task Tool vs Custom Agent
两种方案:Task工具 vs 自定义代理
Task Tool (Default - Recommended)
Task工具(默认 - 推荐)
Zero setup, works immediately with automatic delegation:
bash
You: "Check my stack"
Claude: [Uses Task delegation automatically]
→ Concise summaryCharacteristics:
- ⚡ No configuration needed
- 📦 Works universally
- 🎯 Full context isolation
- ⚪ Standard terminal output
- ✅ Recommended for most users
零配置,自动委托立即生效:
bash
你:"查看我的栈"
Claude:[自动使用Task委托]
→ 简洁摘要特点:
- ⚡ 无需配置
- 📦 通用兼容
- 🎯 完全上下文隔离
- ⚪ 标准终端输出
- ✅ 推荐给大多数用户
Custom Agent (Optional - Power Users)
自定义代理(可选 - 高级用户)
Enhanced UX with colored terminal output:
bash
undefined带彩色终端输出的增强体验:
bash
undefinedOne-time setup in Claude Code
在Claude Code中一次性配置
/agents create
Name: graphite-ops
Color: cyan
Scope: project
Prompt: Load from .claude/agents/graphite-ops-template.md
/agents create
Name: graphite-ops
Color: cyan
Scope: project
Prompt: 从.claude/agents/graphite-ops-template.md加载
Use with color
带颜色使用
You: "graphite-ops check my stack"
graphite-ops [cyan]: ✓ feature/auth | 3 PRs | Review #456
**Characteristics:**
- 🎨 Colored terminal output (cyan)
- 👤 Consistent persona
- 📁 Git-tracked definition
- 🎯 Same context isolation
- 🔧 Requires one-time agent creation
**Agent Template Location:** `graphite-skill/agents/graphite-ops-template.md`你:"graphite-ops check my stack"
graphite-ops [cyan]: ✓ feature/auth | 3个PR | 待审核#456
**特点:**
- 🎨 彩色终端输出(青色)
- 👤 一致的角色设定
- 📁 Git可追踪定义
- 🎯 相同的上下文隔离
- 🔧 需要一次性创建代理
**代理模板位置:** `graphite-skill/agents/graphite-ops-template.md`Team Distribution
团队分发
Graphite Skill is designed for team-wide adoption:
bash
undefinedGraphite Skill专为团队全域采用设计:
bash
undefinedOne team member sets up
一位团队成员完成配置
./install.sh --project
git add .claude/
git commit -m "Add Graphite Skill context-optimization for git/Graphite"
git push
./install.sh --project
git add .claude/
git commit -m "添加Graphite Skill上下文优化以提升Git/Graphite效率"
git push
Other team members pull and get:
其他团队成员拉取后获得:
✓ Automatic context optimization
✓ 自动上下文优化
✓ Consistent behavior across team
✓ 团队内一致的行为
✓ Zero per-developer setup
✓ 无需每个开发者单独配置
**Team benefits:**
- Consistent git/Graphite workflows
- Automatic efficiency for all developers
- Git-tracked configuration (no separate distribution)
- SessionStart hook activates automatically
**团队收益:**
- 一致的Git/Graphite工作流
- 为所有开发者自动提升效率
- Git可追踪的配置(无需单独分发)
- SessionStart hook自动激活Configuration
配置
Default Configuration
默认配置
The skill works out-of-box with sensible defaults. No configuration required.
本技能开箱即用,具备合理默认值。无需额外配置。
Custom Configuration
自定义配置
Adjust behavior by editing :
.claude/plugins/graphite-skill/settings.jsonjson
{
"contextTokens": 800,
"delegationThreshold": 100,
"autoDetectGraphite": true,
"autoDetectCustomAgent": true,
"enableTaskDelegation": true,
"enableCustomAgent": true
}Settings explanation:
- : Amount of pattern context injected (default: 800)
contextTokens - : Token size to trigger delegation (default: 100)
delegationThreshold - : Automatically detect Graphite CLI presence (default: true)
autoDetectGraphite - : Detect and suggest custom agent if available (default: true)
autoDetectCustomAgent - : Enable automatic Task delegation (default: true)
enableTaskDelegation - : Enable custom agent support (default: true)
enableCustomAgent
可通过编辑调整行为:
.claude/plugins/graphite-skill/settings.jsonjson
{
"contextTokens": 800,
"delegationThreshold": 100,
"autoDetectGraphite": true,
"autoDetectCustomAgent": true,
"enableTaskDelegation": true,
"enableCustomAgent": true
}配置说明:
- : 注入的模式上下文token数量(默认:800)
contextTokens - : 触发委托的token阈值(默认:100)
delegationThreshold - : 自动检测Graphite CLI是否存在(默认:true)
autoDetectGraphite - : 自动检测并推荐可用的自定义代理(默认:true)
autoDetectCustomAgent - : 启用自动Task委托(默认:true)
enableTaskDelegation - : 启用自定义代理支持(默认:true)
enableCustomAgent
Efficiency Metrics
效率指标
| Metric | Before (Raw CLI) | After (Graphite Skill) | Improvement |
|---|---|---|---|
| Tokens consumed | 4,108 | 18 | 225x |
| Context pollution | High | Minimal | 99.6% reduction |
| Response quality | Degraded | Optimal | Focused reasoning |
| User effort | Manual patterns | Zero | Automatic |
| Operations before exhaustion | 2-3 | 100+ | 50x |
| 指标 | 之前(原始CLI) | 之后(Graphite Skill) | 提升幅度 |
|---|---|---|---|
| 消耗的Tokens | 4108 | 18 | 225倍 |
| 上下文污染 | 严重 | 极低 | 减少99.6% |
| 响应质量 | 下降 | 最优 | 聚焦推理 |
| 用户操作成本 | 手动设置模式 | 零成本 | 自动化 |
| 耗尽前可执行操作数 | 2-3 | 100+ | 50倍 |
Troubleshooting
故障排除
Hook not firing
Hook未触发
bash
undefinedbash
undefinedCheck permissions
检查权限
chmod +x .claude/plugins/graphite-skill/hooks/session-start.sh
chmod +x .claude/plugins/graphite-skill/hooks/session-start.sh
Check settings.json exists
检查settings.json是否存在
ls -la .claude/settings.json
ls -la .claude/settings.json
Test manually
手动测试
bash .claude/plugins/graphite-skill/hooks/session-start.sh | jq .
undefinedbash .claude/plugins/graphite-skill/hooks/session-start.sh | jq .
undefinedContext not appearing
上下文未出现
bash
undefinedbash
undefinedVerify hook returns correct JSON
验证hook返回正确的JSON
bash .claude/plugins/graphite-skill/hooks/session-start.sh |
jq '.hookSpecificOutput.hookEventName'
jq '.hookSpecificOutput.hookEventName'
bash .claude/plugins/graphite-skill/hooks/session-start.sh |
jq '.hookSpecificOutput.hookEventName'
jq '.hookSpecificOutput.hookEventName'
Should output: "SessionStart"
应输出:"SessionStart"
undefinedundefinedPatterns not applied
模式未生效
Start Claude with debug mode:
bash
claude --debug hooks以调试模式启动Claude:
bash
claude --debug hooksCheck for:
检查:
- Hook execution confirmation
- Hook执行确认
- Context injection success
- 上下文注入成功
- Any error messages
- 任何错误信息
undefinedundefinedDelegation not automatic
未自动委托
If Claude doesn't delegate automatically:
- Verify SessionStart hook is active:
claude --debug hooks - Check hook output contains delegation patterns
- Manually request delegation: "Use Task delegation for this"
- Review hook configuration in
settings.json
如果Claude未自动委托:
- 验证SessionStart hook已激活:
claude --debug hooks - 检查hook输出是否包含委托模式
- 手动请求委托:"对此使用Task委托"
- 查看中的hook配置
settings.json
Files and Structure
文件结构
graphite-skill/
├── SKILL.md # This file - complete skill reference
├── install.sh # Automated installation script
├── settings.json # Configuration settings
├── hooks/
│ └── session-start.sh # SessionStart hook for pattern injection
├── agents/
│ └── graphite-ops-template.md # Custom agent template (optional)
├── examples/
│ └── team-configuration.md # Example team configurations
├── test/
│ └── verify-installation.sh # Installation verification script
├── QUICKSTART.md # Quick start guide
└── README.md # Detailed documentation
References (from root skill directory):
- QUICKSTART.md - 5-minute setup guide
- README.md - Complete documentation
- examples/team-configuration.md - Team setup examplesgraphite-skill/
├── SKILL.md # 本文件 - 完整技能参考
├── install.sh # 自动化安装脚本
├── settings.json # 配置设置
├── hooks/
│ └── session-start.sh # 用于模式注入的SessionStart hook
├── agents/
│ └── graphite-ops-template.md # 自定义代理模板(可选)
├── examples/
│ └── team-configuration.md # 团队配置示例
├── test/
│ └── verify-installation.sh # 安装验证脚本
├── QUICKSTART.md # 快速入门指南
└── README.md # 详细文档
从根技能目录引用:
- QUICKSTART.md - 5分钟配置指南
- README.md - 完整文档
- examples/team-configuration.md - 团队配置示例When to Use This Skill
使用场景
Always active - The SessionStart hook applies patterns automatically, so you don't need to manually invoke this skill. Just use git/Graphite naturally:
- Checking stack status
- Reviewing PRs
- Viewing commit history
- Managing branches
- Submitting for review
- Any git/Graphite operation
The skill is already working if:
- SessionStart hook is installed
- Claude automatically delegates verbose operations
- You receive concise summaries instead of raw output
始终激活 - SessionStart hook自动应用模式,因此你无需手动调用本技能。只需正常使用Git/Graphite:
- 查看栈状态
- 审核PR
- 查看提交历史
- 管理分支
- 提交审核
- 任何Git/Graphite操作
技能已生效的标志:
- SessionStart hook已安装
- Claude自动委托冗长操作
- 你收到的是简洁摘要而非原始输出
References
参考资料
For detailed information:
- Quick Start: - 5-minute setup guide
graphite-skill/QUICKSTART.md - Installation: - Automated installation
graphite-skill/install.sh - Team Setup: - Team configuration examples
graphite-skill/examples/team-configuration.md - Agent Template: - Custom agent definition
graphite-skill/agents/graphite-ops-template.md
如需详细信息:
- 快速入门:- 5分钟配置指南
graphite-skill/QUICKSTART.md - 安装:- 自动化安装
graphite-skill/install.sh - 团队配置:- 团队配置示例
graphite-skill/examples/team-configuration.md - 代理模板:- 自定义代理定义
graphite-skill/agents/graphite-ops-template.md
Status
状态
- ✅ Production-ready
- ✅ Tested with Claude Code 2.0+
- ✅ Compatible with Graphite CLI 1.0+
- ✅ Team-ready with git-tracked configuration
- ✅ Zero-friction automatic activation
- ✅ 生产可用
- ✅ 已通过Claude Code 2.0+测试
- ✅ 兼容Graphite CLI 1.0+
- ✅ 支持Git可追踪配置,适配团队使用
- ✅ 零摩擦自动激活