Skip to content

fix(llm): claude code user id compatible#1102

Merged
looplj merged 1 commit intorelease/v0.9.xfrom
dev-tmp
Mar 19, 2026
Merged

fix(llm): claude code user id compatible#1102
looplj merged 1 commit intorelease/v0.9.xfrom
dev-tmp

Conversation

@looplj
Copy link
Copy Markdown
Owner

@looplj looplj commented Mar 19, 2026

No description provided.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on ensuring that the application can correctly parse and extract trace IDs from Claude Code requests, regardless of whether the user ID is in the legacy string format or the newer JSON format. This involves adding a new claudecode package to handle the parsing logic and updating the trace middleware to use this package.

Highlights

  • Claude Code User ID Compatibility: This PR introduces compatibility with the new Claude Code user ID format (v2 JSON) in addition to the legacy format.
  • Trace ID Extraction: The changes include updating the trace ID extraction logic to handle both the legacy string format and the new JSON format for user IDs.
  • Dependency Injection: The claudecode package is now injected into trace.go and trace_test.go to handle parsing of the user ID.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the Claude Code user ID handling by introducing a dedicated userid.go module. This centralizes the parsing, building, and generation of user IDs, supporting both legacy string formats and new JSON formats. The changes include removing old regex-based parsing logic, updating the User-Agent constant, and integrating the new claudecode.ParseUserID and claudecode.GenerateUserID functions across the codebase and tests. The new module significantly improves maintainability and correctness by providing a robust and unified way to manage Claude Code user IDs.

Comment on lines +72 to +73
data, _ := json.Marshal(uid)
return string(data)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The error returned by json.Marshal is ignored here. While json.Marshal typically doesn't fail for simple structs, it's best practice to handle potential errors, especially if the UserID struct might evolve to include more complex types in the future. Consider logging the error or returning an empty string with a log message if marshaling fails.

func BuildUserID(uid UserID) string {
	data, err := json.Marshal(uid)
	if err != nil {
		// Log the error or handle it appropriately
		return ""
	}
	return string(data)
}

// GenerateUserID creates a random user_id in v2 JSON format.
func GenerateUserID() string {
hexBytes := make([]byte, 32)
_, _ = rand.Read(hexBytes)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The error returned by rand.Read is ignored. rand.Read can return an error if the underlying source of randomness is unavailable, although this is rare. For robustness, it's generally good practice to check for and handle such errors, perhaps by panicking or logging, to ensure that hexBytes is properly populated.

func GenerateUserID() string {
	hexBytes := make([]byte, 32)
	if _, err := rand.Read(hexBytes); err != nil {
		// Handle the error, e.g., log it or panic
		panic(fmt.Sprintf("failed to read random bytes: %v", err))
	}

	return BuildUserID(UserID{
		DeviceID:    hex.EncodeToString(hexBytes),
		AccountUUID: "",
		SessionID:   uuid.New().String(),
	})
}

@looplj looplj merged commit 2e6070a into release/v0.9.x Mar 19, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant