SevyDevy

AI Coding Agent Customization Explained: Instruction Files, Hooks and Sub-Agents

, Last updated , 21 min read

Summary

  • AI coding agent customization means adding your own rules and tools to a coding agent, a program that reads, edits and runs your code with a large model's help.
  • Many agents offer six extension points. Instruction files are always-loaded notes, custom commands are saved prompts, and skills are instructions loaded only when needed. Hooks are scripts run on events, sub-agents are helpers with their own context, and MCP servers connect outside systems.
  • Instruction files, commands and skills are advice the model may still ignore. Hooks are code, so they can block a matching tool call every time.
  • Pick by asking two questions: who should decide when this runs, and must it hold every time? That choice matters more than any file format.
  • Beginners can stop after the comparison table. Engineers get a tested hook script, a working MCP prompt server and the failure modes, including hooks that fail open when they crash.

What goes wrong when you use a coding agent without customising it?

Out of the box, a coding agent knows your language but not your project. It guesses your test command, repeats the same mistakes every session and may treat a secrets file like any other file.

Picture a common setup. A five-person team in Pune maintains a Python web service that books clinic appointments, and they use a coding agent daily. The setup is made up, but every failure below is a common one.

  • The agent runs pytest directly, which skips the database fixtures, so tests fail for the wrong reason. Someone corrects it, and the next session it does the same thing.
  • Before every pull request, a developer types the same six-line review request by hand.
  • One afternoon the agent tries to edit the .env file, which holds database passwords. Another time it proposes a force push.
  • A search across the whole repo fills the agent's memory with search results, and it forgets a detail from the start of the task.
  • The agent cannot see the issue tracker, so someone pastes ticket text into the chat every time.

Each failure has a different fix. AI coding agent customization is the skill of matching the fix to the failure. Writing a longer prompt fixes none of them for good.

Which words do you need before customising an AI coding agent?

You need five words: agent, harness, tool call, context window and prompt injection. Each gets a plain meaning here, and the guide uses them the same way throughout.

  • Agent: a program that gives a large model a task and lets it act in a loop. It reads files, runs commands, looks at the result and decides the next step.
  • Harness: the ordinary code around the model that runs that loop. It builds what the model sees, runs the tools and enforces settings.
  • Tool call: a request from the model to do one action, such as read a file or run a shell command. The harness, not the model, actually runs it.
  • Context window: the text the model can see in one request, measured in tokens (small pieces of words). Everything you add to it costs space and money.
  • Prompt injection: text hidden in a file, web page or tool result that tries to give the model new orders. It works because the model reads instructions and data as the same kind of text.

What is AI coding agent customization?

AI coding agent customization is changing what a coding agent knows, which actions it can take and which actions it must never take, without changing the model. You do it through extension points the harness reads.

Think of a capable new hire joining the clinic team. The list below maps each extension point to one part of onboarding them.

  • Instruction file: the team handbook on their desk. They read it on day one and look back at it often.
  • Custom command: a checklist you hand them when you ask for a specific job, such as a release review.
  • Skill: a binder on the shelf. They know its title and open it only when a task needs it.
  • Hook: the badge reader on the server-room door. It does not argue or forget; it simply refuses.
  • Sub-agent: sending a second person to dig through old records and come back with a one-page summary.
  • MCP server: giving them a login to another system, such as the issue tracker.

Where the picture breaks: a new hire remembers yesterday, but the model starts each session fresh. It only knows what the harness puts in its context window this time. That is why written instructions matter so much.

Where each extension point plugs into a coding agent

Notice that the hook sits between the model and the tools. Everything on the left is text the model reads; the hook is code that runs. Permission prompts also sit there in many agents, and exact wiring varies.

Diagram connections:

  • You to Custom command (calls by name)
  • Custom command to Agent harness (expands into a prompt)
  • Instruction file to Agent harness (always loaded)
  • Skill descriptions to Agent harness (names and descriptions)
  • Agent harness to Model (builds the context)
  • Model to Hook check (proposed tool call)
  • Hook check to Built-in tools (allowed)
  • Hook check to MCP server tools (allowed)
  • Hook check to Agent harness (blocked, with a reason)
  • Agent harness to Sub-agent (delegates a side task)
  • Sub-agent to Agent harness (summary only)
  • You: Type a task or call a command
  • Custom command: Saved prompt you call by name
  • Instruction file: Loaded at the start of every session
  • Skill descriptions: Short list; the full skill loads on use
  • Agent harness: Ordinary code that runs the loop
  • Model: Reads the context, proposes a tool call
  • Hook check: Your script decides: allow or block
  • Built-in tools: Read, edit, run shell commands
  • MCP server tools: Tickets, docs or data outside the repo
  • Sub-agent: Own context; returns a short result

The most useful split is advice versus enforcement. Instruction files, commands and skills are text the model reads. A good model follows them most of the time, but nothing forces it to. A hook is a program, so its answer is the same every time.

The extension points side by side (general patterns; check your agent's docs for exact behaviour)
Extension pointWho decides when it runsWhat enters the contextAdvice or enforcedUse it for
Instruction fileThe harness, automaticallyThe whole file, every sessionAdviceStable facts: commands, layout, conventions
Custom commandYou, by calling its nameIts prompt, only when calledAdviceRepeated tasks you start yourself
SkillThe model, from its descriptionName and description first; the body only on useAdviceOccasional procedures with extra files
HookThe harness, on an eventOnly what the hook sends backEnforced by your codeRules that must hold every time
Sub-agentThe main agent or youA separate context; only the result returnsAdvice plus its own tool limitsNoisy or parallel side work
MCP serverThe model picks a tool; you approveTool names, descriptions and resultsDepends on approvals and server checksReaching systems outside the repo

Which open standards cover coding agent customization in 2026?

Three of the pieces in the comparison table have open, vendor-neutral formats, as of 31 October 2026. Hooks, custom commands and sub-agents do not; each agent defines its own file names and settings.

  • Instruction files: the open AGENTS.md convention is plain Markdown with no required headings. Its site says the nearest file in the folder tree wins, and explicit chat prompts override everything.
  • MCP servers: the Model Context Protocol (MCP) is an open protocol for connecting agents to tools and data. Its prompts feature also gives a standard way to share custom commands.
  • Skills: the Agent Skills spec defines a folder with a SKILL.md file. SevyDevy's agent skills guide covers it in depth, so this guide only shows where skills fit.

Many agents also read their own instruction file names, and some read several. Before you write one, check which names your agent loads and in which order.

What should go in an instruction file?

An instruction file should hold the stable facts an agent needs in almost every session. That means build and test commands, where things live and a few agreed rules. It is a README written for the agent.

The naive first try is to paste the whole team wiki into it. That is the wrong move. The file loads into the context window every session, so every extra line costs tokens and competes for the model's attention.

Here is a short file that fixes the clinic team's first failure.

markdown
# Clinic API: notes for coding agents

## Commands
- Install: make setup
- Test everything: make test (never call pytest directly; it skips the database fixtures)
- Lint and format: make lint

## Layout
- app/ holds the web service; app/booking/ is the appointment logic
- migrations/ is generated by our tool; do not hand-edit old files

## Rules
- Every change to app/booking/ needs a test in tests/booking/
- Ask before adding a new dependency

Notice what it does not contain. It has no coding-style essay, no history and no passwords. Facts that a linter or formatter already checks do not need repeating here.

Nested instruction files

Large repos can keep one file at the root and smaller ones inside sub-folders. Under the AGENTS.md convention, the file closest to the code being edited wins when two files disagree.

For the clinic team, a short file in app/booking/ could say which time zone appointment times use. The root file stays short, and the detail loads only where it applies, in agents that follow this convention.

When should you use a custom command instead of an instruction?

Use a custom command when you keep typing the same request and you want to choose when it runs. A command is a saved prompt with a name, and it enters the context only when you call it.

The clinic team's pre-review request is a good fit. It applies to one moment in the workflow, not to every session. Putting it in the instruction file would waste context on every other task.

Many agents let you store commands as small text files, either in the repo for the team or in your home folder for yourself. Many accept arguments, such as a branch name typed after the command.

Sharing a command through MCP prompts

MCP gives commands a standard form called prompts. The spec calls prompts user-controlled, meaning the user picks when to use them. It gives slash commands as an example interface.

A client asks a server for its prompts with a prompts/list request, then fetches one with prompts/get and its arguments. Here is a tiny server that shares the clinic team's review command. We tested it on the MCP Python SDK 2.3.0 with Python 3.13.

python
from mcp.server.mcpserver import MCPServer

server = MCPServer("team-commands")


@server.prompt(description="Review the current branch against our checklist")
def review_branch(base: str = "main"):
    return (
        f"Compare this branch with {base}. "
        "Run the unit tests with: make test. "
        "List any new migration files. "
        "Flag changes to files under config/ for a human to check."
    )


if __name__ == "__main__":
    server.run()

You can test it without any agent. This script starts the server in the same process, lists its prompts and fetches one.

python
import asyncio

from mcp import Client
from review_server import server


async def main():
    async with Client(server) as client:
        listed = await client.list_prompts()
        for p in listed.prompts:
            print("prompt:", p.name, "| args:", [a.name for a in p.arguments])
        result = await client.get_prompt("review_branch", {"base": "release-2.4"})
        print(result.messages[0].content.text)


asyncio.run(main())

Install the SDK with pip install mcp==2.3.0, then run python try_prompt.py. You should see two lines: the prompt name with its argument list, then the filled-in review request, exactly as below.

text
prompt: review_branch | args: ['base']
Compare this branch with release-2.4. Run the unit tests with: make test. List any new migration files. Flag changes to files under config/ for a human to check.

What just happened? The server turned a function into a named prompt and its parameter into an optional argument. Called without an argument, the same prompt fills in main.

How do hooks gate tool calls in a coding agent?

A hook is a script you register with the agent so it runs on a named event, such as just before a tool call. The script reads details of the call and answers allow or block.

Unlike instruction files, commands and skills, a hook does not depend on the model choosing to obey. That is why it fixes the clinic team's third failure, the .env edit and the force push.

Details differ by agent, but several documented hook systems share a shape, as of 31 October 2026. The agent sends the event as JSON on the script's standard input, including the tool name and its arguments. An exit code of 2 blocks the call, and the script's error text goes back to the model.

What happens when a hook checks a tool call

Follow the arrow marked 'no, or script crashed'. In some agents a crashed hook only logs a warning, so the tool call goes ahead.

Diagram connections:

  • Model proposes a call to Harness finds a hook (before running)
  • Harness finds a hook to Hook reads the event (starts the script)
  • Hook reads the event to Matches a rule? (checks the rules)
  • Matches a rule? to Block with exit code 2 (yes)
  • Matches a rule? to Tool runs (no, or script crashed)
  • Block with exit code 2 to Reason sent to the model (stderr text)
  • Model proposes a call: For example: run rm -rf build/
  • Harness finds a hook: A matcher says which tools it watches
  • Hook reads the event: Tool name and arguments, as JSON
  • Matches a rule?: Your own code, not the model
  • Block with exit code 2: Reason printed to standard error
  • Reason sent to the model: The model can try a safer step
  • Tool runs: Exit code 0, or a crash in some agents

A small guard hook you can run

The script below blocks edits to protected files and three risky command patterns. The event shape is a simplified example; rename the fields to match your agent's documented input. We ran it on Python 3.13.

python
import json
import re
import sys

BLOCK_EXIT_CODE = 2  # several agents treat 2 as "block"; check your agent's docs

PROTECTED_FILES = (".env", "secrets/", "migrations/applied/")
RISKY_COMMANDS = (
    r"\brm\s+-(?=[a-z]*r)(?=[a-z]*f)[a-z]+",  # rm -rf, rm -fr, rm -Rf
    r"\bgit\s+push\b.*--force",
    r"\bdrop\s+table\b",
)


def decide(event):
    tool = event.get("tool_name", "")
    args = event.get("tool_input", {})
    if tool in ("edit_file", "write_file"):
        path = args.get("path", "")
        if any(p in path for p in PROTECTED_FILES):
            return False, f"{path} is protected. Ask a human to change it."
    if tool == "run_shell":
        cmd = args.get("command", "").lower()
        for pattern in RISKY_COMMANDS:
            if re.search(pattern, cmd):
                return False, "This command is blocked by team policy."
    return True, ""


if __name__ == "__main__":
    allowed, reason = decide(json.load(sys.stdin))
    if not allowed:
        print(reason, file=sys.stderr)
        sys.exit(BLOCK_EXIT_CODE)
    sys.exit(0)

Test it by piping a fake event into it and printing the exit code.

bash
echo '{"tool_name": "run_shell", "tool_input": {"command": "rm -rf build/"}}' | python3 guard_hook.py; echo "exit=$?"
echo '{"tool_name": "run_shell", "tool_input": {"command": "pytest -q"}}' | python3 guard_hook.py; echo "exit=$?"

The first prints "This command is blocked by team policy." and then exit=2. The second prints only exit=0. If you see exit=1, the script crashed, usually on bad JSON.

Pause and predict

The agent now wants to run rm -r -f build/ instead. It could also run a one-line Python command that deletes the folder. Will the hook block either one?

Neither is blocked. Both returned exit code 0 when we ran them. The pattern needs r and f inside one flag, such as -rf, and the Python version never mentions rm at all.

Text matching also over-blocks: the .env rule would stop a harmless edit to .env.example too. This is the honest limit of hooks that match text. They catch the common mistake, not a determined workaround. Real protection for secrets and production comes from what the agent's user account can reach, such as a sandbox or a separate credential.

What are sub-agents and when do they help?

A sub-agent is a helper agent that the main agent starts for one side task. It works in its own context window and hands back only a short result.

That solves the clinic team's fourth failure. A broad search across the repo produces pages of matches. If a sub-agent runs it, the main agent receives a ten-line summary instead of the whole mess.

Agents that document sub-agents commonly let you give each one its own instructions and a narrower tool list. A read-only reviewer that cannot edit files is a typical example. Some also let a sub-agent use a different model.

The cost is easy to miss. The sub-agent spends its own tokens, so total usage can go up, not down. In some agents it does not see the main conversation either, so the task you hand over must carry its own goal and context.

  • Good fits: wide searches, reading many files to answer one question, a second-opinion review, and independent tasks that can run side by side.
  • Poor fits: small edits, tasks that need the whole conversation so far, and work where the details matter more than a summary.

Where do MCP servers and skills fit in?

MCP servers add new tools from outside the repo, and skills add know-how that loads only when needed. The clinic team needs an MCP server for its last failure. A skill suits something new: a release checklist the team runs once a month.

MCP servers bring outside systems in

An MCP server could expose the issue tracker as a tool, such as one that fetches a ticket by its ID. The spec calls tools model-controlled, so the model decides when to call them.

Because the model makes that choice, the spec says there should always be a human able to deny tool calls. It also says clients must treat a server's tool annotations as untrusted unless the server is trusted. Annotations are hints such as read-only.

Agents usually list each connected server's tool names and descriptions for the model, so each extra server costs context. Connect the ones a task needs, not every server you can find. OWASP's guidance on excessive agency makes the same point: limit an agent's extensions to the minimum it needs.

Skills load only when needed

A skill is a folder with a SKILL.md file. Under the Agent Skills spec, only each skill's name and description load at startup. The full instructions load when the skill is used.

The release checklist runs once a month, so it fits a skill better than the instruction file. The agent skills guide on SevyDevy explains the format, progressive loading and how to write a good description.

How do you choose the right extension point?

Ask who should decide when it runs, then ask whether it must hold every time. Those two answers pick the extension point in most cases.

  1. Must it hold every time?

    If breaking the rule once would hurt, such as touching secrets or force-pushing, write a hook. Then add a sandbox or narrower credentials behind it.

  2. Does the agent need it in almost every session?

    Put short, stable facts in the instruction file: build and test commands, layout and a few team rules.

  3. Do you start it yourself?

    Make a custom command, or an MCP prompt if several teams or agents should share it.

  4. Is it needed now and then, with extra files?

    Write a skill, so only its description costs context until it is used.

  5. Is the work noisy but the answer short?

    Hand it to a sub-agent with a narrow tool list.

  6. Does the agent need a system outside the repo?

    Connect an MCP server, and keep a person able to deny its tool calls.

The clinic team's failures and their fixes
FailureFixWhy this one
Runs pytest instead of make testOne line in the instruction fileA stable fact needed in most sessions
Same review request typed by handA custom command or MCP promptThe developer chooses when it runs
Tries to edit .env or force-pushA hook, backed by narrow credentialsIt must hold every time
Search results crowd out the taskA read-only search sub-agentNoisy work, short answer
Cannot see ticketsAn MCP server for the trackerThe data lives outside the repo
Monthly release checklistA skillRare, with extra files

What breaks when you customise a coding agent?

Customisation fails in quiet ways: rules that conflict, context that bloats, hooks that fail open and files from strangers that you run without reading. Each one has a simple check.

  • Conflicting instructions. A root file says one test command and a nested file says another. Keep each fact in one place and let nested files add detail, not contradictions.
  • Context bloat. Long instruction files, many MCP servers and many skill descriptions all take space before the task starts. Trim the instruction file whenever you add to it.
  • Hooks that fail open. In at least two agents' hook docs, an exit code other than 0 or 2 only logs a warning, and the action continues. A crashing guard hook is no guard.
  • Slow hooks. A hook runs on every matching call, and at least one agent's docs give a 30-second default timeout. Keep checks fast and local.
  • Untrusted repos. A cloned repo can ship its own instruction files, commands and, in some agents, hook settings. Read them before you trust the folder, because hooks are programs that run on your machine.

The last point links to prompt injection. The OWASP guidance on prompt injection lists files as a source of indirect injection. An instruction file in a stranger's repo is exactly that kind of file.

How to check your setup works

Test each piece the way you would test code, without trusting that the agent read it.

  • Hook: pipe a fake event in, as shown above, and check for exit=2 on a blocked call and exit=0 on a safe one. Add a malformed event and decide what a crash should do.
  • Custom command or MCP prompt: list and fetch it with a small client script before wiring it into an agent.
  • Instruction file: start a fresh session and give a task that needs the fact, such as running the tests. Watch which command the agent actually runs.

How do you explain AI coding agent customization in a system design interview?

Frame it as layers of control around a model you cannot change, from soft advice to hard enforcement.

  1. Name the loop

    A harness gives the model context, the model proposes tool calls, and the harness runs them. Customisation plugs into that loop.

  2. Separate advice from enforcement

    Instruction files, commands and skills shape what the model reads. Hooks and permissions decide what actually runs.

  3. Budget the context

    Say what loads always, what loads on demand and what runs in a separate context, such as a sub-agent.

  4. Add outside systems safely

    Use MCP servers for tools beyond the repo, with a person able to deny calls and the least access that works.

  5. Plan for failure

    Mention hooks that fail open, conflicting instructions and prompt injection from untrusted files, and how you would test each.

A strong answer ends with the trade-off. More customisation makes the agent fit the team, but each piece costs context, upkeep and review time.

Questions people ask

Is an instruction file the same as a system prompt?

Not exactly. An instruction file is a file in your repo whose text the agent adds to what the model sees, next to the agent's own built-in instructions. You control the file, not the built-in part. Both are text the model reads, so neither one can enforce a rule on its own.

Can an instruction file stop an agent from running a dangerous command?

No. An instruction file is advice, and the model can ignore or misread it, especially in long sessions. To stop a command every time, use a hook that blocks the tool call, the agent's permission settings, or a sandbox. A hook that matches text still misses rewritten commands, so pair it with narrow credentials.

What is the difference between a custom command and a skill?

You decide when a custom command runs by calling its name. The model decides when to use a skill, based on its short description. Commands suit tasks you start yourself, like a pre-review checklist. Skills suit procedures that come up now and then and may need extra files, like a release process.

Do sub-agents save tokens?

Not usually in total. A sub-agent spends its own tokens on its own context, so overall usage can rise. What it saves is space in the main agent's context window, because only a short result comes back. That keeps the main task focused on long, messy jobs.

Are hooks the same as a sandbox?

No. A hook is a script that checks a tool call before it runs, usually by matching names and text. It catches honest mistakes, but a rewritten command can slip past it. A sandbox limits what the agent's process can reach at all, such as files, network and credentials. Use both.

Should customisation files live in the repo?

Shared ones should. Commit the instruction file, team commands and hook scripts, and review changes to them like code, because they change how the agent behaves for everyone. Keep personal preferences in your user-level settings. Never put secrets in any of these files, since the model reads them.

Does every coding agent read AGENTS.md?

No, but many do, and the format is open and vendor-neutral, as of 31 October 2026. Some agents read their own file names instead or as well. Check your agent's docs for which files it loads and in which order, then keep one source of truth and point the others to it.