Allow overriding Claude preset tool name via env var#652
Allow overriding Claude preset tool name via env var#652ldthorne wants to merge 4 commits intogit-ai-project:mainfrom
Conversation
|
No AI authorship found for these commits. Please install git-ai to start tracking AI generated code in your commits. |
| fn tool_name_override() -> Option<String> { | ||
| env::var("GIT_AI_OVERRIDE_TOOL_NAME").ok() | ||
| } |
There was a problem hiding this comment.
🔴 Overridden tool name breaks transcript refetching in repo_storage.rs
When GIT_AI_OVERRIDE_TOOL_NAME is set, the AgentId.tool field is replaced with the custom value. However, repo_storage.rs:348-369 matches tool names against hardcoded strings ("claude", "cursor", "codex", "gemini", "opencode", "github-copilot", etc.) to decide whether transcript refetching is possible. An overridden tool name (e.g. "my-custom-agent") won't match any known tool and will fall through to the default arm (// Unknown tools (like custom agent-v1 tools) can't refetch), which treats the tool as unable to refetch transcripts. This silently disables transcript refetching for any agent whose tool name has been overridden, potentially causing missing transcript data in authorship logs.
Prompt for agents
The tool_name_override() function in src/commands/checkpoint_agent/agent_presets.rs:41-43 (and inline env::var calls in agent_v1_preset.rs:86, amp_preset.rs:138, opencode_preset.rs:201) replaces the AgentId.tool field. But src/git/repo_storage.rs:348-369 matches against hardcoded tool name strings to determine refetch capability. When a tool name is overridden, it no longer matches any known tool, so transcript refetching is disabled.
Fix options:
1. Store the original tool name (e.g. "claude") in agent_metadata alongside the overridden display name, and use the original name for refetch logic in repo_storage.rs.
2. Update repo_storage.rs to also check agent_metadata for the original tool identity when the tool name doesn't match any known tool.
3. Add agent_metadata entries like "original_tool" when an override is active, and consult that in repo_storage.rs.
Was this helpful? React with 👍 or 👎 to provide feedback.
| } => Ok(AgentRunResult { | ||
| agent_id: AgentId { | ||
| tool: agent_name, | ||
| tool: env::var("GIT_AI_OVERRIDE_TOOL_NAME").ok().unwrap_or(agent_name), |
There was a problem hiding this comment.
🔴 Missing empty-string filter for GIT_AI_OVERRIDE_TOOL_NAME in agent_v1_preset
In agent_v1_preset.rs:86, env::var("GIT_AI_OVERRIDE_TOOL_NAME").ok().unwrap_or(agent_name) does not filter out empty or whitespace-only values, unlike the tool_name_override() helper in agent_presets.rs:41-43 which applies .filter(|s| !s.trim().is_empty()). If the env var is set to an empty string (e.g. GIT_AI_OVERRIDE_TOOL_NAME=""), the tool name will be set to "" instead of falling back to agent_name. This empty tool name propagates into prompt hashing (generate_short_hash), search filtering, blame display, and serialized authorship logs.
Was this helpful? React with 👍 or 👎 to provide feedback.
|
@ldthorne - made some changes to how this was implemented. Another team asked for this and needs OpenCode, Claude Code and Codex so I made it so one env could override tool name for any tool. This shouldn't be used locally but seems to be the right design for custom background agents |
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
|
||
| let agent_id = AgentId { | ||
| tool: "amp".to_string(), | ||
| tool: env::var("GIT_AI_OVERRIDE_TOOL_NAME").ok().unwrap_or_else(|| "amp".to_string()), |
There was a problem hiding this comment.
🔴 Missing empty-string filter for GIT_AI_OVERRIDE_TOOL_NAME in amp_preset
In amp_preset.rs:138, env::var("GIT_AI_OVERRIDE_TOOL_NAME").ok().unwrap_or_else(|| "amp".to_string()) does not filter out empty or whitespace-only values, unlike the tool_name_override() helper in agent_presets.rs:41-43 which applies .filter(|s| !s.trim().is_empty()). If the env var is set to "" or " ", the tool name will be set to that empty/whitespace string instead of falling back to "amp". This is inconsistent with all the other presets in agent_presets.rs that use the shared tool_name_override() helper.
| tool: env::var("GIT_AI_OVERRIDE_TOOL_NAME").ok().unwrap_or_else(|| "amp".to_string()), | |
| tool: env::var("GIT_AI_OVERRIDE_TOOL_NAME").ok().filter(|s| !s.trim().is_empty()).unwrap_or_else(|| "amp".to_string()), |
Was this helpful? React with 👍 or 👎 to provide feedback.
|
|
||
| let agent_id = AgentId { | ||
| tool: "opencode".to_string(), | ||
| tool: env::var("GIT_AI_OVERRIDE_TOOL_NAME").ok().unwrap_or_else(|| "opencode".to_string()), |
There was a problem hiding this comment.
🔴 Missing empty-string filter for GIT_AI_OVERRIDE_TOOL_NAME in opencode_preset
In opencode_preset.rs:201, env::var("GIT_AI_OVERRIDE_TOOL_NAME").ok().unwrap_or_else(|| "opencode".to_string()) does not filter out empty or whitespace-only values, unlike the tool_name_override() helper in agent_presets.rs:41-43 which applies .filter(|s| !s.trim().is_empty()). If the env var is set to "" or " ", the tool name will be set to that empty/whitespace string instead of falling back to "opencode". This is inconsistent with all the other presets in agent_presets.rs that use the shared tool_name_override() helper.
| tool: env::var("GIT_AI_OVERRIDE_TOOL_NAME").ok().unwrap_or_else(|| "opencode".to_string()), | |
| tool: env::var("GIT_AI_OVERRIDE_TOOL_NAME").ok().filter(|s| !s.trim().is_empty()).unwrap_or_else(|| "opencode".to_string()), |
Was this helpful? React with 👍 or 👎 to provide feedback.
Allow the Claude preset's
agent_id.toolfield to be overridden via theGIT_AI_CLAUDE_PRESET_TOOL_NAMEenvironment variable. This is not a breaking change – if unset, it will continue to beclaudeThis enables platforms that embed Claude Code to identify themselves correctly in git notes authorship metadata without needing a dedicated preset.
I've added a test case but if you'd like to test manually:
agent_id.toolshould remainclaude(no behavior change)GIT_AI_CLAUDE_PRESET_TOOL_NAMEset tomy_new_bff, commit a change.agent_id.toolshould be set tomy_new_bff