Skip to content

feat: add exclude_dynamic_sections input for cross-session prompt caching#1362

Open
sestakvit wants to merge 1 commit into
anthropics:mainfrom
sestakvit:feat/exclude-dynamic-sections
Open

feat: add exclude_dynamic_sections input for cross-session prompt caching#1362
sestakvit wants to merge 1 commit into
anthropics:mainfrom
sestakvit:feat/exclude-dynamic-sections

Conversation

@sestakvit
Copy link
Copy Markdown

Summary

The Agent SDK (@anthropic-ai/claude-agent-sdk) supports excludeDynamicSections: true on the claude_code system prompt preset. When enabled, per-user dynamic content — working directory, git status, auto-memory path — is stripped from the cached system prompt prefix and re-injected as the first user message. This keeps the system prompt byte-for-byte identical across sessions, enabling prompt cache hits between independent runs that share the same prompt.

This is particularly valuable in CI fleet use cases (GitHub Actions workflows, PR validation bots) where many unrelated runs share the same prompt and would otherwise get a cache miss on every invocation due to the dynamic working-directory/git-status sections.

This PR wires that existing SDK option up to an action input.

Changes

  • action.yml: adds exclude_dynamic_sections boolean input (default false) and passes it as EXCLUDE_DYNAMIC_SECTIONS env var
  • base-action/src/run-claude.ts: adds excludeDynamicSections?: boolean to ClaudeOptions
  • base-action/src/parse-sdk-options.ts: passes the option into the claude_code preset system prompt object
  • src/entrypoints/run.ts: reads EXCLUDE_DYNAMIC_SECTIONS env var and passes it through
  • base-action/src/index.ts: same for standalone base-action usage (INPUT_EXCLUDE_DYNAMIC_SECTIONS)

Usage

- uses: anthropics/claude-code-action@v1
  with:
    exclude_dynamic_sections: "true"
    # ... other inputs

Notes

  • Has no effect when a custom system_prompt is set (matches SDK behaviour — excludeDynamicSections only applies to the claude_code preset)
  • The stripped content (working directory, git status, auto-memory path) is still available to the model; it just arrives in the first user message instead of the system prompt
  • No behaviour change when the input is omitted or set to false

…hing

Wires the Agent SDK's excludeDynamicSections option to an action input.
When true, per-user dynamic content (working directory, git status,
auto-memory path) is stripped from the cached system prompt prefix and
re-injected as the first user message. This makes the system prompt
static across sessions, enabling cross-run prompt cache hits in CI
fleets where many independent runs share the same prompt.

Has no effect when a custom system_prompt is set (SDK behaviour).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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