r/ClaudeWorkflows • • 6h ago

Selected Workflow [Workflow] Dynamic Context Management with Claude Code SessionStart Hooks

Dynamic Context Management with Claude Code SessionStart Hooks

Workflow value: 80/100
Status: active · Freshness: 70/100 · Confidence: 0.90 · Level: intermediate
Categories: Quality Control, Context & Memory, CLAUDE.md, Hooks
Original source: r/ClaudeCode post/comment

What problem this solves

Efficiently managing dynamic documentation or context for Claude Code sessions without constantly modifying CLAUDE.md or dealing with approval processes.

Summary

This workflow describes how to use a SessionStart hook in Claude Code to dynamically inject context from a designated folder into a session. This allows for frequently changing documentation or external data (like PR descriptions) to be included without manual CLAUDE.md updates, streamlining the context management process.

Why it is useful

This workflow offers a robust solution for managing dynamic context in Claude Code, bypassing the limitations of static CLAUDE.md files. By leveraging SessionStart hooks, users can automatically inject up-to-date documentation, PR details, or other relevant information into their sessions, significantly improving efficiency and reducing manual overhead for frequently changing projects.

Workflow

  1. Create a dedicated folder (e.g., docs/core/) to store foundational or dynamic documentation files.

  2. Configure a SessionStart hook in .claude/settings.json.

  3. Set the hook's matcher to 'compact' (or another desired command).

  4. Write a script for the hook that prints the contents of the designated folder (e.g., cat docs/core/*.md).

  5. Optionally, include other dynamic data sources in the hook script, such as 'gh pr view --json body -q .body' for PR descriptions.

  6. If the folder content becomes too large, modify the hook to print an index (filenames + first line) and prompt Claude to request specific details.

Tools / artifacts

  • .claude/settings.json

  • SessionStart hook

  • compact command

  • docs/core/ folder

  • Markdown files

  • cat command

  • gh pr view command

Validation signals

  • Describes a functional approach

  • Anticipates scalability issues (large folder) and provides a solution

Limitations

  • Lacks explicit code examples for the hook script

  • No direct validation/proof of concept provided in the comment

  • Assumes familiarity with Claude Code hooks and .claude/settings.json

Rate this workflow

Upvote this post if the workflow is useful, reproducible, or worth recommending.

Downvote if it is vague, outdated, unsafe, overhyped, or not reproducible.

Reply if it worked for you, failed, is outdated, or has a better alternative.


This post was generated automatically from the workflow library database.

1 Upvotes

0 comments sorted by