# Context Aware Ops

> >-

- **Type:** Skill
- **Install:** `agentstack add skill-cogni-ai-ou-cogni-ai-agent-skills-context-aware-ops`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [Cogni-AI-OU](https://agentstack.voostack.com/s/cogni-ai-ou)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [Cogni-AI-OU](https://github.com/Cogni-AI-OU)
- **Source:** https://github.com/Cogni-AI-OU/cogni-ai-agent-skills/tree/main/context-aware-ops

## Install

```sh
agentstack add skill-cogni-ai-ou-cogni-ai-agent-skills-context-aware-ops
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# Context-Aware Operations Skill

This skill provides patterns and techniques for managing large files and command outputs
efficiently, preventing context window exhaustion while maintaining effective problem-solving
capabilities.

## When to Use

- Before executing commands that might produce large output
- Before reading any file in the codebase
- When debugging issues that might involve large resources
- When searching through codebases
- When working with logs, build outputs, or data files

## When Not to Use

- For trivially small, single-file edits where the overhead of checking file size slows down the workflow unnecessarily.
- When the user explicitly demands the full output of a specific file and context limits are known to be sufficient.
- For interactive terminal sessions where pagination tools (`less`, `more`) are natively handled by the user.

## Common Pitfalls

- **Blind Dumping**: Running `cat` on a build log without checking its size, instantly blowing out the LLM's context window.
- **Truncating Crucial Errors**: Using `head` to sample a file when the actual error message resides at the very end of the stack trace (where `tail` was needed).
- **Ignoring Binary Files**: Attempting to read binary artifacts or minified JS without filtering, resulting in unreadable token noise.

## Core Principle

**Always check before you dump!**

Never blindly dump large resources into your context. Always:

1. Check the size first
2. Use filtering if needed
3. Focus on relevant portions only

## File Size Checking

### Check Line Count

```bash
# Fast line count
wc -l filename.txt

# Line count without filename
wc -l (wc -l >&2) | head -20

# Or separately
output_lines=$(command | wc -l)
echo "Command produced $output_lines lines"
if [ $output_lines -gt 100 ]; then
  command | head -50
else
  command
fi
```

### Filter Common Patterns

```bash
# Show only errors and warnings
command 2>&1 | grep -E "error|warn|fail" -i

# Show only specific log levels
command | grep -E "ERROR|WARN|FATAL"

# Exclude verbose/debug lines
command | grep -v -E "DEBUG|TRACE|INFO"

# Show unique errors only
command 2>&1 | grep -i error | sort -u
```

### Paginate Large Output

```bash
# First page
command | head -n 50

# Show summary instead of full output
command | wc -l
command | head -20 && echo "... (showing first 20 lines)"
command | tail -20 && echo "... (showing last 20 lines)"
```

## Smart File Viewing Strategy

### Decision Tree

```bash
#!/bin/bash
FILE=$1

# Check if file exists
if [ ! -f "$FILE" ]; then
  echo "File not found: $FILE"
  exit 1
fi

# Get line count
LINES=$(wc -l /dev/null || find . -type d | head -20
```

## Context Window Budget Management

### Track Usage Mentally

- Small files (2000 lines): Never dump completely

### Prioritization Strategy

1. **Critical**: Files directly related to the bug/feature
2. **Important**: Dependencies and related modules
3. **Nice-to-have**: Context and documentation
4. **Skip**: Tangentially related or very large files

### When Context is Running Low

```bash
# Instead of full file, show:
# 1. File summary
wc -l filename && head -20 filename

# 2. Function/class list
grep -E "^(def|class|function|export)" filename

# 3. Specific section only
sed -n '/start_marker/,/end_marker/p' filename

# 4. Just the relevant function
awk '/^def target_function/,/^def [^t]/' filename.py
```

## Advanced Techniques

### Pipe Chains for Efficiency

```bash
# Find, filter, and limit in one go
find . -name "*.log" -exec grep -l "ERROR" {} \; | head -10

# Search multiple files, show unique results
grep -rh "pattern" . | sort -u | head -20

# Complex filtering in stages
cat large.txt | \
  grep -i "keyword" | \
  grep -v "noise" | \
  sort -u | \
  head -30
```

### Binary Search for Large Files

```bash
# Find approximate location of pattern
total_lines=$(wc -l &1 | grep -E "error|warn" -i || echo "Install successful"`

3. **Don't**: `git log`
   **Do**: `git log --oneline -20` or `git log --oneline | head -20`

4. **Don't**: `docker logs container`
   **Do**: `docker logs --tail 100 container` or `docker logs container 2>&1 | grep -i error`

5. **Don't**: `./run_tests.sh`
   **Do**: `./run_tests.sh 2>&1 | tee >(wc -l >&2) | grep -E "fail|error|pass" -i | head -50`

## Remember

- **Size matters**: Always check before you dump
- **Filter first**: Use grep, head, tail, sed, awk
- **Focus**: Only show what's relevant to the current task
- **Summarize**: When in doubt, show a summary rather than everything
- **Iterate**: You can always come back for more details if needed

## Related Skills

- **shell**:
  You MUST load this skill when handling shell commands with performance monitoring or timeouts.

Your context window is precious - use it wisely!

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [Cogni-AI-OU](https://github.com/Cogni-AI-OU)
- **Source:** [Cogni-AI-OU/cogni-ai-agent-skills](https://github.com/Cogni-AI-OU/cogni-ai-agent-skills)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-cogni-ai-ou-cogni-ai-agent-skills-context-aware-ops
- Seller: https://agentstack.voostack.com/s/cogni-ai-ou
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
