anthropics / anthropics/claude-code-action

`use_sticky_comment` has no effect in agent mode — MCP server starts without CLAUDE_COMMENT_ID

Open
#1,108 2 comments 2 reactions 0 assignees View on GitHub
bug mcp p2
Dominant language
TypeScript
Stars
8.9k
Forks
2.1k
Avg merge
3d 9h
Merged PRs (30d)
10

Description

**Describe the bug**

When `use_sticky_comment: true` is set but the action enters agent mode (because `track_progress: false` and a `prompt` is provided), the sticky comment feature silently breaks. No comment is ever created on the PR, even though the MCP comment server is included in the tool list.

The root cause is a code path gap in `src/modes/agent/index.ts`:

1. `detectMode()` in `src/modes/detector.ts` returns `"agent"` when `track_progress` is false and `prompt` is set
2. In `src/modes/agent/index.ts` line 105, `claudeCommentId` is hardcoded to `undefined`
3. Even though `shouldIncludeCommentServer` evaluates to `true` in `install-mcp-server.ts` (because `mcp__github_comment__update_claude_comment` is in `allowedTools`), the MCP server starts without `CLAUDE_COMMENT_ID` in its environment
4. Every call to `update_claude_comment` fails at line 42-44 of `github-comment-server.ts` with: `"CLAUDE_COMMENT_ID environment variable is required"`

Unlike tag mode, agent mode never calls `createInitialComment()` to create the comment and obtain its ID.

**To Reproduce**

1. Configure a workflow with `track_progress: false`, `use_sticky_comment: true`, and a `prompt` on a `pull_request` event (e.g., with `types: [labeled]`)
2. Trigger the action by adding the label to a PR
3. The action runs successfully (Claude executes the prompt and produces output)
4. No sticky comment appears on the PR

**Expected behavior**

When `use_sticky_comment: true`, agent mode should create an initial comment (like tag mode does via `createInitialComment()`) and pass the resulting comment ID to the MCP server via `CLAUDE_COMMENT_ID`. The sticky comment should be updated throughout the run.

**Workflow yml file**

```yaml
on:
pull_request:
types: [labeled]

jobs:
review:
if: github.event.label.name == 'claude-review'
runs-on: ubuntu-latest
steps:
- uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
use_sticky_comment: true
prompt: |
Review this pull request and post your findings as a comment.
```

Because `track_progress` defaults to `false` and `prompt` is set, this enters agent mode where the sticky comment is silently ignored.

**API Provider**

[x] Anthropic First-Party API (default)
[ ] AWS Bedrock
[ ] GCP Vertex

**Additional context**

- **Workaround:** Setting `track_progress: true` forces tag mode where sticky comments work, but this isn't viable for all event types (e.g., `labeled` fails `validateTrackProgressEvent`).
- **Suggested fix:** In `agent/index.ts`, when `context.inputs.useStickyComment` is true and the context is a PR or issue, call `createInitialComment()` and pass the resulting ID as `claudeCommentId` to `prepareMcpConfig`.
- **Possibly related:** #1052 may be a downstream symptom of this same root cause — the review result is captured but never posted because the comment server silently fails.

Contributor guide

Open the contributing guide

Research direction

Start in src/modes/agent/index.ts, then compare the agent path with tag mode and trace detectMode() in src/modes/detector.ts, prepareMcpConfig in install-mcp-server.ts, and the environment check in github-comment-server.ts. Done means a PR or issue run with use_sticky_comment enabled creates the initial comment, passes its ID to the MCP server, and updates that comment successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
devops
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.