Repository navigation
feat(runner): commit as the session's GitHub account, not Claude - #268
Merged
Merged
Conversation
## Short Summary (TL;DR) Commits that a self-hosted runner session makes now name the GitHub account of the person who started the session. A SessionStart hook looks the account up through the session's git proxy, and `Claude <noreply@anthropic.com>` is only the fallback. ## The Issue The runner deletes `~/.gitconfig` before every session, so the module sets the git identity in `/etc/gitconfig`. That identity is `Claude <noreply@anthropic.com>`, so every commit from a runner session names Claude, not the person who did the work. Before the runner, sessions committed with the workspace owner's own identity. ## How This PR Solves The Issue The new `claude-session-identity` script runs as a SessionStart hook, next to `claude-checkout-check` in the managed settings drop-in. The session's git proxy adds the GitHub credential of the person who started the session, so the hook asks that proxy for GitHub's `/user`, as the session's `gh` shim does. It writes `GIT_AUTHOR_*` and `GIT_COMMITTER_*` to `$CLAUDE_ENV_FILE`, which Claude Code applies to the session's Bash commands. - Name: the account's profile name, or its login. - Email: the account's public email, or `<id>+<login>@users.noreply.github.com`. GitHub credits both to the account. - The hook never uses the workspace's own `gh` login, because that login belongs to the workspace owner, whoever started the session. - When the lookup fails, the hook writes nothing, and commits keep the `/etc/gitconfig` identity. Other identity sources lost. The claude.ai email in the session token is a login, not a git identity, and it can be a shared role account. A key or signing setup on the workspace would let every session act as one person. Commits stay unsigned. The README and docs say to re-sign a branch on your own computer when a repository requires signed commits. ## Manual Testing Instructions Use a freeform workspace with "Run a Claude Code self-hosted runner" on, from a template pushed from this branch. 1. Restart the workspace, then start a session on claude.ai/code in its environment, with a repository attached. 2. Ask Claude to run `env | grep -E '^GIT_(AUTHOR|COMMITTER)_'`. Expect your GitHub profile name and public email, or your `users.noreply.github.com` address. 3. Ask Claude to commit a small change on a branch and push it. On GitHub, expect the commit to show your avatar and login, not Claude's. 4. In the workspace, run `grep claude-session-identity /etc/claude-code/managed-settings.d/coder-runner.json`. Expect the hook command. 5. Check the fallback: run `CLAUDE_ENV_FILE=~/tmp/env.sh GIT_CONFIG_GLOBAL=/dev/null ~/.local/bin/claude-session-identity`. Expect the "commits use the default git identity" message, and expect `~/tmp/env.sh` to stay empty. ## Automated Testing Overview `freeform/tests/validate.tftest.hcl` now checks that the startup script installs `claude-session-identity` and adds it to the SessionStart hooks. Claude Code ran `terraform fmt -recursive`, `make validate` and `make test-templates` (all pass), markdownlint on the changed docs, and `shellcheck` on the script, all on Linux. In a runner session on coder.ddev.com, Claude Code ran the script against the real proxy: it found the right account, wrote the env file, and wrote nothing without an env file or a proxy. Nobody has confirmed yet that the `$CLAUDE_ENV_FILE` exports reach Bash commands in a new runner session, so step 2 above is that check. The strict Zensical docs build was not run. ## Release/Deployment Notes Restart runner workspaces after pushing the template, so they install the hook. The hook relies on two details of Anthropic's git proxy: the `proxy-injected` placeholder token and the `ccr/ca-bundle.crt` path. If either changes, commits fall back to the Claude identity. 🤖 Developed with assistance from [Claude Code](https://claude.ai/code) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UrTUMzWrupgmEe5ZjBfY2J
PreviewsThe start.coder.ddev.com landing-page preview has been removed. Read the Docs keeps or removes its own docs preview. |
Documentation build overview
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Short Summary (TL;DR)
Commits that a self-hosted runner session makes now name the GitHub account of the person who started the session. A SessionStart hook looks the account up through the session's git proxy, and
Claude <noreply@anthropic.com>is only the fallback.The Issue
The runner deletes
~/.gitconfigbefore every session, so the module sets the git identity in/etc/gitconfig. That identity isClaude <noreply@anthropic.com>, so every commit from a runner session names Claude, not the person who did the work. Before the runner, sessions committed with the workspace owner's own identity.How This PR Solves The Issue
The new
claude-session-identityscript runs as a SessionStart hook, next toclaude-checkout-checkin the managed settings drop-in. The session's git proxy adds the GitHub credential of the person who started the session, so the hook asks that proxy for GitHub's/user, as the session'sghshim does. It writesGIT_AUTHOR_*andGIT_COMMITTER_*to$CLAUDE_ENV_FILE, which Claude Code applies to the session's Bash commands.<id>+<login>@users.noreply.github.com. GitHub credits both to the account.ghlogin, because that login belongs to the workspace owner, whoever started the session./etc/gitconfigidentity.Other identity sources lost. The claude.ai email in the session token is a login, not a git identity, and it can be a shared role account. A key or signing setup on the workspace would let every session act as one person. Commits stay unsigned. The README and docs say to re-sign a branch on your own computer when a repository requires signed commits.
Manual Testing Instructions
Use a freeform workspace with "Run a Claude Code self-hosted runner" on, from a template pushed from this branch.
env | grep -E '^GIT_(AUTHOR|COMMITTER)_'. Expect your GitHub profile name and public email, or yourusers.noreply.github.comaddress.grep claude-session-identity /etc/claude-code/managed-settings.d/coder-runner.json. Expect the hook command.CLAUDE_ENV_FILE=~/tmp/env.sh GIT_CONFIG_GLOBAL=/dev/null ~/.local/bin/claude-session-identity. Expect the "commits use the default git identity" message, and expect~/tmp/env.shto stay empty.Automated Testing Overview
freeform/tests/validate.tftest.hclnow checks that the startup script installsclaude-session-identityand adds it to the SessionStart hooks. Claude Code ranterraform fmt -recursive,make validateandmake test-templates(all pass), markdownlint on the changed docs, andshellcheckon the script, all on Linux. In a runner session on coder.ddev.com, Claude Code ran the script against the real proxy: it found the right account, wrote the env file, and wrote nothing without an env file or a proxy. Nobody has confirmed yet that the$CLAUDE_ENV_FILEexports reach Bash commands in a new runner session, so step 2 above is that check. The strict Zensical docs build was not run.Release/Deployment Notes
Restart runner workspaces after pushing the template, so they install the hook. The hook relies on two details of Anthropic's git proxy: the
proxy-injectedplaceholder token and theccr/ca-bundle.crtpath. If either changes, commits fall back to the Claude identity.🤖 Generated with Claude Code
https://claude.ai/code/session_01UrTUMzWrupgmEe5ZjBfY2J