AI, Claude, Nutshell Series

Claude Exam (CCAR-F) Quick Revision 7: Session State & Resumption

Resume vs Fork

  • –resume <session-name> → Continue an existing session.
  • fork_session → Create an independent branch from shared prior context.

Memory: Resume = continue | Fork = diverge.

When to Resume

  • Previous analysis is still valid.
  • Files have not changed significantly.
  • You are continuing the same investigation.

When to Start Fresh

  • Old tool results are stale.
  • Code changed substantially.
  • Previous context may mislead Claude.

Best pattern: New session + structured summary.

Changed Files

When resuming after code changes, tell Claude exactly which files changed.

This enables targeted re-analysis instead of repeating the whole investigation.

Crash Recovery

Agent structured exports
↓
Manifest / checkpoint
↓
Coordinator reloads state
↓
Relevant state injected into agents

Fast Revision

  • Resume → continue valid context.
  • Fork → explore alternative.
  • Stale context → fresh session + summary.
  • Crash recovery → structured state + manifest.
AI, Claude, Nutshell Series

Claude Exam (CCAR-F) Quick Revision 6: Tools, Configuration & Rules

Built-In Tools

  • Read: Read a known file.
  • Edit: Targeted replacement inside an existing file.
  • Write: Create or overwrite an entire file.
  • Glob: Find files by filename/path pattern.
  • Grep: Search text inside files.
  • Bash: Run shell commands.
  • Agent: Delegate work to a separate-context subagent.

Memory: Glob finds files. Grep finds text.

Configuration Scopes

  • User: ~/.claude/ → me across projects.
  • Project: repository configuration → team/repository.
  • Local: personal settings for one repository.
  • Managed: organization-enforced configuration.

Important Files

  • CLAUDE.md: Instructions and project guidance.
  • settings.json: Claude Code configuration.
  • settings.local.json: Personal project overrides.
  • .claude/rules/*.md: Modular/path-specific instructions.
  • .mcp.json: Shared MCP configuration.
  • SKILL.md: Reusable skill definition.
  • .claude/agents/: Custom subagents.

Path-Specific Rules

---
paths:
  - "**/*.tf"
---

Use path-scoped rules when standards should apply only to particular files.

Global standards → CLAUDE.md
File-specific standards → .claude/rules/

Important Principle

CLAUDE.md provides instructions but does not provide deterministic security enforcement.

AI, Claude, Nutshell Series

Claude Exam (CCAR-F) Quick Revision 5: Multi-Agent Workflow Patterns

Prompt Chaining

Use when the sequence is predictable and known in advance.

Example: Extract → Validate → Transform → Publish.

Dynamic Adaptive Decomposition

Use when intermediate discoveries determine the next step.

Example: Debug issue → inspect logs → discover database problem → inspect queries.

Routing

Classify the input and send it to the appropriate specialist or workflow.

Parallel Sectioning

Run different independent subtasks simultaneously.

Example: Security review + performance review + maintainability review.

Parallel Voting

Run the same task multiple times and aggregate results for greater confidence.

Orchestrator-Workers

A coordinator dynamically creates and delegates subtasks to specialized workers.

Evaluator-Optimizer

Generate → critique → improve → repeat.

Context Efficiency

Let subagents perform verbose exploration and return concise synthesized findings to the coordinator.

Memory:
Chain = fixed path.
Route = choose path.
Parallel = many paths.
Orchestrator = create paths dynamically.
Agent = decide next step dynamically.

AI, Claude, Nutshell Series

Claude Exam (CCAR-F) Quick Revision 4: Hooks, Enforcement & Escalation

PreToolUse

Runs before a tool executes.

Best for:

  • Blocking unauthorized transactions.
  • Enforcing refund limits.
  • Checking prerequisites.
  • Preventing policy violations.

Example: Refund > $500 → block and escalate before process_refund executes.

PostToolUse

Runs after a tool returns.

Best for:

  • Trimming verbose results.
  • Normalizing MCP outputs.
  • Keeping only fields needed by the agent.

Example: Tool returns 40 fields → retain status, shipping date and tracking number.

Escalation: Good Triggers

  • Explicit request for a human.
  • Policy gap.
  • Permission boundary.
  • High-risk operation.
  • Deterministic hook blocks an action.

Escalation: Bad Triggers

  • Negative sentiment alone.
  • Profanity alone.
  • Self-reported model confidence alone.

Memory: Prompts guide. Hooks enforce.

AI, Claude, Nutshell Series

Claude Exam (CCAR-F) Quick Revision 3: Agentic Loops & Tool Calling

Agentic Loop

Flow:

Claude → tool_use → execute tool → tool_result → Claude → next action → end_turn

When Should the Loop Stop?

  • stop_reason = tool_use: Execute tool and continue.
  • stop_reason = end_turn: Claude has finished the turn.

Do not: Parse phrases such as “task complete” or “I am done.”

A maximum-turn limit is useful as a safety guard, but it is not the primary completion signal.

Returning Tool Results

  • Return the result in a user-role message.
  • Use a tool_result block.
  • Match the original tool_use_id.
  • The result does not have to be JSON-only.

Multi-Turn Tool Calling

Each tool result can influence Claude’s next decision.

Example: Search → Read → Analyse → Call API → Final answer.

Memory: tool_use = continue. end_turn = finish.

AI, Claude, Nutshell Series

Claude Exam (CCAR-F) Quick Revision 2: Context & Session Management

Important Commands

  • /compact: Summarise conversation and reclaim context.
  • /clear: Start with an empty conversation context.
  • /resume: Continue a previous session.
  • /context: Inspect context-window usage.
  • /branch: Explore an alternative path from the current conversation.
  • –fork-session: Inherit context but create an independent session.
  • /rewind: Return to an earlier checkpoint.

Preserving Critical Information

  • Immutable facts: Account ID, agreed price, transaction ID.
  • Mutable facts: Status, progress, next action.
  • Derived facts: Conclusions based on evidence.
  • Unverified facts: Claims still requiring confirmation.

Do not repeatedly summarise critical transactional facts. Keep them in a structured case-facts block or external state.

Long-Running Tasks

Persist important discoveries to external scratchpad/state files so they survive compaction, context resets and session boundaries.

Resuming Multi-Agent Work

Best pattern: each agent persists structured output, while a coordinator maintains a manifest/checkpoint and restores only relevant state.

Memory: Compact history. Persist facts. Rehydrate only what is needed.

AI, Claude, Nutshell Series

Claude Exam (CCAR-F) Quick Revision 1: Prompt Engineering & Few-Shot Prompting

Core rule: Precise instructions beat vague instructions.

Prompting Types

  • Zero-shot: Instruction only, no examples.
  • One-shot: One example demonstrates expected behaviour.
  • Few-shot: A small number of examples guide difficult decisions.
  • Negative examples: Show what Claude should NOT identify.
  • Contrastive examples: Show why one similar case is correct and another is not.

When to Use Few-Shot Prompting

  • Ambiguous classification.
  • Sarcasm or mixed sentiment.
  • Subjective boundaries.
  • Important edge cases.

Good pattern: Use 2–4 diverse examples including at least one difficult edge case.

Reducing False Positives

Use explicit and measurable criteria instead of instructions such as “flag anything suspicious.”

Example: “Flag functions longer than 50 lines” is better than “flag overly complex functions.”

Exam Traps

  • Temperature 0 improves consistency, not correctness.
  • Few-shot examples guide behaviour but do not guarantee enforcement.
  • Critical business rules should be implemented programmatically.

Memory: Ambiguity → examples. Hard rule → code.

Nutshell Series

Unit of Work Pattern in a Nutshell

The Unit of Work Pattern is used to save multiple database changes as one single transaction.

It makes sure that either all changes are saved or none of them are saved.

Simple Example

When placing an order, the system may need to:

  • Create an order
  • Reduce product stock
  • Save payment details

If one step fails, the other changes should not be saved. Unit of Work helps manage this safely.

Key Idea

Do multiple operations
Save everything once

C# Example

public interface IUnitOfWork
{
    Task SaveChangesAsync();
}
public class UnitOfWork : IUnitOfWork
{
    private readonly AppDbContext _context;

    public UnitOfWork(AppDbContext context)
    {
        _context = context;
    }

    public async Task SaveChangesAsync()
    {
        await _context.SaveChangesAsync();
    }
}

Usage

product.Stock -= 1;

orderRepository.Add(order);

await unitOfWork.SaveChangesAsync();

In EF Core

In Entity Framework Core, DbContext already works like a Unit of Work because it tracks changes and saves them together using:

await dbContext.SaveChangesAsync();

Conclusion

Unit of Work means collect all changes first, then save them together once.

Nutshell Series

How to Optimize GitHub Copilot Usage After June 2026 Changes

GitHub Copilot usage started draining faster for many users after the June 2026 billing changes. The main reason is that Copilot moved toward usage-based billing with GitHub AI Credits.

In simple terms: your usage now depends more on the model you choose, the amount of context, and whether you use features like Chat, Agent Mode, Code Review, CLI, Spaces, Spark, or cloud agents.

What Changed?

  • Copilot now uses AI Credits for many advanced features.
  • Normal code completions and next edit suggestions are still included in paid plans.
  • Premium models consume more credits.
  • Agent mode and code review can drain usage quickly.
  • Claude Sonnet 4.6 can be much more expensive than older models in some plans.

Why Usage Drains Fast

Copilot can consume more credits when it receives large context, scans multiple files, generates long answers, or uses premium models. Agent mode is especially expensive because it may perform multiple steps, inspect files, edit code, and retry.

How to Reduce Copilot Usage

1. Do Not Use Premium Models for Everything

Use cheaper/default models for normal coding, explanations, small refactors, and unit test skeletons. Save premium models for hard debugging, architecture, and complex multi-file issues.

2. Avoid Agent Mode for Small Changes

Do not use agent mode for simple fixes. Use normal chat with selected code instead.

Use only the selected code.
Find the bug.
Show only the minimal fix.
Do not scan the full workspace.

3. Keep Context Small

Select only the method, class, or error message Copilot needs. Avoid asking it to inspect the whole project unless required.

4. Limit Output

Ask Copilot to keep answers short.

Show only changed lines.
Do not rewrite the full file.
Keep the answer under 10 lines.

5. Use Autocomplete More

For daily coding, rely more on Copilot autocomplete and next edit suggestions. Use Chat only when you need reasoning or explanation.

6. Use Code Review Carefully

Copilot code review can consume significant usage. Use it for important PRs, not every small change.

7. Set a Budget

Check your Copilot billing settings and set a small overage limit. Start with a low cap before allowing extra usage.

Recommended Workflow

Autocomplete → daily coding
Default model → small questions
Premium model → hard debugging
Agent mode → only for real multi-file work
Code review → only for important PRs

Final Takeaway

GitHub Copilot is still powerful, but after the June 2026 changes, it should be used more intentionally. Keep prompts small, avoid premium models by default, and reserve agent mode for complex tasks.

Best rule: use the cheapest useful mode first, then move to premium models only when needed.

Nutshell Series

Strategy Pattern Explained in Simple Terms

The Strategy Pattern is a way to keep different behaviours separate instead of putting everything inside one big if/else block.

In simple words:

Strategy Pattern means choosing the right way to do something at runtime.

Layman Example

Imagine you want to travel to office.

You have different options:

  • Walk
  • Take a bus
  • Drive a car
  • Take a train

The goal is the same: reach the office.

But the method, or strategy, is different.

Software Example

Suppose an application needs to calculate delivery charges.

  • Standard delivery has one rule
  • Express delivery has another rule
  • Free delivery has another rule

Without Strategy Pattern, we may write everything in one method using many conditions.

if (deliveryType == "Standard")
{
    // standard delivery logic
}
else if (deliveryType == "Express")
{
    // express delivery logic
}
else if (deliveryType == "Free")
{
    // free delivery logic
}

This works, but as the rules grow, the code becomes harder to read and maintain.

How Strategy Pattern Helps

With Strategy Pattern, each rule is moved into its own class.

  • StandardDeliveryStrategy
  • ExpressDeliveryStrategy
  • FreeDeliveryStrategy

Each class handles only one behaviour.

The main code simply chooses the correct strategy and uses it.

Implementation Example

First, create a common interface for all delivery charge strategies.

public interface IDeliveryChargeStrategy
{
    decimal Calculate();
}

Now create separate classes for each strategy.

public class StandardDeliveryStrategy : IDeliveryChargeStrategy
{
    public decimal Calculate()
    {
        return 5;
    }
}

public class ExpressDeliveryStrategy : IDeliveryChargeStrategy
{
    public decimal Calculate()
    {
        return 15;
    }
}

public class FreeDeliveryStrategy : IDeliveryChargeStrategy
{
    public decimal Calculate()
    {
        return 0;
    }
}

Now choose the correct strategy based on the delivery type.

public class DeliveryChargeCalculator
{
    public decimal Calculate(string deliveryType)
    {
        IDeliveryChargeStrategy strategy = deliveryType switch
        {
            "Standard" => new StandardDeliveryStrategy(),
            "Express" => new ExpressDeliveryStrategy(),
            "Free" => new FreeDeliveryStrategy(),
            _ => throw new ArgumentException("Invalid delivery type")
        };

        return strategy.Calculate();
    }
}

Usage:

var calculator = new DeliveryChargeCalculator();

var charge = calculator.Calculate("Express");

Console.WriteLine(charge); // 15

Why Use It?

  • Code becomes cleaner
  • Large if/else blocks are reduced
  • Each behaviour is easier to change
  • Each rule can be tested separately
  • New behaviours can be added without disturbing old ones

When to Use It?

Use Strategy Pattern when the same action can be done in different ways.

Common examples:

  • Payment methods
  • Discount calculation
  • Delivery charge calculation
  • File export formats
  • Notification sending
  • Data update rules

In a Nutshell

The Strategy Pattern helps us separate different ways of doing the same thing.

Instead of writing one large method with many conditions, we create separate classes for each behaviour and choose the right one when needed.