Skip to content

fix: scrub blocked URLs from system[] instead of relocating all content#198

Open
s2bomb wants to merge 1 commit intogriffinmartin:mainfrom
s2bomb:fix/system-prompt-url-blocklist
Open

fix: scrub blocked URLs from system[] instead of relocating all content#198
s2bomb wants to merge 1 commit intogriffinmartin:mainfrom
s2bomb:fix/system-prompt-url-blocklist

Conversation

@s2bomb
Copy link
Copy Markdown

@s2bomb s2bomb commented Apr 15, 2026

Problem

v1.4.8 moved ALL non-core system content to the first user message to avoid Anthropic's 400 rejection. This regresses instruction priority and prompt-cache efficiency — AGENTS.md, env blocks, skills all lose system[] attention priority.

Root cause

Server-side blocklist. One URL triggers rejection: github.com/anomalyco/opencode.

Reproduces with Claude Code itself:

claude -p --append-system-prompt "https://github.com/anomalyco/opencode" "Reply OK."
# → 400 "You're out of extra usage"

Not a client fingerprint. Not an auth issue. Server-side content filter.

Probe results

15 targeted requests varying system[] content. Same OAuth, same billing, same model.

system[] contains result
billing + identity only 200
+ full OpenCode prompt (no anomalyco URL) 200
+ env block 200
+ AGENTS.md 200
+ skills block 200
+ all three combined 200
+ github.com/anomalyco/opencode 400
word "anomalyco" alone 200
word "opencode" alone 200
opencode.ai URL 200
same path on gitlab 200

Single URL. Nothing else.

Fix

Scrub blocked URL substring in-place. Entry stays in system[]. No content relocation.

OpenCode concatenates the full prompt (identity + agent prompt + env + AGENTS + skills) into one system[] entry. Old approach relocated the whole entry on match → frontloaded everything into user message. This fix removes only the URL string.

const BLOCKED_SYSTEM_STRINGS = ["github.com/anomalyco/opencode"]

for (const entry of parsed.system) {
  if (isBlocked(entry.text)) {
    for (const blocked of BLOCKED_SYSTEM_STRINGS)
      entry.text = entry.text.split(blocked).join("")
  }
}

Wire dump verification

Before (v1.4.10):

  • systemCount: 2 (billing + identity)
  • userPreview: "You are OpenCode, the best coding agent..." ← frontloaded

After:

  • systemCount: 3 (billing + identity + full prompt)
  • userPreview: "What tools do you have? List 3." ← clean
  • API: 200

Tests

214 pass. No new deps.

Copy link
Copy Markdown

@bvironn bvironn left a comment

Choose a reason for hiding this comment

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

Tested locally — 214/214 tests pass. The empirical probe table in the PR body is excellent: it isolates the server-side trigger to one substring.

Two follow-ups worth considering:

  1. Empty replacement leaves text artifacts: replacing github.com/anomalyco/opencode with "" can produce dangling phrases like "Visit for help" in the prompt. Consider replacing with opencode.ai (functionally equivalent project URL — passes the validator per your probe row 11) to keep the prompt grammatically intact.

  2. Blocklist extensibility: a single hardcoded string is fine today, but future Anthropic additions would force another release cycle. An optional OPENCODE_CLAUDE_AUTH_BLOCKED_STRINGS (comma-separated) merged with the built-in list would let users self-mitigate. Not blocking.

Strict improvement over v1.4.8 either way. Resolves #154 and #210.

griffinmartin added a commit to s2bomb/opencode-claude-auth-pr that referenced this pull request Apr 30, 2026
…list

- Replace 'github.com/anomalyco/opencode' with 'opencode.ai' instead of
  empty string so surrounding prose stays grammatical (no double spaces
  or dangling phrases).
- Add OPENCODE_CLAUDE_AUTH_BLOCKED_STRINGS env var (comma-separated,
  optional 'pattern=replacement' form) so users can self-mitigate
  future server-side additions without a release cycle.
- Restate scrub-in-place comment for clarity.
- Add tests for grammatical replacement, realistic concatenated prompt,
  and env-var parser. Fix lint formatting flagged by oxfmt --check.

Addresses review feedback from @bvironn on griffinmartin#198.
@griffinmartin griffinmartin force-pushed the fix/system-prompt-url-blocklist branch from 9b897cb to a10b2b6 Compare April 30, 2026 02:41
@griffinmartin
Copy link
Copy Markdown
Owner

griffinmartin commented Apr 30, 2026

@s2bomb

Getting You're out of extra usage. Add more at claude.ai/settings/usage and keep going.. I can debug later unless you're able to.

Force pushed your original commit, can bring mine back in if this is resolved.

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.

3 participants