Skip to content
cccskills
FreePublished on GitHub

agent-restore-context-setup

Set up the restore-context hook so skills can survive /clear and /compact. Detects .claude/ vs .agents/ layout automatically.

The English summary is being prepared. Showing the original description.

See how to install

Files included (2)

  • SKILL.md3.4 KB
  • resources/agent-restore-context.sh396 B

SKILL.md (original)

Review the instructions the agent will receive before you install.

Setup Restore Context

Set up a generic SessionStart hook that re-injects context after /clear or /compact. Any skill that writes a .agent-restore-context-<name> file in the project root will have its contents automatically injected into the fresh conversation.

How It Works

  1. Skills write .agent-restore-context-<skill-name> files with resume prompts.
  2. A SessionStart hook with matcher clear|compact runs agent-restore-context.sh.
  3. The script globs for .agent-restore-context-* and outputs their contents.
  4. The model receives that output and follows the resume instructions.
  5. Skills manage their own file lifecycle (write/delete).

Process

1. Detect Layout

Determine which configuration layer the project uses:

CheckLayoutSkills directory
.agents/ directory existsagents.agents/skills/
Only .claude/ existsclaude.claude/skills/

Settings files always live under .claude/ regardless of layout.

2. Check if Already Configured

Read .claude/settings.json and .claude/settings.local.json (if it exists). Search both for restore-context. If found in either file, report that the hook is already configured and stop.

3. Locate the Hook Script

The script is at <skills-dir>/agent-restore-context-setup/resources/agent-restore-context.sh (using the skills directory from step 1).

Verify the script exists and is executable. If not executable, run chmod +x.

4. Register the Hook

Permission check

Run gh repo view --json viewerPermission --jq '.viewerPermission'. If the result is READ, warn the user that the repo is read-only — any changes made to .claude/settings.json or .gitignore will need to be committed and pushed manually. Continue with the rest of the steps as normal.

Choose settings file

Ask the user:

"Should I add the restore-context hook to .claude/settings.json (shared/committed) or .claude/settings.local.json (local only)?"

Compute the script path relative to the project root (from step 3), then merge the following into the chosen file's hooks object. Do not overwrite existing hooks — add to or create the SessionStart array:

{
  "SessionStart": [
    {
      "matcher": "clear|compact",
      "hooks": [
        {
          "type": "command",
          "command": "bash <skills-dir>/agent-restore-context-setup/resources/agent-restore-context.sh"
        }
      ]
    }
  ]
}

5. Add Gitignore Entry

Check .gitignore for .agent-restore-context-*. If not present, append:

# Restore context files (used by skills to survive /clear and /compact)
.agent-restore-context-*

6. Confirm

Report to the user:

  • Where the hook was registered (which settings file)
  • The path to the script
  • That any skill can now write .agent-restore-context-<name> files to use this pattern

Guidelines

  • Always read target files before modifying them
  • Do not create .agents/ or .agents/skills/ directories — only use them if they already exist
  • This skill is idempotent — safe to run multiple times

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

Manage restore context files so skills can survive /clear and /compact. Use to write, delete, check, or list .agent-restore-context-* files.

The English summary is being prepared. Showing the original description.

commercetools/nimbus5Updated Oct 17, 2026

You MUST use this before any creative work - creating features, building components, adding functionality, or modifying behavior. Explores user intent, requirements and design before implementation.

The English summary is being prepared. Showing the original description.

commercetools/nimbus5Updated Oct 17, 2026

Implement tasks from an OpenSpec change. Use when the user wants to start implementing, continue implementation, or work through tasks.

The English summary is being prepared. Showing the original description.

commercetools/nimbus5Updated Oct 17, 2026

Archive a completed change. Use when the user wants to finalize and archive a change after implementation is complete.

The English summary is being prepared. Showing the original description.

commercetools/nimbus5Updated Oct 17, 2026

Enter explore mode - a thinking partner for exploring ideas, investigating problems, and clarifying requirements. Use when the user wants to think through something before or during a change.

The English summary is being prepared. Showing the original description.

commercetools/nimbus5Updated Oct 17, 2026

Propose a new change with all artifacts generated in one step. Use when the user wants to quickly describe what they want to build and get a complete proposal with design, specs, and tasks ready for implementation.

The English summary is being prepared. Showing the original description.

commercetools/nimbus5Updated Oct 17, 2026

See all skills by commercetools

Report a problem with this skill